Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Futures订单能否加上TP/SL一键设置机制? #3

Open
TillLindemann opened this issue Mar 12, 2023 · 1 comment
Open

Futures订单能否加上TP/SL一键设置机制? #3

TillLindemann opened this issue Mar 12, 2023 · 1 comment

Comments

@TillLindemann
Copy link

Hi,
目前我用官方的python-binance,它没有对Futures Order做TP/SL一键设置,目前查询到以及目前我正在使用的有瑕疵的方式是:

//创建买入Limit订单
client.futures_create_order(symbol="BTCUSDT",side='BUY',type='LIMIT',quantity=quantity,timeinforce='GTC',price = entry_price)
//创建Market止损订单
client.futures_create_order(symbol="BTCUSDT",side = 'SELL',type ='STOP_MARKET',stopPrice=stop_price,closePosition='true')
//创建Market止盈订单
client.futures_create_order(symbol="BTCUSDT",side = 'SELL',type ='TAKE_PROFIT_MARKET',stopPrice=profit_price,closePosition='true')

即一次发出三次独立委托,在大多数情况下,这么设置是可行的,但是有些情况下会出现比较危险的状况。

上述的止损止盈订单虽然加上了closePosition参数,即只做减仓动作,不会主动开仓,但是价格触及之后无论账户有没有仓位,它都会执行并Fill。

于是就会衍生出一种情况是:
假如当前BTC的价格为100美金,我在90美金挂入Limit Buy Order,止损价格为80美金,止盈价格为110美金,我会同时发出上述三笔order。假如价格此时没有回落,而是直接上涨达到110美金,那么止盈订单会触发,由于没有仓位可减少,该止盈订单会Fill然后消失,此时我委托的订单就只有Limit Buy 和 Market止损,假如此时价格回落到90美金,我的Buy Order被执行,此时我的交易就只有止损订单而没有止盈订单,除非我时刻盯着手机看,否则这笔订单几乎就是一定会被止损,即使打到了止盈线。

当然也有一种解决办法是利用Websocket监控Limit Buy的订单状态,不一次性发出三笔订单,而是监控Buy order的状态,只等它Full Filled之后再发出后两笔订单,但是我找遍了全网也没有找到相应的文档和Code,大多数都是比较支离破碎的Code。

而币安的APP上,你可以看到它在Limit Buy Order订单上加上止盈止损后,它采取的方式是假如buy被执行,才发出止损和止盈的委托,而且任意止盈止损订单被执行后就会取消另一个,如下图:
image

@pyted
Copy link
Owner

pyted commented Mar 12, 2023

我没有使用过交易所自带的止盈止损策略,但是遇到过类似的问题,并以合理解决,可以加我微信沟通——kzl_knight

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants