XChange icon indicating copy to clipboard operation
XChange copied to clipboard

Converting to BinanceKlines gets this error: java.lang.String and java.lang.Boolean are in module java.base of loader 'bootstrap'

Open mtdayacap opened this issue 2 years ago • 7 comments

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.(BinanceKline.java:42) ~[xchange-binance-5.1.1.jar:na] at org.knowm.xchange.binance.service.BinanceMarketDataServiceRaw.lambda$klines$3(BinanceMarketDataServiceRaw.java:83) ~[xchange-binance-5.1.1.jar:na] at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) ~[na:na] at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625) ~[na:na] at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) ~[na:na] at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) ~[na:na] at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) ~[na:na] at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:na] at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682) ~[na:na] at org.knowm.xchange.binance.service.BinanceMarketDataServiceRaw.klines(BinanceMarketDataServiceRaw.java:84) ~[xchange-binance-5.1.1.jar:na]

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<>();
  }

mtdayacap avatar Jan 18 '24 00:01 mtdayacap

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.

rizer1980 avatar Jan 18 '24 10:01 rizer1980

Hi @rizer1980 . Thanks for checking. I’ll try to replicate it and post the code here so you can also test.

mtdayacap avatar Jan 18 '24 14:01 mtdayacap

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.

kvuivbribumok avatar Feb 03 '24 12:02 kvuivbribumok

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.

rizer1980 avatar Feb 05 '24 16:02 rizer1980

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.

kvuivbribumok avatar Feb 05 '24 17:02 kvuivbribumok

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...

rizer1980 avatar Feb 05 '24 18:02 rizer1980

Same issue, pls fix it quickly marketDataService.klines(((CurrencyPair) cp), KlineInterval.m15);

socmia avatar Feb 06 '24 08:02 socmia