XChange icon indicating copy to clipboard operation
XChange copied to clipboard

Android: BinanceTradeService invalid signature with Android API level 24

Open bschnider opened this issue 2 years ago • 0 comments

I am trying to extract trades from my Binance account with the following code:

ExchangeSpecification exSpec = new BinanceExchange().getDefaultExchangeSpecification();
// Define API key
exSpec.setApiKey(keys.get(i).getAPIKey());
exSpec.setSecretKey(keys.get(i).getAPISecretKey());
Exchange binance = ExchangeFactory.INSTANCE.createExchange(exSpec);

TradeService tradeService = binance.getTradeService();

try {
    // Get trades
    BinanceTradeHistoryParams param = new BinanceTradeHistoryParams(new CurrencyPair("BTC", "USDT"));
    List<UserTrade> trades = tradeService.getTradeHistory(param).getUserTrades();  // RAISES AN ERROR
} catch (IOException e) {
    Log.d("TEST1", "Something went wrong");
    e.printStackTrace();
}

This code works on a device with an Android API level of 30 but fails with another device whose API level is 24. On this latter device, the following error is raised:

2022-04-07 00:09:13.538 11013-11073/com.example.trackmycrypto E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
    Process: com.example.trackmycrypto, PID: 11013
    java.lang.RuntimeException: An error occurred while executing doInBackground()
        at android.os.AsyncTask$3.done(AsyncTask.java:318)
        at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
        at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
        at java.util.concurrent.FutureTask.run(FutureTask.java:242)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
        at java.lang.Thread.run(Thread.java:762)
     Caused by: org.knowm.xchange.binance.dto.BinanceException: -1022: Signature for this request is not valid.
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
        at com.fasterxml.jackson.databind.introspect.AnnotatedConstructor.call(AnnotatedConstructor.java:124)
        at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.createFromObjectWith(StdValueInstantiator.java:274)
        at com.fasterxml.jackson.databind.deser.ValueInstantiator.createFromObjectWith(ValueInstantiator.java:228)
        at com.fasterxml.jackson.databind.deser.impl.PropertyBasedCreator.build(PropertyBasedCreator.java:189)
        at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeUsingPropertyBased(BeanDeserializer.java:421)
        at com.fasterxml.jackson.databind.deser.std.ThrowableDeserializer.deserializeFromObject(ThrowableDeserializer.java:65)
        at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:159)
        at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4001)
        at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3030)
        at si.mazi.rescu.serialization.jackson.JacksonResponseReader.read(JacksonResponseReader.java:53)
        at si.mazi.rescu.serialization.jackson.JacksonResponseReader.readException(JacksonResponseReader.java:58)
        at si.mazi.rescu.ResponseReader.read(ResponseReader.java:82)
        at si.mazi.rescu.RestInvocationHandler.mapInvocationResult(RestInvocationHandler.java:169)
        at si.mazi.rescu.RestInvocationHandler.receiveAndMap(RestInvocationHandler.java:157)
        at si.mazi.rescu.RestInvocationHandler.invoke(RestInvocationHandler.java:120)
        at java.lang.reflect.Proxy.invoke(Proxy.java:813)
        at $Proxy5.myTrades(Unknown Source)
        at org.knowm.xchange.binance.service.BinanceTradeServiceRaw.myTrades(BinanceTradeServiceRaw.java:67)
        at org.knowm.xchange.binance.service.BinanceTradeService.getTradeHistory(BinanceTradeService.java:156)
        at com.example.trackmycrypto.SynchronizeAdapter$ProgressTask.doInBackground(SynchronizeAdapter.java:368)
        at com.example.trackmycrypto.SynchronizeAdapter$ProgressTask.doInBackground(SynchronizeAdapter.java:296)
        at android.os.AsyncTask$2.call(AsyncTask.java:304)
        at java.util.concurrent.FutureTask.run(FutureTask.java:237)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 
        at java.lang.Thread.run(Thread.java:762) 
2022-04-07 00:09:13.541 11013-11013/com.example.trackmycrypto D/TextView: setTypeface with style : 0
2022-04-07 00:09:13.545 11013-11013/com.example.trackmycrypto D/TextView: setTypeface with style : 0
2022-04-07 00:09:13.551 11013-11013/com.example.trackmycrypto D/TextView: setTypeface with style : 0
2022-04-07 00:09:13.553 11013-11013/com.example.trackmycrypto D/TextView: setTypeface with style : 0
2022-04-07 00:09:13.556 11013-11013/com.example.trackmycrypto D/TextView: setTypeface with style : 0
2022-04-07 00:09:13.560 11013-11013/com.example.trackmycrypto D/TextView: setTypeface with style : 0
2022-04-07 00:09:13.563 11013-11013/com.example.trackmycrypto D/TextView: setTypeface with style : 0
2022-04-07 00:09:13.565 11013-11013/com.example.trackmycrypto D/TextView: setTypeface with style : 0
2022-04-07 00:09:13.576 11013-11013/com.example.trackmycrypto D/TextView: setTypeface with style : 0
2022-04-07 00:09:13.579 11013-11013/com.example.trackmycrypto D/TextView: setTypeface with style : 0
2022-04-07 00:09:13.582 11013-11013/com.example.trackmycrypto D/TextView: setTypeface with style : 0
2022-04-07 00:09:13.593 11013-11013/com.example.trackmycrypto D/TextView: setTypeface with style : 0
2022-04-07 00:09:13.597 11013-11013/com.example.trackmycrypto D/TextView: setTypeface with style : 0
2022-04-07 00:09:13.599 11013-11013/com.example.trackmycrypto D/TextView: setTypeface with style : 0
2022-04-07 00:09:13.675 11013-11013/com.example.trackmycrypto D/TextView: setTypeface with style : 0
2022-04-07 00:09:13.684 11013-11013/com.example.trackmycrypto D/TextView: setTypeface with style : 0
2022-04-07 00:09:13.689 11013-11013/com.example.trackmycrypto D/TextView: setTypeface with style : 0
2022-04-07 00:09:13.885 11013-11013/com.example.trackmycrypto D/TextView: setTypeface with style : 0
2022-04-07 00:09:13.887 11013-11013/com.example.trackmycrypto D/TextView: setTypeface with style : 0
2022-04-07 00:09:13.889 11013-11013/com.example.trackmycrypto D/TextView: setTypeface with style : 0

I did not manage to extract the API request or to identify the problematic piece of code. I am using xchange-binance 4.3.4. XChange 4.3.4 was the latest version that worked for Kraken API with an Android API level of 24 (using a version > 4.3.4 would bring an unsupported dependency), which is the reason why I am using an older version. I can, however, confirm that the same error is raised with xchange-binance 5.0.13.

#2621 seems to present a similar issue, but since the invalid signature error is quite common and vague, it could also be completely unrelated.

Has anyone faced this issue before ? Would anyone have some suggestions to help me figure out what could be causing this error ? Or alternatively, would there be some alternative solutions to extract the trade history from a Binance account with XChange ?

bschnider avatar Apr 06 '22 22:04 bschnider