POST /v1/accounts/{accountId}/execution/orders. FiveSocket then places the order from its hosted MT5 terminal. You run no Expert Advisor, no MT5 terminal and no Windows machine.trading:execute scope. See authentication.12345curl -X PUT https://api.fivesocket.com/v1/accounts/acc_.../execution \ -H "Authorization: Bearer $FIVESOCKET_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: enable-1" \ -d '{"symbols":[{"symbol":"EURUSD","maxVolume":"0.10"}]}'
{{timenow}} and {{strategy.order.action}} are TradingView placeholders: the first gives each alert a unique ID and the second is buy or sell for a strategy alert.1234567{ "token": "a-long-random-string", "id": "{{timenow}}", "symbol": "EURUSD", "side": "{{strategy.order.action}}", "volume": "0.10" }
ALERT_TOKEN, FIVESOCKET_KEY and FIVESOCKET_ACCOUNT_ID as Worker secrets, and use the Worker's URL as the alert's webhook URL.1234567891011121314151617181920212223242526272829303132333435type Env = { ALERT_TOKEN: string, FIVESOCKET_KEY: string, FIVESOCKET_ACCOUNT_ID: string } type Alert = { token: string, id: string, symbol: string, side: "buy" | "sell", volume: string } export default { async fetch(request: Request, env: Env): Promise<Response> { if (request.method !== "POST") { return new Response(null, { status: 405 }) } const alert = (await request.json()) as Alert if (alert.token !== env.ALERT_TOKEN) { return new Response(null, { status: 403 }) } const clientOrderId = `tv-${alert.id}`.slice(0, 31) const order = await fetch( `https://api.fivesocket.com/v1/accounts/${env.FIVESOCKET_ACCOUNT_ID}/execution/orders`, { method: "POST", headers: { Authorization: `Bearer ${env.FIVESOCKET_KEY}`, "Content-Type": "application/json", "Idempotency-Key": clientOrderId, }, body: JSON.stringify({ clientOrderId, symbol: alert.symbol, side: alert.side, type: "market", volume: alert.volume, }), }, ) return new Response(await order.text(), { status: order.status }) }, }
Idempotency-Key and body never send the order twice, so a repeated delivery of one alert is safe.200 with a command:1234567{ "commandId": "0b1c6f0e-...", "operation": "order.submit", "outcome": "accepted", "status": "filled", "errorCode": null }
outcome: "rejected" with an errorCode means FiveSocket refused the order before the broker saw it, for example execution_policy_violation.outcome: "rejected" with a retcode is the broker's own refusal.202 with outcome: "commit_unknown" means the reply was lost. Poll GET /v1/accounts/{accountId}/execution/commands/{commandId} and do not send the order again.volume to close all of it.12345678curl https://api.fivesocket.com/v1/accounts/acc_.../positions \ -H "Authorization: Bearer $FIVESOCKET_KEY" curl -X POST https://api.fivesocket.com/v1/accounts/acc_.../execution/positions/19283746/close \ -H "Authorization: Bearer $FIVESOCKET_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: close-1" \ -d '{"clientOrderId":"close-1"}'
stopLoss.