Recipe 08 — Stream live portfolio via WebSocket
Status: ⚠️ partial SDK surface today:
client.ai.stream_chat(...)(SSE) — chat stream only SDK surface planned:client.portfolio.stream_ws(...)— M6+ TZ reference: TZ-10 §9.10 (WS catalog), TZ-1 §9.9.2 (WS auth)
What ships Day-0
The SDK supports streaming AI chat via SSE (POST /v1/ai/stream/sse)
and WebSocket (WS /v1/ai/stream/ws with Sec-WebSocket-Protocol: bearer.<jwt>).
A dedicated portfolio WS stream that pushes price + position deltas is
scheduled for M6+ (tz10-ws-catalog).
Today: AI chat SSE
async with CryptoAIClient(api_key="cag_live_...") as client:
async for chunk in client.ai.stream_chat(message="summarize my open positions"):
print(chunk.delta, end="", flush=True)
const client = new CryptoAIClient({ apiKey: 'cag_live_...' });
for await (const chunk of client.ai.streamChat({ message: 'summarize my open positions' })) {
process.stdout.write(chunk.delta ?? '');
}
What's missing
/v1/portfolio/stream/wsendpoint (real-time price + position events)- Portfolio-specific event types (
position_opened,pnl_tick, etc.)
When these land in M6+ this recipe will gain Python + TS examples that subscribe to the portfolio stream and react to events.