API
API overview
The read-only /api/v1 API: base URL, caching, units, paging and errors.
The API serves everything the engine writes to the database, plus live on-chain reads. It is read-only, except for two admin calls. It holds no keys and sends no transactions.
It is a single framework-free handler (lib/server/api.ts) served by Next.js at app/api/v1/[...path]/route.ts, and optionally by the engine itself.
Base URL
https://<your-site>/api/v1The app calls NEXT_PUBLIC_API_URL + "/api/v1", which is the same origin unless that build-time variable points elsewhere.
Conventions
| Methods | GET for reads, POST for the two admin calls, OPTIONS answers 204 |
| CORS | access-control-allow-origin: *, methods GET, POST, OPTIONS, headers content-type, authorization |
| Units | Amounts are in the asset's own units; USD is USD; times are ISO 8601 strings (history points use epoch milliseconds) |
| Rate limiting | None in code. Edge caching is the protection: a crowd watching costs about one database read per second |
Caching
Each endpoint has a cache lifetime (s-maxage). On Vercel the response carries:
cache-control: public, max-age=0, s-maxage=<maxAge>, stale-while-revalidate=<5 × maxAge>Errors and admin calls are no-store. Lifetimes range from 1 s (open orders) to 60 s (config). Some reads are also cached inside each server instance: the HYPE price 5 s, market names 10 min, on-chain reads 10 s, the Montra ladder 12 s.
Paging
List endpoints that can grow without bound (/vault/fills, /ledger) are paged by id, newest first:
| Query | Type | Default |
|---|---|---|
limit | integer 1–500 | 50 |
cursor | positive integer: returns rows with id < cursor | none |
market, strategy, kind | filters (≤ 40 characters) | none |
since | epoch milliseconds (fills only) | none |
interface Page<T> { items: T[]; nextCursor: string | null } // nextCursor is null on the last pageErrors
Every error has the same shape:
{ "error": { "code": "DATABASE_NOT_CONFIGURED", "message": "…" } }| HTTP | Code | When |
|---|---|---|
| 400 | VALIDATION_ERROR | Bad query parameters or admin body |
| 401 | UNAUTHORIZED | Wrong admin token |
| 403 | ADMIN_DISABLED | ADMIN_TOKEN not set, or shorter than 24 characters |
| 404 | NOT_FOUND | Unknown route, strategy or Montra market |
| 503 | DATABASE_NOT_CONFIGURED | The endpoint needs the database and DATABASE_URL is not set |
| 502 | UPSTREAM_ERROR | A data source did not answer (database, RPC, upstream API) |
Endpoints
| Method & path | Cache | Needs the database |
|---|---|---|
GET /status | 2 s | optional |
GET /config | 60 s | no |
GET /vault | 2 s | yes |
GET /vault/history | 15 s | yes |
GET /vault/balances | 2 s | yes |
GET /vault/positions | 2 s | yes |
GET /vault/orders | 1 s | yes |
GET /vault/fills | 2 s | yes |
GET /vault/funding | 10 s | yes |
GET /vault/transfers | 10 s | yes |
GET /strategies | 2 s | yes |
GET /strategies/:id | 2 s | yes |
GET /ledger | 2 s | yes |
GET /arb | 2 s | yes |
GET /revenue | 10 s | yes |
GET /onchain | 10 s | no |
GET /markets/:id/ladder | 12 s | no |
POST /admin/kill | no-store | yes |
POST /admin/strategies/:id | no-store | yes |
Mock data
To see the app full of data without a database or an engine, open /app?mock=1 (?mock=off to leave; also ?mock=paper, halted, offline). A simulated engine in the browser answers the app's API calls: it replays 30 days of trading against real price history, then keeps trading live prices, starting from $50,000. Market data stays live.
Danger
Mock data is invented and nothing on screen says so. It only exists in the visitor's browser tab. Never set NEXT_PUBLIC_MOCK_DATA=1 on the public site: it would show invented numbers to everyone.