WebSocket API
Real-time alpha signals, prices, and portfolio events over WebSocket
WebSocket API
MarketIntell exposes a single WebSocket endpoint for low-latency push notifications. The same alpha signals that fan out over webhooks (with retry + signing) also flow over the WebSocket — pick whichever transport fits your client.
Endpoint:
wss://api.marketintell.ai/wsSame host and port as the HTTP API. The server handles
Upgrade: websocketrequests directly before falling through to Hono.
Authentication
Every connection must authenticate as an API key. Three options, in the order the server tries them:
1. Sec-WebSocket-Protocol subprotocol (preferred)
Browsers don't allow custom headers on WebSocket(), so the API accepts the key as a subprotocol token: auth.<api_key>.
const ws = new WebSocket("wss://api.marketintell.ai/ws", `auth.${apiKey}`);2. Authorization header (Node.js, server-to-server)
import { WebSocket } from "ws";
const ws = new WebSocket("wss://api.marketintell.ai/ws", {
headers: { Authorization: `Bearer ${apiKey}` },
});3. First-message auth (legacy)
If neither the subprotocol nor the header is present, the server waits for the first message and expects:
{ "type": "auth", "key": "mi_k_..." }The server replies { "type": "authenticated" } on success or closes with code 4401 on failure.
Subscriptions
After auth, subscribe to one or more channels:
ws.send(JSON.stringify({ action: "subscribe", channel: "signals" }));| Channel | Push payload |
|---|---|
signals | New alpha signals (the same payload shape as the webhook delivery, one signal per frame) |
prices | (Reserved — populated when the price-tick stream is enabled) |
portfolio | (Reserved — populated when portfolio events are enabled) |
To unsubscribe:
{ "action": "unsubscribe", "channel": "signals" }Message format
Every server-pushed frame is JSON of the form:
{
"type": "signal",
"channel": "signals",
"data": {
"id": "sig_001",
"headline": "Whale accumulation: 5,200 BTC moved to cold storage",
"sentiment": "bullish",
"impact": "HIGH",
"category": "whale",
"tokens_affected": ["BTC"]
}
}Connection lifecycle frames use type values like "authenticated", "subscribed", "unsubscribed", and "error".
Reconnection
The server doesn't ping; clients should send a periodic ping (Bun's Bun.serve honors WebSocket protocol-level ping/pong) and reconnect with exponential backoff if the socket drops. The reference React hook (apps/web/src/hooks/use-alpha-ws.ts) caps backoff at 30 seconds.
Tier gating
The WebSocket is open to all tiers, but signals is rate-limited to your tier's per-minute API budget. Free keys see throttled fan-out; Pro/Enterprise see every signal as soon as the alpha engine publishes it.
Worked example
const ws = new WebSocket("wss://api.marketintell.ai/ws", `auth.${apiKey}`);
ws.addEventListener("open", () => {
ws.send(JSON.stringify({ action: "subscribe", channel: "signals" }));
});
ws.addEventListener("message", (e) => {
const frame = JSON.parse(e.data as string);
if (frame.type === "signal") {
console.log(`[${frame.data.impact}] ${frame.data.headline}`);
}
});
ws.addEventListener("close", (e) => {
if (e.code === 4401) console.error("Auth failed — check the API key");
});