Skip to main content
Our WebSocket API follows the RFC 6455 standard. It is designed to be lightweight and persistent. Once a connection is established, it remains open until explicitly closed by the client or if rate limits are exceeded.
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 (Code 0). 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 code 1. Format: 1[PairID]|[Ask]|[Bid]|[RelativeTime] Example:
Breakdown:

Calculating timestamps

To get the actual time of an update, combine the start_time from the Initial Message with the relative time from the update. Formula: Timestamp=start_time+relative_timetime_mult\text{Timestamp} = \text{start\_time} + \frac{\text{relative\_time}}{\text{time\_mult}} Example Calculation: Using the values from the examples above:
  • start_time: 1594922406.851688
  • time_mult: 1000
  • relative_time: 10