Skip to content

WebSocket Connection

The XBTFX WebSocket API provides real-time streaming market data including price quotes and order book depth.

wss://ws.xbtfx.com/v1/ws

wss://interface.xbtfx.com/v1/ws also works as an alias.

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"
}
LimitValue
Max connections per API key10
Max subscriptions per connection1000

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.

ActionDescription
authAuthenticate the connection
subscribeSubscribe to a channel
unsubscribeUnsubscribe from a channel
FieldValueDescription
actionauth_okAuthentication succeeded
actionauth_errorAuthentication failed
channelquotePrice quote update
  1. Open a WebSocket connection to wss://ws.xbtfx.com/v1/ws
  2. Send an auth message with your API key
  3. Wait for the auth_ok response
  4. Subscribe to symbols you want to receive quotes for
  5. Process incoming quote messages
  6. Unsubscribe or close the connection when done
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})`);
}
};

The server sends periodic ping frames. Most WebSocket libraries handle pong responses automatically. If your connection drops, reconnect and re-authenticate.