UPetit / python-binance-profit

Script to submit a buy order followed by an automatic sell OCO order
MIT License
47 stars 15 forks source link

[BUG] Account has insufficient balance for requested action while placing OCO order #20

Open JulienDev opened 3 years ago

JulienDev commented 3 years ago

Describe the bug Once the buy order is filled, the script was not able to sell what was bought because of this error :

Account has insufficient balance for requested action while placing

I've placed a 67 SUSHI order but probably because of the finance fees, I was only owning 66.970 SUSHI 🍣

Additional context

The order is not filled yet...
The buy order has been filled!
=========================
=== Buy order summary ===
=> Buy price: 15.360 USDT
=> Total price: 1029.120 USDT
=> Buy quantity: 67.000 SUSHI
=> Step 2 - Sell OCO order execution
Selling price (profit): 16.051
Stoploss price: 14.899
(Code 400) Account has insufficient balance for requested action.
Traceback (most recent call last):
  File "execute_orders.py", line 145, in <module>
    input_args=input_args_validated
  File "execute_orders.py", line 74, in main
    input_args.loss,
  File "/home/pi/python-binance-profit/app/client.py", line 515, in execute_sell_strategy
    sell_orders = sell_order["orderReports"]
KeyError: 'orderReports'
UPetit commented 3 years ago

Hey @JulienDev Which buy order did you place? Limit or Market? I'm just trying to understand why you didn't get the quantity you requested with the buy order...

JulienDev commented 3 years ago

Limit, always limit :)

Avik-Jain commented 3 years ago

@JulienDev @UPetit Found any solution ? I am stuck with the same bug.

gogetta69 commented 3 years ago

Same problem for me as well. Anyone have a fix for this?

UPetit commented 3 years ago

The problem with fees is that they're paid by following two scenarios:

At the second step (sell) of the script, it is expecting to sell the exact quantity that has been bought during the first step of the logic which doesn't seem to be always true...: In case you don't own BNB and we're in the second scenario I've just mentioned, then the quantity you bought is slightly different from the quantity input parameter so the script is trying to sell more than what you really have.

It's not very straightforward to check how you paid your fees for each trade (BNB or not).

I need to evaluate what is the best option here for a fix. The first one I can think of right now is to check the current fees for the crypto pair you selected then calculate the quantity to sell by deducting the estimated fees from the quantity that has been bought.

I'll investigate and try few solutions 🤞

gogetta69 commented 3 years ago

I can confirm that as long as you have a BNB balance the oco selling works.

UPetit commented 3 years ago

I can confirm that as long as you have a BNB balance the oco selling works.

Makes sense, thanks for checking. The idea is thus to estimate the fees before creating the buy order 👍 I'll see how I can integrate that to the script.