WebSocket Connection
The XBTFX WebSocket API provides real-time streaming market data including price quotes and order book depth.
Connection URL
Section titled “Connection URL”wss://ws.xbtfx.com/v1/ws
wss://interface.xbtfx.com/v1/wsalso works as an alias.
Authentication
Section titled “Authentication”After opening a WebSocket connection, you must authenticate by sending an auth message as the first message:
{ "action": "auth", "token": "your_api_key_here"}The server responds with a confirmation:
{ "action": "auth_ok", "login": 12345678, "tier": "standard"}If authentication fails, the server responds with:
{ "action": "auth_error", "message": "Invalid API key"}Connection Limits
Section titled “Connection Limits”| Limit | Value |
|---|---|
| Max connections per API key | 10 |
| Max subscriptions per connection | 1000 |
Message Format
Section titled “Message Format”All messages are JSON. Client messages use an action field to identify the request. Server responses use action for auth messages and channel for data messages.
Client Messages
Section titled “Client Messages”| Action | Description |
|---|---|
auth | Authenticate the connection |
subscribe | Subscribe to a channel |
unsubscribe | Unsubscribe from a channel |
Server Messages
Section titled “Server Messages”| Field | Value | Description |
|---|---|---|
action | auth_ok | Authentication succeeded |
action | auth_error | Authentication failed |
channel | quote | Price quote update |
Connection Lifecycle
Section titled “Connection Lifecycle”- Open a WebSocket connection to
wss://ws.xbtfx.com/v1/ws - Send an
authmessage with your API key - Wait for the
auth_okresponse - Subscribe to symbols you want to receive quotes for
- Process incoming quote messages
- Unsubscribe or close the connection when done
Example (JavaScript)
Section titled “Example (JavaScript)”const ws = new WebSocket("wss://ws.xbtfx.com/v1/ws");
ws.onopen = () => { ws.send(JSON.stringify({ action: "auth", token: "your_api_key_here" }));};
ws.onmessage = (event) => { const msg = JSON.parse(event.data);
if (msg.action === "auth_ok") { ws.send(JSON.stringify({ action: "subscribe", channel: "quotes", symbols: ["EURUSD", "GBPUSD"], depth: true })); }
if (msg.channel === "quote") { console.log(`${msg.symbol}: ${msg.bid} / ${msg.ask} (spread: ${msg.spread})`); }};Keep-Alive
Section titled “Keep-Alive”The server sends periodic ping frames. Most WebSocket libraries handle pong responses automatically. If your connection drops, reconnect and re-authenticate.