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://interface.xbtfx.com/v1/wsAuthentication
Section titled “Authentication”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.
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. Each message has a type field that identifies the message kind.
Client Messages
Section titled “Client Messages”| Type | Description |
|---|---|
auth | Authenticate the connection |
subscribe | Subscribe to symbol quotes |
unsubscribe | Unsubscribe from symbol quotes |
Server Messages
Section titled “Server Messages”| Type | Description |
|---|---|
auth | Authentication response |
quote | Price quote update |
Connection Lifecycle
Section titled “Connection Lifecycle”- Open a WebSocket connection to
wss://interface.xbtfx.com/v1/ws - Send an
authmessage with your API key - Wait for the
authresponse withstatus: "ok" - 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://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}`); }};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.