API Reference
HTTP and WebSocket API for Loaf. Base URL: https://api.loafmarkets.com.
Headlines are a separate public service. REST seed is https://news.loafmarkets.com/v1/headlines. See News.
- Trade
- Info
- Offerings
- Orders
- Stop & Take Orders
- Portfolio
- History
- L2
- Explorer
- Competition
- Leaderboard
- WebSocket
- News
Authentication
A client holds one secret, the account’s trading key: api key 0, shown on the app’s API page as loaf_tk_<l2ChainId>_<l2AccountIndex>_<secret>. The key is never sent.
Three credentials reach the API:
| Credential | Where it goes | What it proves |
|---|---|---|
| Nothing | Public reads: trade, info, offerings list, leaderboard, competition overview, explorer, intake | None |
| Order signature | POST /api/orders and POST /api/orders/conditional | The body is signed by api key 0. Any Authorization header on these two routes is ignored. |
Login token loaf_lt_… | Cancels, history, the portfolio summary and component, saved leverage, GET /api/l2/keys, order-index reservation, withdrawals, perps allocate / exit / set mode | A short-lived signature by the same key. Send Authorization: Bearer <token>. These routes also take a Privy JWT. |
| Privy JWT | The web app’s login. Deposits, key registration, relay status, offerings subscribe, wallet send, GET /api/wallet/ipo-holds, competition queue and payouts, share cards, the performance series, on-ramp and off-ramp, GET /api/auth/profile | A browser session. A login token on these routes is 401. |
A Privy JWT is the web app’s Privy access token. It goes in the same Authorization: Bearer header.
A login token is:
loaf_lt_<l2ChainId>_<l2AccountIndex>_<l2ExpiryMs>_<l2SigS><l2SigE>l2ChainId and l2AccountIndex are the same as in the trading key. l2ChainId is also market.l2.l2ChainId on Trade. l2ExpiryMs is unix milliseconds. l2SigS and l2SigE are 80 lowercase hex characters each, the Schnorr signature of api key 0 over the login message. To sign, see Signing. Sign a token for about 10 minutes. Loaf refuses one that is already expired, or one that expires more than 15 minutes ahead.
The WebSocket takes the same Bearer value in an auth frame, never in the URL. See WebSocket.
A refused login token or Privy JWT is 401 with { "error": "<text>", "code": "UNAUTHENTICATED" }. A login token that cannot be checked right now returns 503 with code SERVICE_UNAVAILABLE. Nothing was done. Try again in a moment.
Tickers
REST paths and market-data channels use a ticker. The market index belongs in the signed body.
| Kind | Format | Example |
|---|---|---|
| Asset | ^[A-Z0-9]{1,10}$ | TERA |
| Spot market | the asset ticker | TERA |
| Perp market | asset ticker plus -PERP | TERA-PERP |
Trade paths take a market ticker (TERA or TERA-PERP). Info and Offerings paths take the asset ticker. Offering and info bodies include tokenName, the asset’s display name. Do not put it in a path.
Money and units
Order price, quantity, and triggerPrice are decimal numbers in the market’s own units. Read priceDecimals and quantityDecimals on the market. A price has at most priceDecimals places, a quantity at most quantityDecimals. Quantity decimals are 1 to 6. Price decimals are 0 to 5. The two sum to at most 6. Every market’s minimum order value is 10 USD (minOrderValue), waived for a full close.
l2.signedPriceDecimals and l2.signedQuantityDecimals are the scales inside the signature. The client still sends human prices and quantities. The signature covers the scaled values.
Balances, deposit amounts, and transfer amounts are decimal strings in the token’s base units. A balance row carries decimals. USDC "1000000" with decimals: 6 is 1 USDC. Divide by 10^decimals to display the amount.
A signed withdrawal or allocate amount is in the asset’s L2 ticks: base units divided by the asset’s tickSize. For USDC, read perps.collateral.tickSize on GET /api/portfolio/summary. For another asset, read tickSize from the ZkLoaf proxy’s assetConfig(assetId) at market.l2.proxyAddress. Perps pool amounts on the summary are USD decimal strings.
Fields ending in Bps are basis points (30 = 0.30%). fundingRateCbp is the rate for one funding period (fundingPeriodMs), in centi-basis-points of the oracle price. It is the payment rate on Funding, as rateCbp is in history.
Rate limits
Requests are limited per IP, and per account on authenticated routes. Relay routes (deposits, key registration, offerings subscribe, wallet send) have a tighter per-account limit on top of the account limit. POST /api/orders/cancel-after and the share-card routes have their own per-account limits. GET /api/l2/intake has its own per-IP limit. Resending an order that was already placed has one too.
Each of these limits answers 429 with Retry-After. Routes that are not cached also send RateLimit-Limit, RateLimit-Remaining, and RateLimit-Reset, a 429 included. A cached route sends none of the three, whatever its status. The general per-IP limit returns { "error": "Too many requests. Please slow down." }. Per-account limits, the intake limit, and the resend limit return { "error": "<text>", "code": "RATE_LIMITED" }.
A call refused for too much traffic can also come back as 429, 403, or 202 with no JSON body and no Retry-After. Nothing was done, and a 202 like this is not a success. Slow down and retry with backoff.
Retry idempotent reads after the Retry-After seconds. Retry POST /api/orders only as the same signed body. A placed order is keyed by (l2AccountIndex, l2OrderIndex). That resend returns the original order with duplicate: true. A different body on a spent index is ORDER_INDEX_USED.
503 with code TRADING_PAUSED means trading is temporarily paused. Nothing was placed or changed. Send the same body again after the Retry-After seconds. 503 with NOT_PROCESSED means the trading service did not take the request. Nothing was reserved or placed. Send it again. A halt is 403 with MARKET_HALTED or TRADING_HALTED.
Caching
Some public GET routes are cached briefly at the edge and send Cache-Control: public, max-age=0, s-maxage=N. Share-card routes send Cache-Control: private, no-store. GET /api/trade/:ticker/trades, the explorer routes that take a cursor, and GET /api/l2/intake are not cached.
Ask once, then listen
Subscribe, then call REST for the current state. Apply frames on top of it.
| Need | REST seed | WebSocket |
|---|---|---|
| Book | GET /api/trade/:ticker orderBook | orderbook:{ticker} replaces it when the book changes, and resends it periodically. The seed and each frame hold the best levels on each side. A very deep book is cut off |
| Trades | GET /api/trade/:ticker/trades | trades:{ticker} sends the trades since the last frame. A new subscriber first gets the most recent trades |
| Mark | marketPrice on the trade list, or live.markPrice on a perp | markprice:{ticker} |
| Candles | GET /api/trade/:ticker/candles | chart:{ticker} |
| Your account | GET /api/portfolio/summary and /component | portfolio after auth |
| Perps live state | live on GET /api/trade/:ticker for one market | perps:markets for every perp |
See WebSocket.