|
|
|
|
@ -13,7 +13,7 @@ public class AlphaVantage extends DataSource {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public double[] update(String stype, String idstring) {
|
|
|
|
|
public double[] update(String stype, String idstring) throws IOException {
|
|
|
|
|
double[] result = {0.0, 0.0};
|
|
|
|
|
try {
|
|
|
|
|
String urlString = Net.urlStringBuilder(url, "function", "TIME_SERIES_INTRADAY", "symbol", idstring,
|
|
|
|
|
@ -21,17 +21,20 @@ public class AlphaVantage extends DataSource {
|
|
|
|
|
"apikey", apiKey);
|
|
|
|
|
JsonObject response = StockJson.urlToJson(urlString);
|
|
|
|
|
JsonObject preJson = StockJson.jsonInJson(response, "Time Series (5min)");
|
|
|
|
|
if (preJson == null) {
|
|
|
|
|
throw new IOException("Error getting data from " + name);
|
|
|
|
|
}
|
|
|
|
|
JsonObject mainJson = StockJson.timeSeriesElement(preJson, 0);
|
|
|
|
|
System.out.print(mainJson);
|
|
|
|
|
//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);
|
|
|
|
|
} //catch (IOException e) {
|
|
|
|
|
// System.out.println("Error getting data from: " + name);
|
|
|
|
|
//e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
//}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|