Contract basics

Numeric conventions

Five fixed-point conventions run across three API lines — half of them JSON integers, half strings. Code written against the wrong line does not fail — it simply computes the wrong number. This page gives the mapping first, then the places where it fails silently.

Which convention each line uses

LinePrefixAuthPrice / sizeOutcome
Trading API/api/v1Bearer sessionprice E4 · size E2 · amount E6 (integers)YES | NO
PX Discovery & Account/api/v1/pxPublic reads / Bearer sessionE6 decimal strings throughoutA | B
Market Maker API/v1/pxpxk_ API keyE6 decimal strings throughoutA | B

The three prefixes differ by one segment, the precision differs by 100×, and even the enum spelling differs. Every endpoint page carries this marker in its endpoint bar so you can always tell which line you are on.

The five conventions

UnitMeaningExampleJSON type
E41e-4 USD. Prices on the Trading API5200 = 0.5200 USDinteger
E21e-2 shares. Sizes on the Trading API1000 = 10.00 sharesinteger
E61e-6 USD or 1e-6 shares. Amounts on the Trading API, and every price, size and amount on both PX lines520000 = 0.520000integer on the Trading API, string on both PX lines
ppmParts per million. Fee rates2000 ppm = 0.2%integer
bpsBasis points. Health, interest rates, margin rates, return on equity1500 bps = 15%string

Where it fails silently

  1. Reading an E4 price as E6 is off by 100× and never errors。 `priceE4: 5200` is 0.52 USD; read as E6 it becomes 0.0052. Both are valid integers and no layer will catch it. The only signal is the field-name suffix and which line you are on.
  2. On both PX lines the values are strings, not numbers。 E6 values exceed 2^53, so serialising them as JSON numbers loses precision; both PX lines emit decimal strings instead. After `JSON.parse`, using them directly in arithmetic concatenates strings rather than adding numbers.
  3. Prices must be an integer multiple of the market tick。 `tickE4` comes from the market detail. A price that is not a multiple is rejected with a 400 on a single place; in a batch only **that entry** fails while the rest are still accepted.
  4. Health can be null, and null is not zero。 With no debt `healthBps` is null, because health is undefined without debt. Treating that null as 0 turns the healthiest account into the most distressed one.
  5. Do the arithmetic in integers or a fixed-point library, never floats。 The whole pipeline is integer arithmetic and floating point is display-only. `0.1 + 0.2 !== 0.3` becomes a cent that reconciliation can never close.

Related

Fee rates in ppm and the tiered limits are on Limits & fees; runtime behaviour of matching and settlement is on Runtime behaviour.