Skip to main content

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 the v1/markets endpoint to properly format your order parameters.

Market Configuration

Each market returned from the v1/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. Perp markets always use px_decimals = 6 (prices are in the collateral asset’s decimals): a price of 5.67 is stored as 5670000 (5.67 × 10^6). Spot markets use the quote asset’s decimals.
  • sz_decimals - The number of decimal places used for size precision. Order sizes are stored as integers with this many implied decimal places. This is per market (2–8 on mainnet perps). For APT/USD, sz_decimals = 5, so a size of 1.5 is stored as 150000 (1.5 × 10^5).
  • tick_size - The minimum price increment in chain units. Prices must be multiples of this value. For APT/USD, tick_size = 100 with px_decimals = 6, so the minimum price increment is $0.0001 (100 / 10^6).
  • lot_size - The minimum size increment in chain units. Order sizes must be multiples of this value. For APT/USD, lot_size = 10000 with sz_decimals = 5, so the minimum size increment is 0.1 APT (10000 / 10^5).
  • min_size - The minimum order size in chain units. Orders smaller than this will be rejected. For APT/USD, min_size = 100000 with sz_decimals = 5, so the minimum order size is 1 APT (100000 / 10^5).
  • min_price / max_price - The price band the market currently accepts, in chain units. Orders priced outside it abort with EPRICE_TOO_SMALL / EPRICE_TOO_LARGE.
  • mode - The market state. Only Open accepts every order; ReduceOnly, AllowlistOnly, Halt and Delisting restrict or refuse placement.

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:
What this means:
  • Price Precision: Prices have 6 decimal places. A price of 5.67 is stored as 5670000 chain units.
  • Size Precision: Sizes have 5 decimal places on this market. A size of 1.5 is stored as 150000 chain units.
  • Tick Size: The minimum price increment is $0.0001 (100 / 10^6). Valid prices are: 5.0000, 5.0001, 5.0002, etc. Invalid: 5.00005.
  • Lot Size: The minimum size increment is 0.1 APT (10000 / 10^5). Valid sizes are: 1.0, 1.1, 1.2, etc. Invalid: 1.05.
  • Min Size: The minimum order size is 1 APT (100000 / 10^5). Orders smaller than 1 APT will be rejected.

Market-Specific Values

For the actual min_size, lot_size, and tick_size values for each live market, see Market Parameters.

Common Pitfalls

  1. Not rounding prices: Prices must be multiples of tick_size. Always use roundToValidPrice() before converting to chain units.
  2. Not rounding sizes: Sizes must be multiples of lot_size. Always use roundToValidOrderSize() before converting to chain units.
  3. Forgetting minimum size: Orders below min_size will be rejected. The rounding function handles this automatically.
  4. Using wrong decimals: Always use px_decimals for prices and sz_decimals for sizes when calling amountToChainUnits().