Engine API and stream
Read-only HTTP routes and a WebSocket preview. Nothing here can move funds.
Site routes
Use the site's routes: their URL is stable. They proxy the engine with a 4 second timeout. When the engine is unreachable they answer HTTP 503 with {"ok":false,"error":"engine unreachable"}, and the chain routes keep working.
| Route | Returns |
|---|---|
GET /api/engine/health | ok, wsConnected, wsLagMs, uptimeS |
GET /api/engine/stats | live ingest-to-decision percentiles, frames, decisions, fires sent and refused, strategies, atoms, WebSocket state, cross-check gap |
GET /api/engine/market | HYPE, BTC, ETH, SOL mark, mid, oracle, funding, oi, and kHYPE.rate |
GET /api/engine/strategies | strategies the engine has loaded from the registry |
GET /api/engine/strategies/<id> | one strategy and its decision records, or 404 |
GET /api/engine/fires | the last 50 decision records: values, labels, snapshot hash, status, tx, decide time |
GET /api/engine/metrics | Prometheus text |
POST /api/engine/compile | compile a source line |
GET /api/engine-url | {"http": string|null, "ws": string|null}, the current engine URL and its preview socket |
Compile
curl -s https://scriptcore.me/api/engine/compile \
-H 'content-type: application/json' \
-d '{"source": "if HYPE.funding < 0 then close HYPE"}'{"ok": true, "code": "0x4353...", "codeHash": "0x...", "bytes": 42,
"venue": "HyperCore", "slots": ["HYPE.funding"], "actions": ["Close { ... }"]}
{"ok": false, "error": {"col": 5, "msg": "..."}}Sources are capped at 2000 characters.
Live preview stream
Ask /api/engine-url for the socket, connect, and send {"source": "..."}. The engine answers with the compile result, then a tick about four times a second. Each connection runs its own one-strategy engine on the live state, so crosses and durations behave exactly as they will once registered. Send a new source at any time; it replaces the old one. A source without its action yet still previews its condition.
{"type": "compiled", "ok": true, ..., "condition": {"ok": true, "slots": ["HYPE.mark"]}}
{"type": "tick", "t": 1764400000250, "values": [{"label": "HYPE.mark", "value": "35.412"}],
"result": false, "firedNow": false, "fires": 0, "bytes": 20}result is null until every value the condition reads has arrived. firedNow marks a rising edge in that tick; fires counts them for the session. Sessions close after 30 minutes.
Chain routes
These read the chain directly and work with the engine down.
| Route | Returns |
|---|---|
GET /api/tape?limit=20 | recent fires from the registry's Fired events, each with its source decoded from the registered bytecode, its values and transaction, plus the engine's decision record (labels, status, decide_us) when the engine is up; engine: up or down |
GET /api/strategies?owner=0x... | strategies from Registered events with their live state (escrow, fires, killed, limits) and decoded source |
Raw engine endpoints
The engine serves the same API itself: GET /health, /metrics, /api/stats, /api/market, /api/strategies, /api/strategies/{id}, /api/fires, POST /api/compile and WS /ws/preview, with open CORS. Its URL can change; read it from /api/engine-url instead of hard-coding it.