TradrBot backend API
Everything the app reads and sends: live prices, trading through the relayer, and the indexed history of the protocol on Robinhood Chain (chain id 4663). Collateral is USDG; the reward token is TRADR.
Three services, all public and CORS-open. Reads need no key. Trades and wallet actions are signed in the browser and sent to the relayer, which pays the gas.
Start here
Pick the service by what you need. Every service answers JSON and errors carry a stable code plus a human message in English.
| Service | Production URL | What it does | Local (fork) |
|---|---|---|---|
| Indexer API | https://hmindexer-production.up.railway.app | Accounts, positions, history, markets, stats, charts, leaderboard, profiles, token | http://localhost:8096 |
| Relayer | https://hmrelayer-production.up.railway.app | Config for signing, open/close intents, wallet actions (deposit, withdraw, session keys, staking) | http://localhost:8091 |
| Prices | https://hmprices-production.up.railway.app | Live Pyth prices (websocket), candles and ticks, SPY and TSLA previews | http://localhost:8090 |
configure.ts) and the relayer wallet has ETH and its role; until then /api/markets shows listed: false, the relayer's /live answers 503 and every list is empty. Empty lists are real data, not errors.Conventions
The same rules hold across the three services, so the front never guesses units.
| Thing | Format | Example |
|---|---|---|
| USDG amounts (indexer) | Decimal string, 6 decimals already applied | "1234.56" |
| TRADR amounts | Decimal string, 18 decimals applied | "20.4581" |
| Prices (indexer) | Decimal string in USD | "79783.68" |
| Prices (prices service, relayer) | Integer string with expo (Pyth), or WAD (18 decimals) in relayer results; usd is a number for display only | {"price":"7964500832418","expo":-8} |
| Amounts you send to the relayer | Raw integer strings: USDG × 10⁶, TRADR × 10¹⁸ | "10000000" = 10 USDG |
| Percentages | Number with 2 decimals; bps fields are basis points (1 bps = 0.01 %) | 161.33, winFeeBps: 200 |
| Times | Unix seconds (chain time). Price ticks use milliseconds where noted | 1793072560 |
| Addresses | Lowercase in responses; any case accepted in requests | 0x3c44…93bc |
| Markets | instrumentId 0 = BTC/USD, 1 = ETH/USD (tradable). 100 = SPY/USD, 101 = TSLA/USD (previews, prices only) | market=0 |
| Errors (indexer, prices) | { code, message } with HTTP 400/404/409/429/5xx | {"code":"INVALID_REQUEST","message":"…"} |
| Errors (relayer) | { status: "rejected", code, message }; codes are the contract's error names | {"status":"rejected","code":"InvalidSize",…} |
| Strict query strings | Newer routes reject unknown or repeated params with 400. Build queries with URLSearchParams and omit defaults | ?window=7d |
| Rate limits (per IP) | Indexer: 60 burst, 20/s. Prices: 30 burst, 10/s (/history costs 3). Relayer: 30 burst, 10/s, and 5 intents/s per signer. Over the limit: 429 | poll every 2–5 s |
How a trade happens
The wallet signs once to create a session key. After that, opening and closing are signed by the session key in the browser, with no popups and no gas for the user.
GET /config: contracts, EIP-712 types, market limits and chain time (use it for signedAt).POST /action kind depositPermit: a USDG permit signature, no approve, no gas.POST /action kind registerSessionKey, up to 30 days. Keep the private key in the browser only.POST /intent kind open with a priceLimit, then poll GET /intent/:id until executed./api/positions/:user (live PnL, liquidation price) and /api/preview/:id before closing.POST /intent kind close. Profit is paid now or queued if the house is short (see queue).Which screen uses what
A map from the app's pages to the calls behind them. Poll account data every 4 s; feeds every 4–10 s; charts every 30–60 s.
| Screen | Calls |
|---|---|
| Trade | Prices websocket, /history + /api/volume (chart), /api/markets, /api/config, /api/positions/:user, /api/preview/:id, /api/activity?kind=trades (tape), relayer /config, /intent, /live |
| Portfolio | /api/account/:user, /api/pnl/:user, /api/history/:user, /api/activity?user=, relayer /action (withdraw, deposit) |
| Leaderboard | /api/leaderboard/accounts (sort by pnl, liquidations, staked…), /api/leaderboard/positions |
| Public profile | /api/profile/by-username/:name, /api/account/:user, /api/pnl/:user, /api/activity?user=&kind=close,liquidation |
| House | /api/house, /api/stats, /api/stats/history, /api/activity |
| Token | /api/token, /api/token/history, /api/rate, /api/account/:user (staking), relayer /action (stake, unstake, claim) |
Error codes
Show message by default and branch on code only where the UI does something different.
| Service | Code | HTTP | Meaning |
|---|