patriques82 / alphavantage4j

(Repository is not maintained anymore) A Java wrapper to get stock data and stock indicators from the Alpha Vantage API
https://www.alphavantage.co/
Apache License 2.0
124 stars 73 forks source link

Null values when AA doesn't send expected fields #28

Closed Montesinnos closed 6 years ago

Montesinnos commented 6 years ago

Awesome project. Thanks for creating!

I noticed this weekend (not sure if it's a temporal thing), AA is not sending volume in the timeseries data. Ie:

{
    "Meta Data": {
        "1. Information": "Intraday (1min) prices and volumes",
        "2. Symbol": "MSFT",
        "3. Last Refreshed": "2018-08-03 15:59:00",
        "4. Interval": "1min",
        "5. Output Size": "Compact",
        "6. Time Zone": "US/Eastern"
    },
    "Time Series (1min)": {
        "2018-08-03 15:59:00": {
            "1. open": "107.9000",
            "2. high": "108.0000",
            "3. low": "107.9000",
            "4. close": "108.0000"
        }
}

That causes the Parser to throw an error and return. In this specific case, I'd be ok to get the results even with missing fields. Code with problem is in: package api.quote.patriques.output.timeseries.IntraDay. Line 65

There are robust ways to return a failure, with means for the user to recover for it. In my specific case, I'm ok with missing values, so I just add extra checks for the expected fields. If it's not present, I put 0L. Of course the user can't tell the difference, so this isn't good for everyone.

values.containsKey("5. volume") ? Long.parseLong(values.get("5. volume")) : 0L)
Montesinnos commented 6 years ago

Did some extra research. It appears that the intraday function does not return volume, while the daily one does. I have examples:

https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=MSFT

{
    "Meta Data": {
        "1. Information": "Daily Prices (open, high, low, close) and Volumes",
        "2. Symbol": "MSFT",
        "3. Last Refreshed": "2018-08-03",
        "4. Output Size": "Compact",
        "5. Time Zone": "US/Eastern"
    },
    "Time Series (Daily)": {
        "2018-08-03": {
            "1. open": "107.8000",
            "2. high": "108.0500",
            "3. low": "106.8200",
            "4. close": "108.0400",
            "5. volume": "18659599"
        }
}

while https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=1min&apikey=HI

{
    "Meta Data": {
        "1. Information": "Intraday (1min) prices and volumes",
        "2. Symbol": "MSFT",
        "3. Last Refreshed": "2018-08-03 15:59:00",
        "4. Interval": "1min",
        "5. Output Size": "Compact",
        "6. Time Zone": "US/Eastern"
    },
    "Time Series (1min)": {
        "2018-08-03 15:59:00": {
            "1. open": "107.9000",
            "2. high": "108.0000",
            "3. low": "107.9000",
            "4. close": "108.0000"
        }
}
patriques82 commented 6 years ago

Hi Montesinnos. I will have a look a soon as I can. Thanks for the information. Otherwise if you wish you could send a pull request and I´ll merge it after reviewing it.

patriques82 commented 6 years ago

Hm thats weird. Now when I click on your intraday link the volume is visible. I guess the API changed for our benefit?

Montesinnos commented 6 years ago

Yap. Seems to be good now. Thanks for looking into it!