Skip to content

Commit

Permalink
Update AlphaVantage to use the non-premium endpoint to read historica…
Browse files Browse the repository at this point in the history
…l prices

Issue: #3275
  • Loading branch information
buchen committed Apr 15, 2023
1 parent 6127657 commit e9e6e00
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private QuoteFeedData getHistoricalQuotes(Security security, boolean collectRawR
{
@SuppressWarnings("nls")
WebAccess webaccess = new WebAccess("www.alphavantage.co", "/query") //
.addParameter("function", "TIME_SERIES_DAILY") //
.addParameter("function", "TIME_SERIES_DAILY_ADJUSTED") //
.addParameter("symbol", security.getTickerSymbol()) //
.addParameter("apikey", apiKey) //
.addParameter("datatype", "csv") //
Expand All @@ -204,7 +204,8 @@ private QuoteFeedData getHistoricalQuotes(Security security, boolean collectRawR
return data;

// poor man's check
if (!"timestamp,open,high,low,close,volume".equals(lines[0])) //$NON-NLS-1$
if (!"timestamp,open,high,low,close,adjusted_close,volume,dividend_amount,split_coefficient" //$NON-NLS-1$
.equals(lines[0]))
{
data.addError(new IOException(MessageFormat.format(Messages.MsgUnexpectedHeader, html)));
return data;
Expand All @@ -217,7 +218,7 @@ private QuoteFeedData getHistoricalQuotes(Security security, boolean collectRawR
String line = lines[ii];

String[] values = line.split(","); //$NON-NLS-1$
if (values.length != 6)
if (values.length != 9)
throw new IOException(MessageFormat.format(Messages.MsgUnexpectedValue, line));

LatestSecurityPrice price = new LatestSecurityPrice();
Expand All @@ -230,7 +231,7 @@ private QuoteFeedData getHistoricalQuotes(Security security, boolean collectRawR

price.setHigh(asPrice(values[2]));
price.setLow(asPrice(values[3]));
price.setVolume(Long.parseLong(values[5]));
price.setVolume(Long.parseLong(values[6]));

if (price.getValue() != 0)
data.addPrice(price);
Expand Down

0 comments on commit e9e6e00

Please sign in to comment.