crazzyghost / alphavantage-java

Fluent Java wrapper for Alpha Vantage API
MIT License
80 stars 35 forks source link

Monthly stock units not mapping correctly. #1

Closed ajt001 closed 4 years ago

ajt001 commented 4 years ago

Hi, When I run your code to get prices for a month, it appears the mapping isn't quite right. You can see the code I'm using (per your instructions), and the results (screenshots below. What is returned is not what is in the json file from the api.

fun getMonthlyQuotesForSecurity(security: String): MutableList<StockUnit> {
        var stocks = emptyList<StockUnit>()
        return runBlocking {
            run {
                AlphaVantage.api()
                        .init(Config.builder()
                                .key(PriceProcesses.alphaVantageKey)
                                .timeOut(10)
                                .build())

                AlphaVantage.api()
                        .timeSeries()
                        .monthly()
                        .forSymbol(security)
                        .onSuccess { r: TimeSeriesResponse ->
                            stocks = r.stockUnits
                        }
                        .onFailure { e: AlphaVantageException? ->
                            (PriceProcesses.logger.error { "There was an error with the API: => $e.localizedMessage" })
                        }
                        .fetch()
            }

            val deferredResult = async {
                var counter: Long = 0
                while (stocks.isEmpty() && counter < 10000) {
                    counter += 1000
                    delay(counter)
                }
                return@async stocks.toMutableList()
            }

            return@runBlocking deferredResult.await()
        }

image

image

crazzyghost commented 4 years ago

Hi @ajt001, thanks for pointing that out. I've reviewed and merged your PR into the master branch.