Socketrade

WebSocket

Live ticks, and only ticks.

The WebSocket is one connection per account and one job: push bid/ask ticks for the symbols you subscribe to. Positions, orders and history stay REST reads. Saying that plainly saves you a wrong architecture.

The contract

  • URL: wss://win-vi96ovqi4i6.taile61f2a.ts.net/v2/{account_id}/ws
  • Auth: the same X-API-Key header, or ?api_key= when the client cannot set a header.
  • Subscribe: {"action":"subscribe","symbols":["EURUSD"]}
  • Ack: {"type":"subscribed","topic":"prices","symbols":[…]}
  • List and unsubscribe: {"action":"list"} and {"action":"unsubscribe","symbols":[…]}
  • Limit: 64 symbols per socket. Slower consumers lose the oldest ticks first; the socket does not grow forever.

A tick

{
  "type": "tick",
  "topic": "prices",
  "symbol": "EURUSD",
  "bid": 1.08451,
  "ask": 1.08455,
  "last": 0,
  "volume": 0,
  "timeMsc": 1764450000123,
  "seq": 918273,
  "ts": 1764450000456
}

A zero on one side can mean the feed has not sent that side yet, not that there is no market. Keep the last known value.

Node

import WebSocket from "ws";

const ws = new WebSocket(
  `wss://win-vi96ovqi4i6.taile61f2a.ts.net/v2/${accountId}/ws`,
  { headers: { "X-API-Key": process.env.SOCKETRADE_KEY } },
);

ws.on("open", () => {
  ws.send(JSON.stringify({
    action: "subscribe",
    symbols: ["EURUSD", "XAUUSD"],
  }));
});

ws.on("message", (raw) => {
  const m = JSON.parse(raw.toString());
  if (m.type === "tick") console.log(m.symbol, m.bid, m.ask);
});

Python

On websockets older than 13, the header argument is extra_headers.

import asyncio, json, os, websockets

async def main():
    headers = {"X-API-Key": os.environ["SOCKETRADE_KEY"]}
    url = f"wss://win-vi96ovqi4i6.taile61f2a.ts.net/v2/{account_id}/ws"
    async with websockets.connect(url, additional_headers=headers) as ws:
        await ws.send(json.dumps({
            "action": "subscribe",
            "symbols": ["EURUSD", "XAUUSD"],
        }))
        async for raw in ws:
            msg = json.loads(raw)
            if msg.get("type") == "tick":
                print(msg["symbol"], msg["bid"], msg["ask"])

asyncio.run(main())

Browser option

A browser WebSocket cannot set an X-API-Key header. The gateway accepts ?api_key= for that case, but the key is then visible in the URL and in any logs that keep query strings. Prefer a backend; use the query only when you have to.

The REST host api.socketrade.com is a serverless front and does not carry WebSockets. Use the gateway host shown in the contract above.