The rule
Every monetary value — in both requests and responses — is a full-precision plain decimal string in USD. That means:- A string, e.g.
"12.50"— never a bare JSON number - In human USD, e.g.
"5"means five dollars — never raw base units like"5000000" - Plain decimal — never scientific notation like
"5e-7" - Full precision — never pre-rounded; round only when you display to users
Why strings instead of numbers
JSON numbers are IEEE-754 double-precision floats. The classic0.1 + 0.2 = 0.30000000000000004 problem is real, and integers silently lose precision beyond 2^53. For money, that is unacceptable. A decimal string carries the exact value with zero rounding, and you parse it with a decimal library on your side. $5 serializes as "5" — not 5000000 (its raw base units) and not 5.0 (a float).
Token quantities that are genuinely in base units are the one exception, and they are always
named with a
Raw suffix — for example currentTokenAmountRaw or inputAmountRaw. Every field
named ...Usd, or that represents a price, PnL, or percentage, is a human decimal string.Correct vs. incorrect formats
When you send money in a request body, always use a decimal string. Never multiply by1e6 and never send a plain number.
400 INVALID_AMOUNT rather than silently mis-scaling your trade.
Parsing money safely
Use a decimal type — not a float — whenever you do arithmetic on money values.Raw vs. human quantities
Two distinct kinds of numeric values appear in the API. The field name suffix tells you exactly which you are dealing with.| Field style | Meaning | Example value | How to use |
|---|---|---|---|
...Usd, prices, PnL, percent | Human decimal string in USD | "12.50", "-3.7" | Parse with a decimal library. |
...Raw, ...BaseUnits, ...BaseLots | Integer base-unit quantity string | "25000000" | Humanize using the token’s decimals. |
tokenDecimals, decimals, counts, indices | Structural integer | 6, 9 | Plain JSON number — use as-is. |
10 ** decimals using a decimal type:
Percentages
Percentage fields —pnlPct, exitPnlPct, winRate, priceChange24hPct, and others — follow the same decimal string rule. The value is expressed as a percent directly: "4.27" means 4.27% and "-12.5" means −12.5%. Do not divide by 100 before displaying.
Worked example
A$5 spot buy returns a response like the one below. Note that totalCostUsd is the human string "5", not 5000000.
totalCostUsd: "5"→ five dollars.tokenAmount: "1380.5"→ already humanized for trade rows (usestokenDecimals).pricePerTokenUsd: "0.00362"→ a small price, still plain decimal — never"3.62e-3".