资源加载中... loading...

通过exchange.IO调用币安市价止盈API时,报错“{"code": -2021, "msg": "Order would immediately trigger."}”,但直接用exchange.Buy(-1,quantity),就不会报错。

Author: 风影1124, Created: 2023-10-05 16:48:10, Updated: 2023-10-08 11:40:34

1、调用币安API接口:
var message = "symbol=ETHUSDT&side=BUY&positionSide=SHORT&type=TAKE_PROFIT_MARKET&closePosition=true&stopPrice="+ticker.Last+"&timestamp=" + Date.now();

var orderInfos = exchange.IO("api", "POST", "/fapi/v1/order", message);

报错信息:“{"code": -2021, "msg": "Order would immediately trigger."}”

2、直接用FMZ的exchange.Buy(-1,quantity),就不会报错。

More

发明者量化-小小梦 看上去,代码写的不太对: ``` var message = "symbol=" + "ETHUSDT" + "&side=BUY" + orderid +"&positionSide=SHORT" +"&type="+"TAKE_PROFIT_MARKET"+"closePosition=true"+"&stopPrice="+ticker.Last+"&timestamp=" + Date.now(); ``` 其中```orderid ```没有参数名,只有一个值。```closePosition ```前也少写了```&```符号。 建议再检查看下。

发明者量化-小小梦 Order would immediately trigger. 这个报错是交易所接口返回的,看字面意思应该是参数设置有误,会导致订单直接成交。

风影1124 就是判断市价达到计算的止盈价格时,Exchange.IO调用TAKE_PROFIT_MARKET类型进行市价止盈,会报: Order would immediately trigger.(偶发性) 但用fmz api就能够马上成交,不会报错,如下: exchange.SetDirection("closebuy"); exchange.Sell(-1, quantity);

发明者量化-小小梦 exchange.IO 调用时不用传入时间戳之类的参与签名的参数。要看具体报错信息。

风影1124 已更新。 var message = "symbol=ETHUSDT&side=BUY&positionSide=SHORT&type=TAKE_PROFIT_MARKET&closePosition=true&stopPrice="+ticker.Last+"&timestamp=" + Date.now();