Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pavlo-pastushok opened this issue Jan 18, 2024 · 5 comments

Comments

@pavlo-pastushok
Copy link
Contributor

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
Copy link
Contributor Author

did anyone facing same issue?

@rizer1980
Copy link
Contributor

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?

@pavlo-pastushok
Copy link
Contributor Author

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

@rustyruzzee
Copy link

@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 :)

@gewure
Copy link

gewure commented May 15, 2024

@rustyruzzee nice. shouldnt this be a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants