Converting to BinanceKlines gets this error: java.lang.String and java.lang.Boolean are in module java.base of loader 'bootstrap'
Using version 5.1.1 gets the following error when fetching Binance Klines:
java.lang.ClassCastException: class java.lang.String cannot be cast to class java.lang.Boolean (java.lang.String and java.lang.Boolean are in module java.base of loader 'bootstrap')
at org.knowm.xchange.binance.dto.marketdata.BinanceKline.
Code:
private List<BinanceKline> geKlinesFromBinance(
CurrencyPair currencyPair, KlineInterval interval, long startTime, long endTime) {
try {
return binanceMarketDataService.klines(currencyPair, interval, 1000, startTime, endTime);
} catch (IOException e) {
e.printStackTrace();
}
return new ArrayList<>();
}
Hello, @mtdayacap
The given code is not enough to understand the reason. There is a class BinanceKlineExample in Binance-stream with an example, it works, I just checked it.
Hi @rizer1980 . Thanks for checking. I’ll try to replicate it and post the code here so you can also test.
I have the same issue. It's situated in the constructor at line 42 (org.knowm.xchange.binance.dto.marketdata.BinanceKline):
this.closed = (Boolean)obj[11];
obj[11] is a String ("0") that's being attempted to be converted into a Boolean and fails.
As I understand it, you are trying to receive data not from binance-stream, but through a regular binance api
something like that:
List<BinanceKline> kline = ((BinanceMarketDataServiceRaw) binanceExchange.getMarketDataService()).klines(new CurrencyPair("BTC/USDT"),m1);
The code there is from 2018 years, and also not quite ready, since there is no method in the marketdata, only in marketdataraw.
When they wrote in 2023 klines for binance-stream, they break the usual binance-api klines. And of course the code needs to be reworked a little.
Because this is crooked:
@Path("api/v3/klines")
List<Object[]> klines(
Need to do a normal klines data parse.
As I understand it, you are trying to receive data not from binance-stream, but through a regular binance api something like that:
List<BinanceKline> kline = ((BinanceMarketDataServiceRaw) binanceExchange.getMarketDataService()).klines(new CurrencyPair("BTC/USDT"),m1);The code there is from 2018 years, and also not quite ready, since there is no method in the marketdata, only in marketdataraw.
When they wrote in 2023 klines for binance-stream, they break the usual binance-api klines. And of course the code needs to be reworked a little.
Because this is crooked:
@Path("api/v3/klines") List<Object[]> klines(Need to do a normal klines data parse.
Yes, exactly. The code is:
Exchange binance = ExchangeFactory.INSTANCE.createExchange(BinanceExchange.class.getName()); BinanceMarketDataServiceRaw binanceMarketDataServiceRaw = (BinanceMarketDataServiceRaw) binance.getMarketDataService(); List<BinanceKline> klines = binanceMarketDataServiceRaw.klines(CurrencyPair.BTC_USDT, KlineInterval.d1);
Is that legacy/deprecated code ? I haven't really looked into the binance-stream api yet, I thought that was more for advanced stuff like websockets.
Is that legacy/deprecated code ? not legacy/deprecated, but usually we have public methods in MarketDataService, and MarketDataServiceRaw is for internal use only. Since in this case there is no method in the MarketDataService, I conclude that something is not completed. Stream - for websockets, yes.
for quick fix you can simply delete two lines in BinanceKline.class
private final boolean closed;
and
this.closed = (Boolean) obj[11];
after this simple api works. but this break a little steams...
Same issue, pls fix it quickly
marketDataService.klines(((CurrencyPair) cp), KlineInterval.m15);