简体   繁体   English

如何在 Binance API Python 上设置止盈止损的市场期货订单?

[英]How to place a market futures order with take profit and stop loss on Binance API Python?

I want to place a market long order with take profit and stop loss and a short position the same way.我想以相同的方式下一个带有止盈止损和空头头寸的市场多头订单。 I need to use leverage and isolated mode.我需要使用杠杆和孤立模式。 I have configured the leverage, isolated mode, how much margin I want to use, and the quantity.我已经配置了杠杆、隔离模式、我要使用多少保证金以及数量。 I have a problem understanding the Binance docs.我在理解 Binance 文档时遇到问题。 Can somebody provide me the code I need to use to place a market long order with take profit and stop loss and a short position?有人可以提供我需要使用的代码来下一个带有止盈止损和空头头寸的市场多头订单吗?

As I understand, you can't do it in one order via Binance API据我了解,您不能通过 Binance API 一次性完成

You need to place 3 orders in order to implement this:您需要下 3 个订单才能执行此操作:

  1. Initial order to open your SHORT or LONG position (type: "BUY" for long; type: "SELL" for short)建立您的空头或多头头寸的初始订单(输入:“买入”为多头;输入:“卖出”为空头)
  2. TAKE-PROFIT order获利订单
  3. STOP order停止订单

This is the way that Binance handles your margin order with both stop-loss and take profit这是币安通过止损和获利处理您的保证金订单的方式

It can be done like this for SHORT position in python (if you need to open LONG instead of SHORT just change "BUY" to "SELL" and "SELL" to "BUY":对于 python 中的 SHORT 位置,可以这样做(如果您需要打开 LONG 而不是 SHORT,只需将“BUY”更改为“SELL”并将“SELL”更改为“BUY”:

from binance import Client

client = Client(api_key, api_secret)
quantity = 0.001
symbol = "BTCUSDT"
tp_price = 22800
sl_price = 22000

client.futures_create_order(symbol=symbol, side="SELL", type="MARKET", quantity=quantity)
client.futures_create_order(symbol=symbol, side="BUY", type="TAKE_PROFIT_MARKET", quantity=quantity, stopPrice=tp_price)
client.futures_create_order(symbol=symbol, side="BUY", type="STOP_MARKET", quantity=quantity, stopPrice=sl_price)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 python-binance 下达带有止盈和止损的期货市场订单 - How to place a Futures Market order with Take Profit and Stop Loss using python-binance Python 币安期货止盈止损订单 API 错误 2021 订单将立即触发 - Python Binance Futures Take Profit and Stop Loss order API Error 2021 Order would immediately trigger 如何使用 python-binance 下期货市场订单:APIError(code=-1111): Precision is over the maximum defined for this assets - How to place a futures market order using python-binance: APIError(code=-1111): Precision is over the maximum defined for this asset Python Binance Futures - 创建止盈限价订单时出现问题 ->(APIError(代码=-2021):订单会立即触发。) - Python Binance Futures - problem creating Take Profit Limit order -> (APIError(code=-2021): Order would immediately trigger.) 如何在 python 中使用 ccxt 制作币安期货订单? - How to make a binance futures order with ccxt in python? 使用 ccxt 创建带止盈和止损的合约订单 - Create Contract order with Take Profit and Stop Loss with ccxt 在 Python 中实现止损/获利的最佳方法 - Best Approach to implement Stop Loss / Take Profit in Python 无法使用币安设置止损限价单 Python API - Unable to set the STOP-LOSS limit order using Binance Python API 如何取消期货币安订单? - How to cancel futures binance order? python-binance 中的止损限价单 API - Stop Limit Order in python-binance API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM