Skip to main content

Websocket Gateway API Design

Endpoints:

Binance:

Spot

  • wss://stream.binance.com:443
    • Raw stream: /ws/<streamName>
    • Combined streams: /stream?streams=<streamName1>/<streamName2>/<streamName3>

USD-M Futures

  • Base: wss://ws-fapi.binance.com/ws-fapi/v1
  • Market Data
    • Raw stream: wss://fstream.binance.com/ws/bnbusdt@aggTrade
    • Combined streams: wss://fstream.binance.com/stream?streams=bnbusdt@aggTrade/btcusdt@markPrice
  • User Data Stream
    • wss://fstream.binance.com/ws/XaEAKTsQSRLZAGH9tuIu37plSRsdjmlAVBoNYPUITlTAko1WI22PgmBMpI1rS8Yh

Coin-M Futures

  • Base: wss://ws-dapi.binance.com/ws-dapi/v1
  • Market data
    • wss://dstream.binance.com/ws/bnbusdt@aggTrade
    • wss://dstream.binance.com/stream?streams=bnbusdt@aggTrade/btcusdt@markPrice
  • User Data Stream
    • wss://dstream.binance.com/ws/XaEAKTsQSRLZAGH9tuIu37plSRsdjmlAVBoNYPUITlTAko1WI22PgmBMpI1rS8Yh

HashKey Public stream: wss://stream-glb.sim.hashkeydev.com/quote/ws/v1 Private stream: wss://stream-glb.sim.hashkeydev.com/api/v1/ws/{listenKey}

V2 only support public stream Sandbox Public stream: wss://stream-glb.sim.hashkeydev.com/quote/ws/v2

WebSocket API General Info

The base endpoint is: wss://ws-fapi.binance.com/ws-fapi/v1

The base endpoint for testnet is: wss://testnet.binancefuture.com/ws-fapi/v1

A single connection to the API is only valid for 24 hours; expect to be disconnected after the 24-hour mark.

Websocket server will send a ping frame every 3 minutes.

  • If the websocket server does not receive a pong frame back from the connection within a 10 minute period, the connection will be disconnected.
  • When you receive a ping, you must send a pong with a copy of ping's payload as soon as possible.
  • Unsolicited pong frames are allowed, but will not prevent disconnection. It is recommended that the payload for these pong frames are empty.

Signature payload must be generated by taking all request params except for the signature and sorting them by name in alphabetical order.

Lists are returned in chronological order, unless noted otherwise.

All timestamps are in milliseconds in UTC, unless noted otherwise.

All field names and values are case-sensitive, unless noted otherwise.

INT parameters such as timestamp are expected as JSON integers.

DECIMAL parameters such as price are expected as JSON strings.

Private Stream requests - you will need to establish a separate WebSocket connection to listen to user data streams

Heartbeat check

Client initiates a periodic heartbeat message (ping message) every 10 seconds, which is used to keep alive the connection

Public Stream

Topics in docs:

  • Kline_$interval: kline_15m
  • Realtimes: realtimes
  • Trade: trade
  • Depth: depth
  • BBO: bbo

Futures public topics: wss://bws-glb.global.sim.hashkeydev.com/ws/quote/v1?lang=en-us

  • diffMergedDepth
  • trade
  • markPrice
  • index
  • kline_15m

SPOT AND FUTURES SYMBOLS at same stream

Private Streams (User Data Streams)

A User Data Stream listenKey is valid for 60 minutes after creation.

Doing a PUT on a listenKey will reset its validity to 60 minutes.

Doing a DELETE on a listenKey will close the stream and invalidate the listenKey

Doing a POST on an account with an active listenKey will return the currently active listenKey and extend its validity for 60 minutes.

One user has only one listenKey at a time, and it is used to access all private streams for that user.

For one connection(one user data), the user data stream payloads can guaranteed to be in order during heavy periods; Strongly recommend you order your updates using E (event time (ms)) field.

A single connection is only valid for 24 hours; expect to be disconnected at the 24 hour mark.

Topics in docs:

  • Account Update
  • Order Update
  • Ticket push
  • Position push

Sport private:

  • order
  • balance

Future Private topic: wss://bws-glb.global.sim.hashkeydev.com/api/ws/user?lang=en-us&orgId=9001

  • futures_position
  • futures_tradeable
  • futures_order
  • futures_symbol_suspend_plan
  • balance
  • futures_plan_order