从官方文档中我发现了这个:
import bybit
client = bybit.bybit(test=True, api_key="api_key", api_secret="api_secret")
print(client.LinearOrder.LinearOrder_new(
side="Sell",
symbol="BTCUSDT",
order_type="Limit",
qty=0.22,
price=10000,
time_in_force="GoodTillCancel",
reduce_only=False,
close_on_trigger=False
).result())
还可以发送附加参数take_profit和stop_loss。然后,止盈价和止损价将与订单一起放置。
我想知道是否有办法在下单后下达止盈止损订单。官方文档中没有示例,我也不明白其中为这些订单编写的任何说明。
提前谢谢
最佳答案
是的,可以在建仓后附加这些订单。在文档中,他们引用了 set stop,这也包含在 Bybit python 安装中的 test.py 文档页面中
这是文档的链接
以下是多头头寸的止损和止盈价。请注意,长期以来,我们为侧面参数设置了当前的位置。 (买入)
# Stop Loss
print(client.LinearPositions.LinearPositions_tradingStop(
symbol="BTCUSDT",
side="Buy",
stop_loss=41000).result())
# Take profit
print(client.LinearPositions.LinearPositions_tradingStop(
symbol="BTCUSDT",
side="Buy",
take_profit=49000).result())
补充说明:TP订单是条件订单,这意味着它们一旦触发就会发送到订单簿,从而产生市价订单。如果您已经知道您的目标水平,限价单可能更合适。这将转入您的有效订单,您必须取消这些订单。我们对此使用卖出参数:
# Limit order
print(client.LinearOrder.LinearOrder_new(
side="Sell",
symbol="BTCUSDT",
order_type="Limit",
qty=0.001,
price=49000,
time_in_force="GoodTillCancel",
reduce_only=True,
close_on_trigger=False).result())
干杯我的 friend ,祝你编码和交易好运!
关于python - 拜比特 API : is there a way to place Take Profit & Stop Loss orders after a opening a position?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69184604/