WebSocket API Basics
Sparky exposes one WebSocket endpoint per deployment. It carries public market data and private user-data channels over a single connection with a JSON subscribe protocol. It is not Binance's stream format (<symbol>@trade, /stream?streams=); it is Sparky's own, documented in Market Data Streams.
| URL | Purpose |
|---|---|
wss://api-avax.sparkydex.app/ws | Sparky native engine: trades, order book, ticker, klines, and (after auth) positions / orders / balances |
wss://api-avax.sparkydex.app/ws/internal | Alias of /ws |
wss://api-avax.sparkydex.app/ws/external | Proxy of the external price source (Hyperliquid-format messages); mark price / ticker / order book for reference only |
Replace api-avax with the host of the chain you trade on (see Base URLs).
Protocol summary
- Client → server messages are JSON objects with a
typefield:subscribe,unsubscribe,auth,auth_token,ping. - Server → client messages are JSON objects with a
typefield:subscribed,unsubscribed,auth_result,trade,orderbook,ticker,kline,kline_snapshot,position,order,balance,error,pong. - Channel names use a colon separator:
trades:BTCUSDT,orderbook:BTCUSDT,ticker:BTCUSDT,kline:BTCUSDT:1m; private channels are static names:positions,orders,balance. - Unknown channels are rejected with
{"type":"error","code":"INVALID_CHANNEL"}rather than silently accepted. - Private channels require an
authmessage first (AUTH_REQUIREDotherwise). Bots authenticate with alistenKeyfromPOST /fapi/v1/listenKey; front ends use a JWT. - Subscribing to
orderbook:*,ticker:*,kline:*,positions,ordersorbalancesends an immediate snapshot, then deltas. - Send
{"type":"ping"}and expect{"type":"pong"}for application-level keepalive.
WebSocket API (request/response over WS)
Status: Not yet implemented (空缺).
Binance's wss://…/ws-fapi/v1 order-entry API (order.place, order.cancel, … over a socket) has no Sparky equivalent. Place and cancel orders over REST; watch fills over the orders / positions channels.
Binance stream compatibility
Sparky does not serve <symbol>@aggTrade, <symbol>@markPrice, <symbol>@depth, combined /stream?streams= URLs, or /ws/<listenKey> user-data URLs. Each Binance stream page in Market Data Streams points to the Sparky channel that carries the same information, or is marked not implemented.