question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

binance - oco-order does not work for me (python)

See original GitHub issue

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!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:17 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
kroitorcommented, Apr 5, 2021

@don-mao the last price of ETHBUSD is floating all the time, and your price has to be > last price, while your stopPrice has 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 that price > last price > stopPrice.

1reaction
Defqon51commented, Jan 11, 2021

ty @kroitor now it’s working fine! have a nice day!

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - How to send OCO order to binance
The problem of the OCO order is that there is limit order instead of market order, I stopped using it because it just...
Read more >
What is an OCO (One-Cancels-the-Other) Order and How ...
An OCO order on Binance consists of a stop-limit order and a limit order with the same order quantity. Both orders must be...
Read more >
Binance Futures OCO order (or SL/TP)
Unfortunately, so far futures trade does not provide OCO oder. However, both stop loss and take profit orders are available.
Read more >
python-binance Documentation
Binance API Telegram https://t.me/binance_api_english ... Creates and validates a new order but does not send it into the exchange.
Read more >
Binance Python API – A Step-by-Step Guide
Next we will create a dictionary that will hold our latest price data and also let us known if there is a problem...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found