Trading
Broker integration (onPlaceOrder)
Called for every order — from the trading panel, the chart buttons or the API — before it is filled.
<FxChart
onPlaceOrder={async (order) => {
// order = { symbol, side: "buy"|"sell", type: "market"|"limit"|"stop", lots, price, sl, tp, marketPrice, time }
const res = await fetch("/api/orders", { method: "POST", body: JSON.stringify(order) });
const data = await res.json();
if (!res.ok) return { error: data.message }; // ✗ rejected → shown to the user
return { id: data.ticket, price: data.fillPrice }; // ✓ use your broker's ticket and fill price
}}
/>| Return | Result |
|---|---|
nothing / true | Accepted, filled at the chart's price |
{ id, price } | Accepted with your ticket id and fill price |
false / { error } | Rejected; the error is shown |
a Promise | Waits for it (the panel shows the result as a notification) |
▶ Live example — every order asks for confirmation
Use the BUY / SELL buttons on the chart…