MultiversX Tracker is Live!

[PROBLEM] Python Binance Futures API Take Profits Orders or Stop Loss order and Position still active

Binance

Cryptocoins Exchanges / Binance 600 Views

I've just a little drawback, I exploit the https://fapi.binance.com base API for the Binance Futures, we now have a sign to open Long position on BTCUSDT at 16485.853 entry goal, and place 5 Take Income orders at 16733.087, 16897.945, 17062.803, 17310.092, 17474.948, 17722.235 and Cease Loss at 50% with Leverage 20x. I gather the tickSize for BTCUSDT is 'tickSize': '0.10' meaning for the worth parameter we will add after the comma just 1 decimal, for example for the entry goal 16485.853 we will set the worth 16485.8. I acquire the minQty for BTCUSDT is 'minQty': 'zero.001' meaning for the amount parameter we will add after the comma simply 3 decimals, for instance if i need to purchase BTCUSDT for 30$ with leverage 20x, the amount is equal to 30 * 20 / 16485.853 = 0.0363948410798034 and we set the quantity parameter to zero.036.

So, I begin with 30$ at leverage 20x, I open a Long position on BTCUSDT at 16485.853 (16485.eight after transformed with tickSize) meaning i obtain 0.0363948410798034 (0.036 after transformed with minQty) amount, this is the json for payload on the /fapi/v1/order endpoint:

open_position =
"image": 'BTCUSDT',
"aspect": 'BUY',
"positionSide": 'LONG',
"sort": "LIMIT",
"timeInForce": "GTC",
"quantity": '0.036',
"worth": '16485.eight'

After that I put the 5 Take Income orders and I would like every Take Profit Order to have 20% of the quantity so let's give instance of the primary Take Revenue, we've zero.036 / 5 = 0.0072 (0.007 after converted with minQty) for every of the Take Revenue Order at 16733.087 (16733.0 after transformed to tickSize). For example:

take_profit =
"image": 'BTCUSDT',
"aspect": 'SELL',
"positionSide": 'LONG',
"sort": 'TAKE_PROFIT',
"quantity": '0.007',
"stopPrice": '16733.0',
"worth": '16733.0'

And the remainder of four Take Income will probably be with the same amount at their worth.

After that I put the Stop Loss at 50% so, we've to set the stopPrice and worth parameters, for that I exploit the entry target 16485.853 * (1 - the cease loss % 50% for that we now have zero.5 / leverage 20x). 16485.853 * (1 - 0.5 / 20) = 16073.706675 ( 16073.7 transformed with the tickSize). For instance:

stop_loss =
"symbol": 'BTCUSDT',
"aspect": 'SELL',
"sort": "STOP",
"positionSide": 'LONG',
"amount": 'zero.036',
"stopPrice":'16073.7',
"worth": '16073.7'

And now my drawback is :

Why after all of the 5 Take Profit Orders accomplished I nonetheless have the Stop Loss Order lively and the BTCUSDT position lively? I feel because:

zero.036 / 5 take income = zero.0072 quantity per take revenue but we will use simply three decimals and we set zero.007 quantity per take profit but right here we stay zero.0002 amount for every of take revenue in complete we now have zero.0010 amount remaining in the air and for that cause we still have the place opened because we nonetheless have zero.0010 quantity there and in addition the Stop Loss continues to be there.

And in addition within the different case if the Stop Loss is executed, the place is closed because i set the quantity for the Stop Loss similar with the position amount but the 5 Take Income continues to be there lively.

Why after all the Take Income executed doesn't shut the place and the Cease Loss order? And vice versa after the Cease Loss executed the position closed and we still have the Take Income?

How can I clear up this drawback?

Thank you verry a lot, Nameless Billionaires!

submitted by /u/Adventurous_Class863
[link] [comments]
Get BONUS $200 for FREE!

You can get bonuses upto $100 FREE BONUS when you:
πŸ’° Install these recommended apps:
πŸ’² SocialGood - 100% Crypto Back on Everyday Shopping
πŸ’² xPortal - The DeFi For The Next Billion
πŸ’² CryptoTab Browser - Lightweight, fast, and ready to mine!
πŸ’° Register on these recommended exchanges:
🟑 Binance🟑 Bitfinex🟑 Bitmart🟑 Bittrex🟑 Bitget
🟑 CoinEx🟑 Crypto.com🟑 Gate.io🟑 Huobi🟑 Kucoin.



Comments