unterstein / binance-trader

Experimental trading bot for crypto currency on Binance.com
Apache License 2.0
274 stars 144 forks source link

error, the bot is trying to resell the full amount of what we bought. not taking account fees ? #4

Open DokRaphael opened 6 years ago

DokRaphael commented 6 years ago

Hi The bot bought 500 XVG When he tries to sell I get :

2018-01-04 20:13:26.570  INFO 15 --- [pool-1-thread-1] io.github.unterstein.BinanceTrader       : Tradingbalance: AssetBalance[asset=XVG,free=499.50000000,locked=0.00000000]
2018-01-04 20:13:26.570  INFO 15 --- [pool-1-thread-1] io.github.unterstein.BinanceTrader       : Order filled, let`s sell!
2018-01-04 20:13:26.570  INFO 15 --- [pool-1-thread-1] io.github.unterstein.TradingClient       : Selling 500 for 0.00017219

2018-01-04 20:13:27.962 ERROR 15 --- [pool-1-thread-1] io.github.unterstein.BinanceTrader       : Unable to perform ticker

com.binance.api.client.exception.BinanceApiException: Account has insufficient balance for requested action.
lhilarides commented 6 years ago

As a temporary workaround you could use BNB coins to pay for fees (see binance settings), so the fee is not subtracted from the coins when you buy them. This way the buy amount will equal the sell amount.

dengo1905 commented 6 years ago

I have the same problem...and I'm using BNB but still got that error when selling and buying and most of the times exception happens when I'm low on funds... I think that calculates fees somewhere.

gu3nter commented 6 years ago

as workaround (for BTC trading too) you can change in TradingClient.java:

NewOrder order = new NewOrder(symbol, OrderSide.SELL, OrderType.LIMIT, TimeInForce.GTC, "" + quantity, priceString);

to:

NewOrder order = new NewOrder(symbol, OrderSide.SELL, OrderType.LIMIT, TimeInForce.GTC, "" + Double.valueOf(getTradingBalance().getFree()).intValue(), priceString);

But note: After the change, all currencies >1 gets sold, so i you want to hold funds than do not change TradingClient.java.