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
| Line | Prefix | Auth | Price / size | Outcome |
|---|---|---|---|---|
| Trading API | /api/v1 | Bearer session | price E4 · size E2 · amount E6 (integers) | YES | NO |
| PX Discovery & Account | /api/v1/px | Public reads / Bearer session | E6 decimal strings throughout | A | B |
| Market Maker API | /v1/px | pxk_ API key | E6 decimal strings throughout | A | 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
| Unit | Meaning | Example | JSON type |
|---|---|---|---|
E4 | 1e-4 USD. Prices on the Trading API | 5200 = 0.5200 USD | integer |
E2 | 1e-2 shares. Sizes on the Trading API | 1000 = 10.00 shares | integer |
E6 | 1e-6 USD or 1e-6 shares. Amounts on the Trading API, and every price, size and amount on both PX lines | 520000 = 0.520000 | integer on the Trading API, string on both PX lines |
ppm | Parts per million. Fee rates | 2000 ppm = 0.2% | integer |
bps | Basis points. Health, interest rates, margin rates, return on equity | 1500 bps = 15% | string |
Where it fails silently
- 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.
- 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.
- 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.
- 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.
- 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.
