WebSocket
๐ General Overview
WebSocket is a modern HTML5 protocol that supports full-duplex communication between the client and the server. Unlike traditional polling or HTTP requests, WebSocket only requires a single handshake to establish a persistent connection, enabling efficient real-time data transfer.
โ
Advantages
Extremely lightweight headers (~2 bytes)
Bi-directional communication: server and client can both initiate messages
No repeated TCP connectionsโsaves server resources and bandwidth
Highly recommended for real-time market data and order book depth
๐ Connection Info
WebSocket URL:
wss://ws.coinlocally.com/kline-api/ws
Compression: Binary data is compressed using Gzip โ clients must decompress accordingly.
๐ซ Heartbeat (Ping/Pong)
To maintain connection stability:
The server sends a
ping
message every 10 seconds.The client should immediately respond with a
pong
message.The server does not enforce one-to-one verification, but may close the connection if no pong is received.
Ping Message (Server โ Client)
Pong Message (Client โ Server)
๐ก Command Format
๐ Subscribe & Unsubscribe
sub
market_$symbol_depth_step0
Subscribe to order book depth
unsub
market_$symbol_depth_step0
Unsubscribe from order book depth
sub
market_$symbol_trade_ticker
Subscribe to real-time trades
unsub
market_$symbol_trade_ticker
Unsubscribe from real-time trades
sub
market_$symbol_ticker
Subscribe to 24h market ticker
unsub
market_$symbol_ticker
Unsubscribe from 24h market ticker
sub
market_$symbol_kline_1min
Subscribe to 1-minute kline
req
market_$symbol_kline_1month
Request 1-month historical kline
๐ฅ Subscription Examples
๐ Depth (Order Book)
Subscribe Message
Response Payload
๐ Real-Time Trade
Subscribe Message
Response Payload
๐ Kline (Candlestick Data)
Subscribe Message
Response Payload
๐ Market Ticker (24h)
Subscribe Message
Response Payload
๐ค Request Historical Data
๐ฐ Historical Kline
Request Message
Response Payload
๐งพ Historical Trades
Request Message
Response Payload
Last updated