Numeric Values: Strings to Avoid Float Precision Loss
All prices, quantities, and monetary amounts are raw integer strings — a whole number with no decimal point, carried as a JSON string rather than a JSON number. This avoids the precision loss that occurs when JSON parsers store large numbers as IEEE 754 doubles.p and s in an order are raw integer strings, not display values. The server rejects a value with a real fractional part ("85000.5" → 400). A lossless suffix such as "85000.0" is accepted, but it still denotes the raw integer 85000 — requests do not accept decimal values.
Raw Integers and Scale Factors
Numeric values in API responses are raw integers. To obtain the human-readable display value, divide by 10 raised to the scale exponent for that field. Use theconfigs endpoint to retrieve priceScale and qtyScale for each contract.
Display to Raw — the order path
The wire protocol is integer-only. Convert before signing; the signature covers the raw values.1
Read the contract's own parameters
Fetch
priceScale, qtyScale, tickSize, and stepSize from configs for the exact contract. Never reuse another contract’s values, and never use a value from documentation.2
Scale to raw integers
price_raw = display_price × 10 ** priceScale and size_raw = display_size × 10 ** qtyScale, computed with Decimal. If either result is not a whole number, the input carries more precision than the contract accepts.3
Validate, do not round
price_raw must be a positive multiple of tickSize; size_raw a positive multiple of stepSize. Reject the request if it is not. Silently rounding changes the order the caller asked for.4
Send as strings
Place the raw integers into
p and s as decimal strings, then sign.Which scale applies
Scales come in three kinds and must not be mixed. All of them are read fromconfigs.
Which coin’s
szDecimals applies depends on where the amount appears:
Look the coin up as shown above rather than hardcoding a number of decimal places — different coins have different
szDecimals.
Fixed-denominator fields
The following fields do not use any scale fromconfigs. Each has a fixed denominator:
A fee field that is not set is returned as JSON
null. 0 (a 0% fee) and negative values (rebates, negative funding) are real values and are returned as such — do not treat 0 as “not set”.
Large integers and IDs
Raw values are int64 and can exceed JavaScript’sNumber.MAX_SAFE_INTEGER (2^53 − 1); beyond that, a default JSON.parse loses precision silently. Parse amounts with a string-preserving decoder or BigInt. ID fields such as positions[].id, accountId, blockHeight, nonce, and cloid are identifiers that are never scaled, but must also be handled as strings or big integers, never as floating-point numbers.
Each contract’s
priceScale and qtyScale are published by the configs endpoint. The values above are illustrative only. Scales differ per contract, are frequently 0, and change as contracts are listed or reconfigured — always read them from configs for the exact contract you are trading, and never carry a value over from another contract or from an example.Naming quirks to watch
These are wire-format facts, not typos. They cost a round trip each to discover, so they are collected here.Timestamps
All timestamps are int64 Unix milliseconds — the number of milliseconds elapsed since 1970-01-01T00:00:00Z. Timestamps are represented as JSON integers (not strings).Ethereum Addresses
Addresses follow the standard Ethereum format:0x prefix followed by 40 lowercase hexadecimal characters (42 characters total).
Contract (Asset) IDs
Each perpetual contract has an integer ID stored in thea field of order, cancel, and modify actions. Call configs to enumerate the contracts and their IDs — the listed set changes, IDs are assigned by the server, and contractId 1/2/3 do not map to any fixed pair. Match on name and never hardcode an ID.
Client Order IDs (cloid)
A client order ID is an int64 decimal string that you assign when placing an order. It must be a unique positive integer. You can use it later to cancel or query orders without needing the server-assignedoid.
The format is validated strictly wherever a client order ID is accepted — c in order and cancel, cloid in cancelByCloid, and cloid / c in modify:
- Decimal digits (
0–9) only, at most 20 bytes, and within the int64 range. - Hexadecimal, UUIDs, prefixed values (
0x…), and signed values are rejected with400 INVALID_PARAM,errors[].reasonINVALID_FORMAT(OUT_OF_RANGEwhen the value exceeds int64). - Omitting the field or sending an empty string
""means no client order ID is set. - In
cancel,cis used to locate the order only wheno(order ID) is absent, and is validated only in that case. When both are sent,otakes precedence.
Short Key Convention (Order Payloads)
Order-related actions use single-letter compact keys to reduce payload size. The mapping is:
Example order object using short keys:
Full Key Convention (Margin and Mode Actions)
Margin and account mode actions use full field names rather than single-letter abbreviations:
Example leverage update using full keys:
