python - 拜比特 API : is there a way to place Take Profit & Stop Loss orders after a opening a position?

标签 python api trading cryptocurrency

从官方文档中我发现了这个:

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_profitstop_loss。然后,止盈价和止损价将与订单一起放置。

我想知道是否有办法在下单后下达止盈止损订单。官方文档中没有示例,我也不明白其中为这些订单编写的任何说明。

提前谢谢

最佳答案

是的,可以在建仓后附加这些订单。在文档中,他们引用了 set stop,这也包含在 Bybit python 安装中的 test.py 文档页面中

这是文档的链接

Bybit Set Stop

以下是多头头寸的止损和止盈价。请注意,长期以来,我们为侧面参数设置了当前的位置。 (买入)

# 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/

相关文章:

python - 强制 Dlib python 安装时只支持 CPU;在带有 Cuda 和一切的 GPU 机器上

python - 为什么所有异常都被 ldap.SERVER_DOWN 捕获?

python - 如何创建带有可选参数的 Python 函数?

api - 如果客户端 IP 白名单,我是否仍应使用 API key

c# - 如何在 C# 中使用 QuickFix 读取多边定单的边?

pine-script - 如何使用 barstate.islastconfirmedhistory

python - bigquery 的意外关键字参数 'type'

java - 相当于 Google Ads API 中的 AD_PERFORMANCE_REPORT?

api - 我应该为我的 API 使用哪种身份验证策略?

python - python ebay sdk中如何添加多张图片