Standard PING/PONG control frames are disabled to reduce overhead. The connection relies on the underlying TCP keepalive mechanisms.
Connection Flow
1. Establish Connection
Connect to the WebSocket endpoint (e.g.,wss://api.xchangeapi.com/websocket/live).
2. Subscribe to Pairs
Immediately after connecting, send a JSON message to subscribe to specific currency pairs:3. Receive Initial Configuration
Upon successful subscription, the server sends an Initial Message (Code0). This message contains session details and the mapping definitions required to parse subsequent updates.
Example Initial Message:
Message Structure
All server messages start with a single-digit Message Code, followed by the message body.Message Codes
See Message Codes for a complete list.
Processing Updates (Code 1)
Update messages are optimized for size and speed. They are not JSON. Instead, they use a pipe-separated format prefixed by the message code1.
Format:
1[PairID]|[Ask]|[Bid]|[RelativeTime]
Example:
Calculating timestamps
To get the actual time of an update, combine thestart_time from the Initial Message with the relative time from the update.
Formula:
Example Calculation:
Using the values from the examples above:
start_time:1594922406.851688time_mult:1000relative_time:10
