XChange icon indicating copy to clipboard operation
XChange copied to clipboard

Huobi nullpointer, because transactionFeeWithdrawal may be null

Open mumch opened this issue 2 years ago • 5 comments

In HuobiAdapters, the line

BigDecimal transactFeeWithdraw = new BigDecimal(huobiCurrency.getTransactFeeWithdraw());

leads to a nullpointer, since transactFeeWithdraw may be null. Huobi's API documentation says: "Withdraw fee in each request (only applicable to withdrawFeeType = fixed)" according to https://huobiapi.github.io/docs/spot/v1/en/#apiv2-currency-amp-chains

mumch avatar Jul 29 '22 14:07 mumch

I am having the same issue with it. The adapter stopped working all of a sudden. Although, I am not sure how that happened, because there is no Huobi changelog that would indicate anything obvious.

Caused by: java.lang.NullPointerException at java.base/java.math.BigDecimal.<init>(BigDecimal.java:834) at org.knowm.xchange.huobi.HuobiAdapters.getCurrencyMetaData(HuobiAdapters.java:140) at org.knowm.xchange.huobi.HuobiAdapters.adaptCurrencyMetaData(HuobiAdapters.java:126) at org.knowm.xchange.huobi.HuobiAdapters.adaptToExchangeMetaData(HuobiAdapters.java:111) at org.knowm.xchange.huobi.HuobiExchange.remoteInit(HuobiExchange.java:45) at org.knowm.xchange.BaseExchange.applySpecification(BaseExchange.java:113) at org.knowm.xchange.ExchangeFactory.createExchange(ExchangeFactory.java:130) ...

vangogiel avatar Aug 08 '22 11:08 vangogiel

A quick and dirty workaround would be modifying the HuobiAdapters.getCurrencyMetaData() method to:

private static CurrencyMetaData getCurrencyMetaData(
      HuobiCurrency huobiCurrency, boolean isDelisted) {
    int withdrawPrecision = huobiCurrency.getWithdrawPrecision();
    BigDecimal transactFeeWithdraw = BigDecimal.ONE;
    if(huobiCurrency!=null && huobiCurrency.getTransactFeeWithdraw() != null) {
    	transactFeeWithdraw = new BigDecimal(huobiCurrency.getTransactFeeWithdraw());
    }
    BigDecimal minWithdrawAmt = new BigDecimal(huobiCurrency.getMinWithdrawAmt());
    WalletHealth walletHealthStatus =
        isDelisted ? WalletHealth.OFFLINE : getWalletHealthStatus(huobiCurrency);
    return new CurrencyMetaData(
        withdrawPrecision, transactFeeWithdraw, minWithdrawAmt, walletHealthStatus);
  }

mumch avatar Aug 12 '22 12:08 mumch

@mumch I have created a solution locally and installed a snapshot version to use in my uber jar.

I can create a PR in your repo if it helps.

Thanks, Norbert

vangogiel avatar Aug 12 '22 13:08 vangogiel

@vangogiel If you have an appropriate solution, better make a pull request directly here to the XChange project. Thank you and regards, mum

mumch avatar Aug 12 '22 13:08 mumch

My solution was to just query the transactionFeeWithdraw if it is null to place BigDecimal.ZERO

Στις Παρ 12 Αυγ 2022 στις 4:17 μ.μ., ο/η mumch @.***> έγραψε:

@vangogiel https://github.com/vangogiel If you have an appropriate solution, better make a pull request directly here to the XChange project. Thank you and regards, mum

— Reply to this email directly, view it on GitHub https://github.com/knowm/XChange/issues/4537#issuecomment-1213100245, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHIWQ746TGJSCLC4QWNZBN3VYZFGDANCNFSM55A5YFVQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

makarid avatar Aug 12 '22 13:08 makarid

@mumch I created a PR, https://github.com/knowm/XChange/pull/4552. In my opinion, this is the cleanest approach. I wanted to add a test, but there is no structure for Integration or Exchange tests, so I wasn't invasive as much.

vangogiel avatar Aug 17 '22 10:08 vangogiel

@vangogiel i have add your implementation to my PR #4546 also. Thanks

makarid avatar Aug 17 '22 12:08 makarid

@makarid @mumch What happens to my PR then?

vangogiel avatar Aug 24 '22 17:08 vangogiel

Hi @vangogiel I don't know, I am not one of the project owners. But I guess, it will be merged with the next release.

mumch avatar Aug 25 '22 09:08 mumch

I have add your implementation to my PR and it got merge. Then probably your PR was cancelled because my PR had already merged it.

On Thu, Aug 25, 2022, 12:44 PM mumch @.***> wrote:

Hi @vangogiel https://github.com/vangogiel I don't know, I am not one of the project owners. But I guess, it will be merged with the next release.

— Reply to this email directly, view it on GitHub https://github.com/knowm/XChange/issues/4537#issuecomment-1227031948, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHIWQ7ZCHCCI4TZTHBNP6HLV246BFANCNFSM55A5YFVQ . You are receiving this because you were mentioned.Message ID: @.***>

makarid avatar Aug 25 '22 09:08 makarid

Yeah, it would be nice to get credit for that work.

vangogiel avatar Sep 04 '22 21:09 vangogiel

5.0.14-SNAPSHOT fix this issue.

pom.xml as follow:

    <dependencies>
        <dependency>
            <groupId>org.knowm.xchange</groupId>
            <artifactId>xchange-huobi</artifactId>
            <version>5.0.14-SNAPSHOT</version>
        </dependency>
    </dependencies>
    <repositories>
        <repository>
            <id>sonatype-oss-snapshot</id>
            <snapshots/>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        </repository>
    </repositories>

qyvlik avatar Oct 09 '22 03:10 qyvlik

I'll do a proper release soon, as it's been a long while now.

timmolter avatar Oct 09 '22 08:10 timmolter