![](/img/trans.png)
[英]How to place a market futures order with take profit and stop loss on Binance API Python?
[英]Python Binance Futures Take Profit and Stop Loss order API Error 2021 Order would immediately trigger
我写了一个交易机器人,在期货账户上进行保证金交易。 我在下面分享的一段代码只运行了一次。 然后它开始给出以下错误: APIError(code=-2021): 订单将立即触发。 问题是当我将这段代码(与打开 position 并给出止盈和止损订单相关的部分)复制并粘贴到新文件并运行它时,它工作正常,但在机器人中出现错误。 我找不到问题的原因。
如果 currentdiff > 0:
buy_order = client.futures_create_order(symbol='SOLBUSD',
side='BUY',
type ='MARKET',
quantity = qty,
positionSide='LONG')
poisiton = "LONG"
stopprice = currentprice - (value*1.2)
takeprofit = currentprice + (value*1.2)
stopprice = round(stopprice,2)
takeprofit = round(takeprofit,2)
print("Take profit : ", takeprofit)
print("Stop price : ", stopprice)
tp_order = client.futures_create_order(symbol='SOLBUSD',
side='SELL',
positionSide='LONG',
type ='TAKE_PROFIT_MARKET',
timeInForce='GTE_GTC',
quantity = qty,
stopPrice=stopprice,
workingType='MARK_PRICE'
)
sl_order = client.futures_create_order(symbol='SOLBUSD',
side='SELL',
positionSide='LONG',
type ='STOP_MARKET',
timeInForce='GTE_GTC',
quantity = qty,
stopPrice=takeprofit,
workingType='MARK_PRICE'
)
好像你搞砸了你发送的参数
检查 API 文档。 这一切都在那里
For TRAILING_STOP_MARKET, if you got such error code.
{"code": -2021, "msg": "Order would immediately trigger."}
means that the parameters you send do not meet the following requirements:
BUY: activationPrice should be smaller than latest price.
SELL: activationPrice should be larger than latest price.
https://binance-docs.github.io/apidocs/futures/en/#new-order-trade
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.