Formatting Prices and Sizes for Orders
When placing orders on Decibel, you need to convert decimal prices and sizes to chain units that match the market’s precision requirements. This guide explains how to use market configuration data from thev1/markets endpoint to properly format your order parameters.
Market Configuration
Each market returned from thev1/markets endpoint includes precision configuration:
Market Configuration Fields
-
px_decimals- The number of decimal places used for price precision. Prices are stored as integers with this many implied decimal places. For example, ifpx_decimals = 9, a price of5.67is stored as5670000000(5.67 × 10^9). -
sz_decimals- The number of decimal places used for size precision. Order sizes are stored as integers with this many implied decimal places. For example, ifsz_decimals = 9, a size of1.5is stored as1500000000(1.5 × 10^9). -
tick_size- The minimum price increment in chain units. Prices must be multiples of this value. For example, iftick_size = 1000000andpx_decimals = 9, the minimum price increment is0.001(1000000 / 10^9). -
lot_size- The minimum size increment in chain units. Order sizes must be multiples of this value. For example, iflot_size = 100000000andsz_decimals = 9, the minimum size increment is0.1(100000000 / 10^9). -
min_size- The minimum order size in chain units. Orders smaller than this will be rejected. For example, ifmin_size = 1000000000andsz_decimals = 9, the minimum order size is1.0(1000000000 / 10^9).
Conversion Functions
Convert Decimal Amount to Chain Units
Convert Chain Units to Decimal Amount
Price Formatting
Round Price to Valid Tick Size
Prices must be rounded to the nearest valid tick size. Use this function to ensure your price is valid:Size Formatting
Round Size to Valid Lot Size
Order sizes must be rounded to the nearest valid lot size and meet the minimum size requirement:Complete Example
Here’s a complete example of formatting prices and sizes for placing an order:Understanding the Values
Example Market Configuration
Let’s say a market has the following configuration:-
Price Precision: Prices can have up to 9 decimal places. A price of
5.67is stored as5670000000chain units. -
Size Precision: Sizes can have up to 9 decimal places. A size of
1.5is stored as1500000000chain units. -
Tick Size: The minimum price increment is
0.001(1000000 / 10^9). Valid prices are:5.000,5.001,5.002, etc. Invalid:5.0005. -
Lot Size: The minimum size increment is
0.1(100000000 / 10^9). Valid sizes are:1.0,1.1,1.2, etc. Invalid:1.05. -
Min Size: The minimum order size is
1.0(1000000000 / 10^9). Orders smaller than 1.0 will be rejected.
Market-Specific Values
For the actualmin_size, lot_size, and tick_size values for each live market, see Market Parameters.
Common Pitfalls
-
Not rounding prices: Prices must be multiples of
tick_size. Always useroundToValidPrice()before converting to chain units. -
Not rounding sizes: Sizes must be multiples of
lot_size. Always useroundToValidOrderSize()before converting to chain units. -
Forgetting minimum size: Orders below
min_sizewill be rejected. The rounding function handles this automatically. -
Using wrong decimals: Always use
px_decimalsfor prices andsz_decimalsfor sizes when callingamountToChainUnits().

