Skip to content

WebSocket Connection

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

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

After opening a WebSocket connection, you must authenticate by sending an auth message as the first message:

{
"type": "auth",
"api_key": "your_api_key_here"
}

The server responds with a confirmation:

{
"type": "auth",
"status": "ok"
}

If authentication fails, the connection is closed.

LimitValue
Max connections per API key10
Max subscriptions per connection1000

All messages are JSON. Each message has a type field that identifies the message kind.

TypeDescription
authAuthenticate the connection
subscribeSubscribe to symbol quotes
unsubscribeUnsubscribe from symbol quotes
TypeDescription
authAuthentication response
quotePrice quote update
  1. Open a WebSocket connection to wss://interface.xbtfx.com/v1/ws
  2. Send an auth message with your API key
  3. Wait for the auth response with status: "ok"
  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://interface.xbtfx.com/v1/ws");
ws.onopen = () => {
ws.send(JSON.stringify({
type: "auth",
api_key: "your_api_key_here"
}));
};
ws.onmessage = (event) => {
const msg = JSON.parse(event.data);
if (msg.type === "auth" && msg.status === "ok") {
ws.send(JSON.stringify({
type: "subscribe",
symbols: ["EURUSD", "GBPUSD"]
}));
}
if (msg.type === "quote") {
console.log(`${msg.symbol}: ${msg.bid} / ${msg.ask}`);
}
};

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