JavaScript (browser)
Runs in a web page on the same computer as MetaTrader 5. The API allows cross-origin requests.
All examples assume the EA is running on the same computer with default ports. Order examples are for demo accounts.
Get a price
Section titled “Get a price”const API = "http://127.0.0.1:81";const q = await fetch(`${API}/v1/quote?symbol=EURUSD`).then((r) => r.json());document.querySelector("#price").textContent = `${q.BID} / ${q.ASK}`;Live price board
Section titled “Live price board”<div id="board"></div><script type="module"> const API = "http://127.0.0.1:81"; await fetch(`${API}/v1/track/prices?symbols=EURUSD,GBPUSD,XAUUSD`, { method: "POST" }); const rows = {}; const ws = new WebSocket("ws://127.0.0.1:81"); ws.onmessage = (e) => { const m = JSON.parse(e.data); if (m.MSG !== "TRACK_PRICES") return; rows[m.SYMBOL] ??= document.getElementById("board").appendChild(document.createElement("p")); rows[m.SYMBOL].textContent = `${m.SYMBOL} ${m.BID} ${m.ASK}`; };</script>