question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Futures order with TAKE_PROFIT_MARKET same time

See original GitHub issue

Here’s my achievement that’s what I’m trying to make on API:

Create an order for BTCUSDT from 53000 price with 0.005 quantity and set TP value as markprice=54000 when order executed. This is what I can do from app as like this:

image

I tried with this code block:

await binance.futuresOrder( 'BUY', 'BTCUSDT', 0.005, 53000, { type: 'TAKE_PROFIT', stopPrice: 54000 } )

Which will send the request with these parameters:

{
  type: 'TAKE_PROFIT',
  stopPrice: 54000,
  symbol: 'BTCUSDT',
  side: 'BUY',
  quantity: 0.005,
  price: 53000,
  timeInForce: 'GTX'
}

But order opening as wrong way like this:

image

However when I place the order from app it shows like this:

image

When I click on View under TP/SL it shows a condition like this:

image

How can I achieve this via API?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:6
  • Comments:21 (3 by maintainers)

github_iconTop GitHub Comments

14reactions
laukikkcommented, May 25, 2021

Using the python-binance package I was able to achieve in putting the Stop Loss and Take Profit in 3 different actions:

order = client.futures_create_order(
            symbol='ETHUSDT', side=SIDE_BUY, type=ORDER_TYPE_MARKET, quantity=quantity, isolated=True, positionSide=positionSide)
        client.futures_create_order(
            symbol='ETHUSDT', side=SIDE_SELL, type=FUTURE_ORDER_TYPE_STOP_MARKET, quantity=quantity, positionSide=positionSide, stopPrice=stopLoss, timeInForce=TIME_IN_FORCE_GTC)
        client.futures_create_order(
            symbol='ETHUSDT', side=SIDE_SELL, type=FUTURE_ORDER_TYPE_TAKE_PROFIT_MARKET, quantity=quantity, positionSide=positionSide, stopPrice=takeProfit, timeInForce=TIME_IN_FORCE_GTC)

But still not able to execute the same order in the same line. Though for the time being it works as desired.

EDIT: Now after using it I’ve come across problems that if for example even if the Stop Loss is triggered then the Take Profit order is still there and it interferes with my later orders. For this then I had to write down another logic to get the order Id of my stop losses and take profits and cancel them every time either one is triggered. The need for a single command now is axiomatic.

10reactions
alessandromotaacommented, Dec 28, 2021

I was able to solve this problem by adding these arguments timeInForce=‘GTE_GTC’, workingType=‘MARK_PRICE’, priceProtect=True. Remember that I’m using mode position = HEDGE, for this reason I have to inform the positionSide argument.

`coin = ‘BTCUSDT’ qtd = 0.001

SELL order

buy_limit = client.futures_create_order( symbol=coin, side=‘BUY’, positionSide=‘LONG’, type=‘MARKET’, quantity=0.001 )

tp = round(45000,2) # TakeProfit = 45000

sl = round(50000,2) # StopLoss = 50000

TAKE_PROFIT_MARKET order

sell_gain_market = client.futures_create_order( symbol=coin, side=‘SELL’, positionSide=‘LONG’, type=‘TAKE_PROFIT_MARKET’, stopPrice=tp, closePosition=True, timeInForce=‘GTE_GTC’, workingType=‘MARK_PRICE’, priceProtect=True )

STOP_MARKET order

sell_stop_market = client.futures_create_order( symbol=coin, side=‘SELL’, positionSide=‘LONG’, type=‘STOP_MARKET’, stopPrice=sl, closePosition=True, timeInForce=‘GTE_GTC’, workingType=‘MARK_PRICE’, priceProtect=True ) `

Read more comments on GitHub >

github_iconTop Results From Across the Web

Futures Order Types - Kraken Support
This article details the order types available when trading futures contracts. For spot and margin trading order types, see Summary of Order Options....
Read more >
Futures PlaceOrder and - set up take profit #734 - GitHub
I try to find solution about place order. How can i set Take profit when i place order? var otwarte_pozycje = client.FuturesUsdt.Order.
Read more >
12. Advanced Order Types: Conditional Orders - Kraken Futures
Key points: - Conditional orders allow you to set trigger prices and actions, and can be a valuable tool for certain strategies.
Read more >
Take Profit Orders On Kraken: Use Market Or Limit Order?
Today we'll look at what a take profit order is and what the differences are between a take profit market order and take...
Read more >
What is a market if touched order-FUTU Help Center
If you submit a sell take profit market order at a take profit trigger price of 15 when the market ... You can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found