Skip to content

fix: infer Bybit, Bitget and Binance precision from Decimal exponent - #243

Merged
brokermr810 merged 1 commit into
OpenByteInc:mainfrom
Dev-next-gen:fix/step-precision-scientific-notation
Sep 13, 2026
Merged

fix: infer Bybit, Bitget and Binance precision from Decimal exponent#243
brokermr810 merged 1 commit into
OpenByteInc:mainfrom
Dev-next-gen:fix/step-precision-scientific-notation

Conversation

@Dev-next-gen

Copy link
Copy Markdown
Contributor

Summary

The OKX client was fixed to infer lot precision from the Decimal exponent, because Decimal.normalize() turns small steps into scientific notation (Decimal("0.0000001").normalize() is 1E-7, with no . in it). I found the same string parsing still in place in the Bybit and Bitget clients and in BinanceSpotClient._decimal_places_from_step, which the Binance futures client also uses. For any step or tick at 1E-7 or smaller, precision comes out as 0.

That value then goes to _dec_str(..., strict_precision=0), which rounds down to an integer. Take Bybit linear with a tickSize of 0.0000001: a limit price of 0.01234567 is sent as "0". Quantities with an 0.00000001 step are cut the same way, and on Binance futures min(quantityPrecision, 0) keeps the 0.

Changes

  • bybit.py: _normalize_qty and _normalize_price get the precision from step.normalize().as_tuple().exponent, the same way okx.py already does
  • bitget.py: same change in _normalize_size and _normalize_price, for the fallback used when sizePlace / pricePlace are missing
  • binance_spot.py: _decimal_places_from_step uses the exponent too
  • New tests/test_step_precision_scientific_notation.py with one case for each call site

Steps of 1E-6 or more and integer steps like 10 (1E+1, precision 0) give the same result as before, so nothing changes for the instruments that already worked.

Test plan

  • Tested locally with docker compose up -d --build
  • Backend logs show no errors
  • Relevant pytest tests pass

Without the fix, all 5 new tests fail on the value itself (assert 0 == 7, assert 0 == 8). With it they pass, and the full tests/ suite gives 2343 passed and 20 skipped (Python 3.12). ruff check app scripts tests, scripts/backend_quality_check.py and scripts/check_mojibake.py also pass. I didn't run the Docker stack because the change doesn't touch any route or config.

API documentation (if routes/schemas changed)

No routes or schemas changed.

AI tools used

Decimal.normalize() renders steps below 1E-6 in scientific notation, so
parsing the string for a '.' read the precision of a 0.0000001 tick or a
0.00000001 lot step as 0 and truncated prices and quantities to integers.
Apply the exponent-based inference already used for OKX lotSz.
@brokermr810
brokermr810 merged commit 48c9417 into OpenByteInc:main Sep 13, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants