XChange icon indicating copy to clipboard operation
XChange copied to clipboard

BitfinexAdapters.adaptTicker(org.knowm.xchange.bitfinex.v2.dto.marketdata.BitfinexTicker bitfinexTicker) NPE

Open pavlo-pastushok opened this issue 1 year ago • 5 comments

During Bitfinex remoteInit I received an error related to tickers adaptation

BigDecimal percentageChange =
        bitfinexTicker.getDailyChangePerc().multiply(new BigDecimal("100"), new MathContext(8));

a line above throws an exception

Cannot invoke "java.math.BigDecimal.multiply(java.math.BigDecimal, java.math.MathContext)" because the return value of "org.knowm.xchange.bitfinex.v2.dto.marketdata.BitfinexTicker.getDailyChangePerc()" is null

because some tickers have dailyChangePerc field as null

for example:

["tALT2612:USD",100,null,100,null,null,null,null,null,null,null]
["tALT2612:UST",100,null,100,null,null,null,null,null,null,null]

pavlo-pastushok avatar Jan 18 '24 23:01 pavlo-pastushok

did anyone facing same issue?

pavlo-pastushok avatar Jan 19 '24 07:01 pavlo-pastushok

Hello, @pavlo-pastushok i checked https://api.bitfinex.com/v2/tickers?symbols=tALT2612%3AUSD strange, but results are different, sometimes one, sometimes another. ["tALT2612:USD",100,0,100,0,0,0,100,1.0E-6,0,0] ["tALT2612:USD",100,null,100,null,null,null,null,null,null,null]

We need to understand that this is normal operation of the exchange API, and then create an exception handler. Or is this some kind of temporary error?

rizer1980 avatar Jan 19 '24 11:01 rizer1980

Hi @rizer1980

I am not sure, but I received this situation more than 10 times a day during last 3 days I will try to contact support with this question

pavlo-pastushok avatar Jan 19 '24 11:01 pavlo-pastushok

@rizer1980 @pavlo-pastushok

I have faced a similar issue. It seemed that exchange metadata was not populated for currency pairs with USDT as the quoted currency. Upon checking, it looks like during the remote init process, currency pairs derived from tickers and symbol details are processed inconsistently, at least in terms of adapting the currencies. This resulted in

BigDecimal last = lastPrices.get(currencyPair); in BitfinexAdapters.adaptMetaData() not finding USDT quoted symbols, because the ticker-derived list of symbols (lastPrices) had the quoted currency as UST, but the symbols-details-derived (symbolDetails) currency as USDT.

The fix appears to be needed in BitfinexAdapters.adaptTicker(org.knowm.xchange.bitfinex.v2.dto.marketdata.BitfinexTicker bitfinexTicker)

Change: CurrencyPair currencyPair = CurrencyPairDeserializer.getCurrencyPairFromString(bitfinexTicker.getSymbol().substring(1)); to: CurrencyPair currencyPair = BitfinexAdapters.adaptCurrencyPair(bitfinexTicker.getSymbol());

This will then adapt ticker-derived symbols and symbols-details-derived symbols in the same way, and results in UST being converted to USDT in both cases.

Note that getTicker() and getTickers() on BitfinexMarketDataService also call BitfinexAdapters.adaptTicker, so a regression test could be extended to these use cases as well.

Hope this helps with any bug fix that may be deemed necessary :)

ghost avatar Mar 01 '24 16:03 ghost

@rustyruzzee nice. shouldnt this be a PR?

gewure avatar May 15 '24 10:05 gewure