ccxt: binance - oco-order does not work for me (python)
Hello guys!
I am trying to get oco-orders (binance) to work for several hours now, but without any success. I also looked up closed issues with similar problems like this https://github.com/ccxt/ccxt/issues/5966 but it didn’t help me neither.
- OS: Windows 10x64 running PyCharm 2020.3.2
- Programming Language version: python 3.8
- CCXT version: 1.40.30
Here is my code
def placeOco():
exchange = ccxt.binance({
'apiKey': "xxx",
'secret': "xxx",
'enableRateLimit': True,
# 'options': {'adjustForTimeDifference': True}
})
precision = 8
thePrice = 0.00002000
thePrice_str = '{:0.0{}f}'.format(thePrice, precision)
stopPrice = 0.00001600
stopPrice_str = '{:0.0{}f}'.format(stopPrice, precision)
stopLimitPrice = 0.00001500
stopLimitPrice_str = '{:0.0{}f}'.format(stopLimitPrice, precision)
symbol = 'SCRT/BTC'
type = 'limit' # or 'market'
side = 'sell' # or 'buy'
amount = 26
price = thePrice_str # or None
# extra params and overrides if needed
params = {
'test': True, # test if it's valid, but don't actually place it
'stopPrice': stopPrice_str,
'stopLimitPrice': stopLimitPrice_str,
'stopLimitTimeInForce': "GTC",
}
order = exchange.create_order(symbol, type, side, amount, price, params)
print(order)
placeOco()
This is my error message
Traceback (most recent call last):
File "C:/Users/xxx/PycharmProjects/xxx/xxx.py", line 72, in <module>
placeOco()
File "C:/Users/xxx/PycharmProjects/xxx/xxx.py", line 69, in placeOco
order = exchange.create_order(symbol, type, side, amount, price, params)
File "C:\Users\xxx\PycharmProjects\xxx\venv\lib\site-packages\ccxt\binance.py", line 1665, in create_order
response = getattr(self, method)(self.extend(request, params))
File "C:\Users\xxx\PycharmProjects\xxx\venv\lib\site-packages\ccxt\base\exchange.py", line 465, in inner
return entry(_self, **inner_kwargs)
File "C:\Users\xxx\PycharmProjects\xxx\venv\lib\site-packages\ccxt\binance.py", line 2473, in request
response = self.fetch2(path, api, method, params, headers, body)
File "C:\Users\xxx\PycharmProjects\xxx\venv\lib\site-packages\ccxt\base\exchange.py", line 486, in fetch2
return self.fetch(request['url'], request['method'], request['headers'], request['body'])
File "C:\Users\xxx\PycharmProjects\xxx\venv\lib\site-packages\ccxt\base\exchange.py", line 604, in fetch
self.handle_errors(http_status_code, http_status_text, url, method, headers, http_response, json_response, request_headers, request_body)
File "C:\Users\xxx\PycharmProjects\xxx\venv\lib\site-packages\ccxt\binance.py", line 2467, in handle_errors
self.throw_exactly_matched_exception(self.exceptions, error, feedback)
File "C:\Users\xxx\PycharmProjects\xxx\venv\lib\site-packages\ccxt\base\exchange.py", line 504, in throw_exactly_matched_exception
raise exact[string](message)
ccxt.base.errors.BadRequest: binance {"code":-1104,"msg":"Not all sent parameters were read; read '11' parameter(s) but was sent '13'."}
Thanks in advance for your time and help!
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 21 (8 by maintainers)
@don-mao the last price of ETHBUSD is floating all the time, and your
pricehas to be >last price, while yourstopPricehas to be <last price, which makes your range very-very narrow which in its turn yields your error. You just have to use a wider range so thatprice>last price>stopPrice.ty @kroitor now it’s working fine! have a nice day!
CCXT currently does not support Binance’s OCO orders with the
create_ordercall, however you can place your OCO order with CCXT using the implicit API methods:Let us know if this example does not answer your question: