简体   繁体   English

如何向币安发送OCO订单

[英]How to send OCO order to binance

I would like to ask you for help.我想请你帮忙。 I´m trying to change python code from sending limit/market order to OCO order through api to binance.我正在尝试将 python 代码从通过 api 发送限价/市场订单到 OCO 订单更改为 binance。 I can make limit order, market order, stop loss limit order.我可以做限价单、市价单、止损限价单。 I can´t figure out how to place OCO order...我不知道如何下 OCO 订单...

When I used limit order I was sending order_type=ORDER_TYPE_LIMIT then I used order = client.create_order() and it was working.当我使用限价单时,我发送了 order_type=ORDER_TYPE_LIMIT 然后我使用了 order = client.create_order() 并且它正在工作。 When I wanted to send market order I used order_type=ORDER_TYPE_MARKET but when I want to make OCO order the only option that I found that should work is: order = client.create_oco_order() without order_type but here I´m getting error 1013 Stop loss is not supported for this symbol...当我想发送市场订单时,我使用了 order_type=ORDER_TYPE_MARKET 但是当我想下 OCO 订单时,我发现应该工作的唯一选项是: order = client.create_oco_order() without order_type 但在这里我收到错误 1013 止损不支持此符号...

I checked https://api.binance.com/api/v1/exchangeInfo我检查了https://api.binance.com/api/v1/exchangeInfo

and there is this "orderTypes":["LIMIT","LIMIT_MAKER","MARKET","STOP_LOSS_LIMIT","TAKE_PROFIT_LIMIT"],"icebergAllowed":true,"ocoAllowed":true,还有这个 "orderTypes":["LIMIT","LIMIT_MAKER","MARKET","STOP_LOSS_LIMIT","TAKE_PROFIT_LIMIT"],"icebergAllowed":true,"ocoAllowed":true,

So I can´t use order_type.所以我不能使用 order_type。 There is not ORDER_TYPE_OCO and ocoAllowed is true so I should be able to send oco order.没有 ORDER_TYPE_OCO 并且 ocoAllowed 是真的,所以我应该能够发送 oco 订单。 But I´m getting "error 1013: Stop loss orders are not supported for this symbol. order failed".但我收到“错误 1013:此交易品种不支持止损订单。订单失败”。

What I want is to set "price" as limit sell order to take profit highier when price will get there and to set stop loss "stopPrice" lower if price will go down...at once.我想要的是将“价格”设置为限价卖单,以便在价格到达那里时获得更高的利润,并在价格将 go 立即下跌时将止损“stopPrice”设置得更低。 This is how OCO should works.这就是 OCO 的工作方式。

Can somebody please give me an advice how to do it?有人可以给我一个建议吗? I´m not python guru I´m just changing one code that I found and what I understand is if oco is allowed stop loss should be allowed too.我不是 python 大师我只是更改我找到的一个代码,我的理解是如果允许 oco 也应该允许止损。 Thanks谢谢

so that all interested have a precise answer about the solution of this problem, I include the code with the comments.为了让所有感兴趣的人都能对这个问题的解决方案有一个准确的答案,我在注释中包含了代码。

I'll use an OCO sell order as an example in BTCUSDT.我将以 BTCUSDT 中的OCO 卖单为例。

Imagine I have 1 BTC.想象一下我有 1 个比特币。 The current price is at 30157.85 and I want to sell 1 BTC much higher at 32000.07当前价格为 30157.85,我想以 32000.07 高得多的价格卖出 1 BTC

But the price does not rise and begins to fall, so I place my stopPrice at 29283.03 where the limit sell order will be opened at the price 29000.00但是价格没有上涨并开始下跌,所以我将 stopPrice 设置在 29283.03,限价卖单将以 29000.00 的价格开仓

This means that I will sell at 32000.07 or 29000.00 USDT.这意味着我将以 32000.07 或 29000.00 USDT 的价格卖出。 The order is written as follows:顺序写如下:

order= client.order_oco_sell(
    symbol= 'BTCUSDT',                                            
    quantity= 1.00000,                                            
    price= '32000.07',                                            
    stopPrice= '29283.03',                                            
    stopLimitPrice= '29000.00',                                            
    stopLimitTimeInForce= 'FOK')

Note that the OCO order requires the stopLimitTimeInForce parameter.请注意,OCO 订单需要 stopLimitTimeInForce 参数。 I have used the value 'FOK' but I leave you here the description of the different values that you can use: https://help.bybit.com/hc/en-us/articles/360039749233-What-are-time-in-force-TIF-GTC-IOC-FOK-我使用了值“FOK”,但我在这里留下了您可以使用的不同值的描述: https://help.bybit.com/hc/en-us/articles/360039749233-What-are-time-有效-TIF-GTC-IOC-FOK-

Note well that the price, stopPrice, stopLimitPrice and stopLimitTimeInForce parameters are strings and not float or decimal.请注意,price、stopPrice、stopLimitPrice 和 stopLimitTimeInForce 参数是字符串,而不是浮点数或小数。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM