| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Decimal.normalize() renders lotSz values like 0.00000001 in scientific notation (1E-8). The string-based precision parser found no '.' in '1E-8' and fell back to precision 0, so any spot order below one whole unit was quantized to sz="0" and rejected by OKX with error 51000 (Parameter sz error). Derive precision from the Decimal exponent instead, and add regression tests.
| Back | FazBrowse Home | New Git URL |
Problem
Placing a spot market order through the OKX adapter fails with:
OKX error: {'code': '1', 'data': [{'sCode': '51000', 'sMsg': 'Parameter sz error', ...}], 'msg': 'All operations failed'}This affects any spot order below one whole base unit — e.g. a 50 USDT quick-trade buy of BTC/USDT (~0.0008 BTC).
Root cause
OkxClient._normalize_order_size() infers the size precision from lotSz by string-parsing the normalized Decimal:
Decimal.normalize() renders small steps in scientific notation, so BTC-USDT spot (lotSz=0.00000001) yields precision 0. _dec_str(sz, strict_precision=0) then quantizes 0.00081471 down to sz="0", which OKX rejects with 51000.
Fix
Derive the precision from the Decimal exponent instead of parsing the string representation:
Handles 0.00000001 → 8, 0.000001 → 6, 1 → 0 (whole swap contracts), 10 → 0.
Testing