Skip to content

WebSocket

Overview

The AVS WebSocket endpoint provides real-time updates for order events. Connect to receive instant notifications when orders are filled, partially filled, replaced, or canceled.

Connection

Open a WebSocket connection to the appropriate environment:

EnvironmentWebSocket URL
Trading UATwss://uat.atomicvaults.com/websocket
APAC UATwss://apac.uat.atomicvaults.com/websocket

Authentication is required via the X-API-KEY header when establishing the connection.

Example

javascript
const ws = new WebSocket("wss://uat.atomicvaults.com/websocket", {
  headers: {
    "X-API-KEY": "your-api-key",
  },
});

ws.onmessage = (event) => {
  const data = JSON.parse(event.data);
  console.log(`Event: ${data.message}, Order:`, data.order);
};

ws.onopen = () => {
  console.log("Connected to AVS WebSocket");
};

ws.onclose = () => {
  console.log("Disconnected from AVS WebSocket");
};

Message Format

Each message is a JSON object with the following structure:

json
{
  "message": "fill",
  "order": {
    "order_id": "abc123",
    "symbol": "AAPL",
    "side": "buy",
    "qty": "10",
    "filled_qty": "10",
    "status": "filled"
  }
}

Event Types

EventDescription
newOrder has been accepted
fillOrder has been completely filled
partial_fillOrder has been partially filled
replacedOrder has been modified/replaced
canceledOrder has been canceled

Multiple Connections

You may open multiple WebSocket connections simultaneously. Each connection receives the same set of order events for your account.

Reconnection

If the connection drops, implement automatic reconnection with exponential backoff:

javascript
function connect() {
  const ws = new WebSocket("wss://uat.atomicvaults.com/websocket", {
    headers: { "X-API-KEY": "your-api-key" },
  });

  let retryDelay = 1000;

  ws.onclose = () => {
    setTimeout(() => {
      retryDelay = Math.min(retryDelay * 2, 30000);
      connect();
    }, retryDelay);
  };

  ws.onopen = () => {
    retryDelay = 1000;
  };

  ws.onmessage = (event) => {
    const data = JSON.parse(event.data);
    handleOrderEvent(data);
  };
}