[英]How to place a market futures order with take profit and stop loss on Binance API Python?
I want to place a market long order with take profit and stop loss and a short position the same way.我想以相同的方式下一个带有止盈止损和空头头寸的市场多头订单。 I need to use leverage and isolated mode.我需要使用杠杆和孤立模式。 I have configured the leverage, isolated mode, how much margin I want to use, and the quantity.我已经配置了杠杆、隔离模式、我要使用多少保证金以及数量。 I have a problem understanding the Binance docs.我在理解 Binance 文档时遇到问题。 Can somebody provide me the code I need to use to place a market long order with take profit and stop loss and a short position?有人可以提供我需要使用的代码来下一个带有止盈止损和空头头寸的市场多头订单吗?
As I understand, you can't do it in one order via Binance API据我了解,您不能通过 Binance API 一次性完成
You need to place 3 orders in order to implement this:您需要下 3 个订单才能执行此操作:
This is the way that Binance handles your margin order with both stop-loss and take profit这是币安通过止损和获利处理您的保证金订单的方式
It can be done like this for SHORT position in python (if you need to open LONG instead of SHORT just change "BUY" to "SELL" and "SELL" to "BUY":对于 python 中的 SHORT 位置,可以这样做(如果您需要打开 LONG 而不是 SHORT,只需将“BUY”更改为“SELL”并将“SELL”更改为“BUY”:
from binance import Client
client = Client(api_key, api_secret)
quantity = 0.001
symbol = "BTCUSDT"
tp_price = 22800
sl_price = 22000
client.futures_create_order(symbol=symbol, side="SELL", type="MARKET", quantity=quantity)
client.futures_create_order(symbol=symbol, side="BUY", type="TAKE_PROFIT_MARKET", quantity=quantity, stopPrice=tp_price)
client.futures_create_order(symbol=symbol, side="BUY", type="STOP_MARKET", quantity=quantity, stopPrice=sl_price)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.