Agent-readable docs index: /llms.txt. Full docs in one file: /llms-full.txt. Download /docs.zip to grep all markdown files locally.

TradingView alerts

A TradingView alert can post its message to a webhook URL. FiveSocket has no inbound webhooks, so the alert goes to a small relay that you run, and the relay calls 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.
This page uses a Cloudflare Worker as the relay. To use n8n instead, see n8n. For the overview, see send TradingView or n8n alerts to MT5.

Before you start

1. Allow the symbols the alert may trade

Trading stays off until the account has a policy. Name each symbol exactly as your broker does, with the largest volume one order may have.
curl -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"}]}'
An order for another symbol or a larger volume is refused before it reaches MT5.

2. Write the alert message

In the TradingView alert, tick Webhook URL and set the message to JSON. {{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.
{ "token": "a-long-random-string", "id": "{{timenow}}", "symbol": "EURUSD", "side": "{{strategy.order.action}}", "volume": "0.10" }
Type the symbol yourself. A TradingView ticker is often not the name your MT5 broker uses.

3. Deploy the relay

The Worker checks the shared token, then sends the order. Store ALERT_TOKEN, FIVESOCKET_KEY and FIVESOCKET_ACCOUNT_ID as Worker secrets, and use the Worker's URL as the alert's webhook URL.
type 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 }) }, }
The same Idempotency-Key and body never send the order twice, so a repeated delivery of one alert is safe.

4. Read the result

A confirmed order returns 200 with a command:
{ "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.
The first order after the account has been idle logs in to your broker and can take several seconds.

Close a position from an alert

Read the open positions, then close one by its ID. Leave out volume to close all of it.
curl 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"}'
A webhook URL has no sign-in. Keep the token long and random, keep the policy narrow, and test on a demo account first. An order sent to a live account is a real trade.

Limits

  • FiveSocket sends nothing back to TradingView. It has no webhooks, price stream or WebSocket.
  • On an account with a prop-firm program set, every order needs a stopLoss.
  • Rate limits are per API key, workspace and account. See errors and limits.