Skip to content
All library documents

Floating-Point Rounding Errors in Binance Order Quantities

Article FMZ forum · Author: leemon

Summary

The document describes an order-management issue in a Binance perpetual futures example. A partially filled sell order has an original quantity and an executed quantity; subtracting the latter from the former in JavaScript produces a residual quantity with a long decimal tail. Submitting that quantity for another order triggers the exchange's maximum-precision rejection.

The example illustrates how binary floating-point arithmetic can represent decimal quantities imprecisely, which can make an apparently valid residual exceed an exchange's allowed precision. It does not provide a fix, discuss exchange filters or step sizes, or show a broader set of cases. Traders and developers can take from it the need to handle order quantities using the instrument's permitted precision when calculating unfilled amounts; the document itself offers only the reported failure, not an implementation method or trading strategy.

Key ideas

  • Subtracting executed quantity from original quantity in JavaScript can produce a floating-point residual with excess decimal places.
  • The exchange rejects a follow-up order when its quantity exceeds the asset's precision limit.
  • Order quantity calculations must account for the instrument's permitted precision.
  • The document reports one failure scenario and does not provide a correction or broader testing.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.