API
API overview
The read-only /api/v1 API: base URL, caching, units, paging, errors and every endpoint.
The API serves everything the engine writes to the database, plus live reads of the chain: the contracts, and the token's Ascend pool (its price, trades and candles). 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 (ENGINE_SERVES_API=true).
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 numbers in the asset's own units; USD is USD; times are ISO 8601 strings. Exceptions: history points use epoch milliseconds, the pool endpoints use epoch milliseconds and wei strings, and a draw's roundId and readyAt are unix seconds |
| 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, one draw's record).
Some reads are also cached inside each server instance: the HYPE price 5 s, market names and a coin's published art 10 min, on-chain contract reads 10 s, the Ascend ladder 12 s, the pool's summary and candles 5 s, its trades 3 s. A pool's fixed facts (pool id, escrow, fee, name) are kept once found; a pool that was not found is looked up again after a minute.
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 page/vault/funding takes limit only. /draws is not paged: it returns the last 50 rounds.
Errors
Every error has the same shape:
{ "error": { "code": "DATABASE_NOT_CONFIGURED", "message": "…" } }| HTTP | Code | When |
|---|---|---|
| 400 | VALIDATION_ERROR | Bad query parameters, an unknown candle interval, a draw round id that is not a positive integer, or a bad 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, Ascend market or draw round; or a pool token that is not one of this vault's own markets |
| 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 /router | 2 s | yes |
GET /revenue | 10 s | yes |
GET /draws | 10 s | yes |
GET /draws/:roundId | 60 s | yes |
GET /onchain | 10 s | no |
GET /markets/:id/ladder | 12 s | no |
GET /pool/:token | 5 s | no |
GET /pool/:token/trades | 3 s | no |
GET /pool/:token/candles | 5 s | no |
POST /admin/kill | no-store | yes |
POST /admin/strategies/:id | no-store | yes |
Note
The public site currently has no database connected. Every endpoint marked yes answers 503 DATABASE_NOT_CONFIGURED there; the ones marked no work.
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, including the Ascend pool, which is always read from the real /pool/* endpoints.
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.