跳到主要内容

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.

URLPurpose
wss://api-avax.sparkydex.app/wsSparky native engine: trades, order book, ticker, klines, and (after auth) positions / orders / balances
wss://api-avax.sparkydex.app/ws/internalAlias of /ws
wss://api-avax.sparkydex.app/ws/externalProxy 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 type field: subscribe, unsubscribe, auth, auth_token, ping.
  • Server → client messages are JSON objects with a type field: 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 auth message first (AUTH_REQUIRED otherwise). Bots authenticate with a listenKey from POST /fapi/v1/listenKey; front ends use a JWT.
  • Subscribing to orderbook:*, ticker:*, kline:*, positions, orders or balance sends 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.