|
|
|
|
@ -7,6 +7,7 @@ import data.DataSource;
|
|
|
|
|
import network.exceptions.*;
|
|
|
|
|
|
|
|
|
|
public class AlphaVantage extends DataSource {
|
|
|
|
|
|
|
|
|
|
public AlphaVantage() {
|
|
|
|
|
super("AlphaVantage", "https://www.alphavantage.co/query", "4MC2LL0HOQ2TFQL1");
|
|
|
|
|
}
|
|
|
|
|
@ -15,20 +16,23 @@ public class AlphaVantage extends DataSource {
|
|
|
|
|
public double[] update(String stype, String idstring) {
|
|
|
|
|
double[] result = {0.0, 0.0};
|
|
|
|
|
try {
|
|
|
|
|
String urlString = Net.urlStringBuilder(url,
|
|
|
|
|
"function", "GLOBAL_QUOTE",
|
|
|
|
|
"symbol", idstring,
|
|
|
|
|
String urlString = Net.urlStringBuilder(url, "function", "TIME_SERIES_INTRADAY", "symbol", idstring,
|
|
|
|
|
"interval", "5min",
|
|
|
|
|
"apikey", apiKey);
|
|
|
|
|
JsonObject response = StockJson.urlToJson(urlString);
|
|
|
|
|
JsonObject mainJson = StockJson.jsonInJson(response, "Global Quote");
|
|
|
|
|
result[0] = Double.parseDouble(StockJson.stringGetter(mainJson, "05. price"));
|
|
|
|
|
result[1] = StockJson.doublePercent(mainJson, "10. change percent");
|
|
|
|
|
JsonObject preJson = StockJson.jsonInJson(response, "Time Series (5min)");
|
|
|
|
|
JsonObject mainJson = StockJson.timeSeriesElement(preJson, 0);
|
|
|
|
|
System.out.print(mainJson);
|
|
|
|
|
result[0] = Double.parseDouble(StockJson.stringGetter(mainJson, "4. close"));
|
|
|
|
|
Double open = Double.parseDouble(StockJson.stringGetter(mainJson, "1. open"));
|
|
|
|
|
result[1] = (result[0] - open) / open;
|
|
|
|
|
} catch (ParaMismatchException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
System.out.println("Error getting data from: " + name);
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
//e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|