knowm / XChange

XChange is a Java library providing a streamlined API for interacting with 60+ Bitcoin and Altcoin exchanges providing a consistent interface for trading and accessing market data.
http://knowm.org/open-source/xchange/
MIT License
3.84k stars 1.94k forks source link

[Binance] cannot make more than 500 withdrawals #4682

Open pvyhnal-generalbytes opened 1 year ago

pvyhnal-generalbytes commented 1 year ago

Our customer reported seeing the following exception:

org.knowm.xchange.binance.dto.BinanceException: Number of saved withdrawal addresses cannot exceed 500. (HTTP status code: 400)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.fasterxml.jackson.databind.introspect.AnnotatedConstructor.call(AnnotatedConstructor.java:124)
at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.createFromObjectWith(StdValueInstantiator.java:291)
at com.fasterxml.jackson.databind.deser.ValueInstantiator.createFromObjectWith(ValueInstantiator.java:288)
at com.fasterxml.jackson.databind.deser.impl.PropertyBasedCreator.build(PropertyBasedCreator.java:202)
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeUsingPropertyBased(BeanDeserializer.java:454)
at com.fasterxml.jackson.databind.deser.std.ThrowableDeserializer.deserializeFromObject(ThrowableDeserializer.java:65)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:195)
at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:322)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4591)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3546)
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:113)
at com.sun.proxy.$Proxy113.withdraw(Unknown Source)
at org.knowm.xchange.binance.service.BinanceAccountServiceRaw.lambda$withdraw$1(BinanceAccountServiceRaw.java:56)
at org.knowm.xchange.client.ResilienceUtils$DecorateCallableApi.call(ResilienceUtils.java:86)
at org.knowm.xchange.binance.service.BinanceAccountServiceRaw.withdraw(BinanceAccountServiceRaw.java:68)
at org.knowm.xchange.binance.service.BinanceAccountServiceRaw.withdraw(BinanceAccountServiceRaw.java:40)
at org.knowm.xchange.binance.service.BinanceAccountService.withdrawFunds(BinanceAccountService.java:131)

and Binance support told them:

If you provide the "name" parameter when calling /sapi/v1/capital/withdraw/apply, the address will be automatically added to the whitelist of addresses. In this case, do not specify the "name" parameter when making an API withdrawal. The total number of addresses whitelisted cannot exceed 500

The API spec says the name parameter is optional but the code has a comment saying it might be not?

https://github.com/knowm/XChange/blob/xchange-5.0.12/xchange-binance/src/main/java/org/knowm/xchange/binance/service/BinanceAccountServiceRaw.java#L38

We're on version 5.0.12

timmolter commented 1 year ago

If you submit a PR with the fix, we'll gladly merge it.

TheCookieLab commented 1 year ago

To clarify, is your issue with the name parameter or the fact that you cannot retrieve more than 500 whitelisted addresses?

pvyhnal-generalbytes commented 1 year ago

as the quoted response from binance says, when we have the "name" parameter in the "withdraw" request, then the address is stored in a binance whitelist. (this does not seem to be documented). When the whitelist is full (500 addresses) new withdrawals with the "name" parameter fail because they cannot add the address to the whitelist.

I think the solution is just to omit the "name" parameter, but it the xchange code mentions it's mandatory. the api spec doesn't say that so it would have to be tested. Maybe it was mandatory in the past