Skip to main content

Numeric Types in Spot Responses

Spot endpoints return price, quantity, average_price, orig_qty, executed_qty, and similar fields as JSON numbers (not strings):

{
"data": {
"price": 26000,
"quantity": 0.0009,
"average_price": 0,
"orig_qty": 0.0009,
"executed_qty": 0
}
}

Why this matters

Most languages parse JSON numbers as IEEE 754 double-precision floats by default. That's fine for display and arithmetic up to about 15 significant decimal digits, but don't use floats for financial calculations if you care about exact paise/satoshi precision. Common pitfalls:

  • 0.1 + 0.2 != 0.3 in IEEE 754
  • Quantities like 0.00005 may serialize as 5e-05 (still a valid JSON number, but parsers may surprise you)

Recommendations

LanguageParse strategy
PythonUse decimal.Decimal for arithmetic, parse with json.loads(s, parse_float=Decimal).
JavaConfigure Jackson to use BigDecimal: mapper.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS).
JavaScript / NodeUse a string-preserving parser (e.g. lossless-json) or convert to BigNumber/Decimal libraries.
GoDecode into decimal.Decimal (e.g. shopspring/decimal).

Comparison with Futures

Futures responses use JSON strings for numerics ("price": "26000") — fixed-precision and lossless. Spot responses use JSON numbers.

If you write a single client that handles both surfaces, normalise everything to your preferred decimal type at parse time so downstream code doesn't have to think about the difference.