fx-chartingDocs
Data

Connecting data

The chart asks a datafeed for symbols, historical bars and live updates. There are four ways to provide one — from zero code to full control.

OptionUse it whenPage
createDatafeed()You have a function / endpoint for history and (optionally) a tick or bar streamcreateDatafeed
restDatafeed()Your bars come from a REST URLREST API
binanceDatafeed()Crypto from Binance — real data, no keyBinance
mt5Datafeed()Your broker's MetaTrader 5 server (separate package)MetaTrader 5
Your own objectYou need complete controlCustom datafeed
The shortest real connection
import { FxChart, createDatafeed } from "@fx-charting/max";

const datafeed = createDatafeed({
  symbols: ["EURUSD", "GBPUSD"],
  history: async ({ symbol, interval, to, countBack }) => {
    const res = await fetch(`https://my.api/bars?s=${symbol}&tf=${interval}&to=${to ?? ""}&limit=${countBack}`);
    return res.json(); // [[time, open, high, low, close, volume], …] or [{ time, open, … }]
  },
  ticks: (symbol, onTick) => {
    const ws = new WebSocket(`wss://my.api/ticks/${symbol}`);
    ws.onmessage = (e) => onTick(JSON.parse(e.data)); // { price, time?, volume?, bid?, ask? }
    return () => ws.close();
  },
});

export default () => <FxChart datafeed={datafeed} symbol="EURUSD" />;

That's it — the chart pages back through history as the user scrolls, builds candles of every interval from your ticks, and everything else (indicators, alerts, replay, experts, trading) runs on that data.