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.

bybit: sign error for conditional market orders when stop/base price is a round number

See original GitHub issue
  • OS: Ubuntu 20.04
  • Programming Language version: Python 3.9
  • CCXT version: 1.40.94

Hey Igor,

This seems pretty crazy to have gone by without being reported so I’m hoping this is either an incoming API change or an unexpected dependency upgrade that’s suddenly causing. But in either case, this is what I’m seeing:

import ccxt

bybit = ccxt.bybit()
bybit.apiKey = "cox"
bybit.secret = "dix"
bybit.urls["api"] = bybit.urls["test"]

bybit.create_order("BTC/USD", "Market", "buy", 16,
                   params={
                       'order_link_id': "peen",
                       'stop_px': 31320.0,
                       'base_price': 31319.0,
                       'trigger_by': 'LastPrice'
                   })

Error:

ExchangeError: bybit {"ret_code":10004,"ret_msg":"error sign! origin_string[api_key=<redacted>\u0026base_price=31319.0\u0026order_link_id=peen\u0026order_type=Market\u0026qty=16\u0026recv_window=5000\u0026side=Buy\u0026stop_px=31320.0\u0026symbol=BTCUSD\u0026time_in_force=GoodTillCancel\u0026timestamp=1611516960917\u0026trigger_by=LastPrice]","ext_code":"","ext_info":"","result":null,"time_now":"1611516961.337532"}

What’s bizarre is that this is only happening if the stopPx/base_price is a round number (no decimal). So in the example above, it should succeed if the prices are 31320.5 and 31319.5. I dug into the py source code, and tried casting the params to ints beforehand, and that seems to fix it:

Adding this after L1293 in bybit.py (sorry don’t have time to find it in the JS source):

                if request["stop_px"] == round(request["stop_px"]):
                    request["stop_px"] = int(request["stop_px"])
                if request["base_price"] == round(request["base_price"]):
                    request["base_price"] = int(request["base_price"])

Is this an edge case in the signing algo? Or one of my params throwing the system off? New weirdness on testnet? It was certainly not happening before (I upgrade ccxt recently). Happy to file a PR if you (or anyone else) can confirm there is a bug here.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
kroitorcommented, Jan 24, 2021

@daikts Bybit’s API wasn’t too good at first, which is why we had to add a workaround, but now they have fixed it, apparently, and the workaround is not necessary anymore, so they’re making progress towards a better API. I’ll push the fix in a few minutes. Thx for your feedback!

1reaction
daiktscommented, Jan 24, 2021

That seemed to work! Just tested both on testnet and realnet. Massive ups for that response / resolution time @kroitor! Is Bybit API particularly shitty like this is or is this the average experience?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why Was My Conditional Order Triggered but Not Executed?
1) Due to insufficient margin (The system will show as rejected). Conditional orders do not have any margin requirements when traders place ...
Read more >
Group And Resources – Bybit API Docs - GitHub Pages
Order price : If it is a stop order, this parameter is required. When there is no position, the price should be higher...
Read more >
BYBIT - HOW TO PLACE CONDITIONAL ORDERS - YouTube
In this Bybit tutorial I show you how to place conditional orders. Conditional orders can be useful for break out trade ideas and...
Read more >
ByBit Exchange Spot Conditional Order - Stack Overflow
But I got this error: InvalidRequestError: Param validation for 'reduce_only' failed on the 'exists' tag (ErrCode: 10001) ...
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