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