JavaScript
MT5 from JavaScript, without a terminal.
REST is plain fetch. The WebSocket is for live ticks and belongs on your server, because a browser cannot set the API-key header.
A small client
const BASE = "https://api.socketrade.com";
const KEY = process.env.SOCKETRADE_KEY;
async function call(path, options = {}) {
const res = await fetch(BASE + path, {
...options,
headers: {
"X-API-Key": KEY,
"Content-Type": "application/json",
...(options.headers || {}),
},
});
const body = await res.json().catch(() => ({}));
if (!res.ok) throw new Error(`${res.status} ${JSON.stringify(body)}`);
return body;
}
const usage = await call("/v2/usage");
const account = await call("/v2/accounts", {
method: "POST",
body: JSON.stringify({
accountNumber: "41299492",
accountPassword: process.env.MT5_PASSWORD,
accountServerHost: "Deriv-Demo",
name: "Demo",
}),
});
await call(`/v2/accounts/${account.id}/connect`, { method: "POST" });
const status = await call(`/v2/${account.id}/status`);
const positions = await call(`/v2/${account.id}/positions`);Place and close
const order = await call(`/v2/${account.id}/OrderSend`, {
method: "POST",
body: JSON.stringify({ symbol: "EURUSD", operation: 0, volume: 0.01 }),
});
await call(`/v2/${account.id}/PositionClose`, {
method: "POST",
body: JSON.stringify({ ticket: order.ticket }),
});The browser rule
Keep the key on your server. A browser bundle exposes it to anyone who opens devtools. For the socket, open it from Node or a server route and pass the ticks to the page.
The WebSocket contract →