fx-chartingDocs
Data

WebSocket ticks

websocketTicks turns a socket that sends prices into a tick source, with automatic reconnects.

js
import { createDatafeed, websocketTicks } from "@fx-charting/max";

const datafeed = createDatafeed({
  symbols: ["EURUSD", "GBPUSD"],
  history: fetchBarsFromMyApi,
  ticks: websocketTicks("wss://stream.example.com", {
    subscribe: (symbol) => ({ action: "subscribe", symbol }),          // sent after connecting
    parse: (msg, symbol) => (msg.s === symbol ? { price: msg.b, bid: msg.b, ask: msg.a, time: msg.t } : null),
  }),
});

One socket per symbol. If your server multiplexes all symbols on one connection, write the ticks function yourself — it's just (symbol, onTick) => unsubscribe.