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.
| Option | Use it when | Page |
|---|---|---|
createDatafeed() | You have a function / endpoint for history and (optionally) a tick or bar stream | createDatafeed |
restDatafeed() | Your bars come from a REST URL | REST API |
binanceDatafeed() | Crypto from Binance — real data, no key | Binance |
mt5Datafeed() | Your broker's MetaTrader 5 server (separate package) | MetaTrader 5 |
Your own object | You need complete control | Custom datafeed |
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.