-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebStockService.java
More file actions
46 lines (36 loc) · 1.49 KB
/
WebStockService.java
File metadata and controls
46 lines (36 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.origamisoftware.teach.advanced.services;
import com.origamisoftware.teach.advanced.model.StockQuote;
import com.origamisoftware.teach.advanced.util.Interval;
import yahoofinance.Stock;
import yahoofinance.YahooFinance;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
/**
* I assume this interacts with the YF API directly?
* not needing the servlet
* I made a simple servlet but couldn't understand how to
* integrate it into the WenStockService
*/
public class WebStockService implements StockService {
private Stock stock;
@Override
public StockQuote getQuote(String symbol) throws StockServiceException, IOException {
stock = YahooFinance.get(symbol);
String yfSymbol = stock.toString();
return new StockQuote(new BigDecimal(100), Calendar.getInstance().getTime(), yfSymbol);
}
@Override
public List<StockQuote> getQuote(String symbol, Calendar from, Calendar until, Interval interval) throws StockServiceException, IOException {
List<StockQuote> stockQuotes = new ArrayList<>();
stock = YahooFinance.get(symbol, from, until);
BigDecimal price = stock.getQuote().getPrice();
Date aDay = (Date) stock.getHistory();
String yfSymbol = stock.getSymbol();
stockQuotes.add(new StockQuote(price, aDay, yfSymbol));
return stockQuotes;
}
}