این صفحه contract اتصال stream واقعی بکاند را مستند میکند. UI و runtime همچنان فقط با data-loader abstraction کار میکنند؛ Socket.IO داخل api-client پنهان شده است.
Transport mode
stream
برای production میتوان stream را روشن کرد؛ حالت پیشفرض امنتر polling است.
Namespace
/v1/market/stream
namespace واقعی backend برای latest_update و candle_update.
Token exposure
Headers/Auth only
runtime token در embed code، URL عمومی، postMessage یا UI نمایش داده نمیشود.
adapter boundary
Frontend stream rules
- Runtime token must come from /api/v1/widget/bootstrap and stay in Socket.IO auth, never query-snippet UI.
- Handshake namespace is /v1/market/stream and subscribe payload is { symbols: [...], interval }.
- candle_update payload is normalized before KLineCharts; old timestamps are dropped before callback.
- Security/token/license/quota errors stop the stream path instead of creating retry storms.
- Polling fallback remains the default unless NEXT_PUBLIC_REALTIME_TRANSPORT=stream is explicitly enabled.
برای تست واقعی، ابتدا backend bootstrap باید runtimeToken کوتاهمدت برگرداند، بعد `NEXT_PUBLIC_API_MODE=real` و `NEXT_PUBLIC_REALTIME_TRANSPORT=stream` فعال شود. اگر token وجود نداشته باشد یا backend خطای امنیتی بدهد، adapter بهصورت fail-closed متوقف میشود.