By Nima Dorostkar, Trading Systems Engineer — MT5, FIX & broker software · Updated
MT5 Gateway & Trading Terminal development for brokers
MT5 Gateway
+ Trading Terminal.
Everything a broker needs to let clients trade on MetaTrader 5: the backend that talks to your MT5 server, and the frontend your clients trade on. Built, deployed under your brand, and customized by one team.
The MT5 Gateway handles communication with MetaTrader 5 and execution; the Trading Terminal is how your clients use their trading accounts. We build, deploy, and customize both, as one platform or one half at a time. Deep dives: MT5 gateway development and trading terminal development.
- Volume
- 1.00 lot
- Spread
- 0.18
- Execution
- Market
- Route
- Hybrid A/B
| Symbol | Side | Lots | Price | P/L |
|---|---|---|---|---|
| XAUUSD | Buy | 2.00 | 3,693.45 | +$3,130.73 |
| EURUSD | Sell | 5.00 | 1.17743 | −$1,065.24 |
| BTCUSD | Buy | 0.50 | 112,279.4 | +$89.68 |
AI riskXAUUSD net client exposure up 18% in the last hour — review B-book limit.
MT5 Gateway
- MT5 sessions
- pooled · signed in
- Quotes
- every 250 ms, on change
- Streams
- 6 on one WebSocket
- Breaker
- closed
The terminal above runs a simulated price feed. Watch one on live market data
- 76
- REST routes over MT5
- 6
- realtime streams, one WebSocket
- 250 ms
- quote batching from MT5
- 16
- terminal widgets, desktop and phone
Counted in the OPOTRADE build — gateway in Go, terminal in React.
In short
- To let clients trade on MetaTrader 5 in its own platform, a broker needs two components: an MT5 gateway (backend) and a trading terminal (frontend).
- The MT5 gateway connects the broker's MT5 server to the trading platform and handles order execution, account synchronisation, balances, positions, prices, and the trading API.
- The trading terminal is the interface where clients sign in, watch live prices, monitor balances and positions, and place, modify, or close trades.
- Nima Dorostkar's team builds both — a Go MT5 gateway and a React trading terminal on TradingView charts — and runs them in production for OPOTRADE, Opofinance's trading platform.
- Together the two are what brokers also call a branded web trader on an MT5 REST and WebSocket API: the MetaTrader 5 server stays the trade engine, and clients trade in the broker's own terminal.
Two components
The gateway trades.
The terminal is what clients see.
The MT5 Gateway handles all communication with MetaTrader 5 and the execution of trades. The Trading Terminal is the interface your clients use to work with their accounts. Each needs the other — so we build them as one platform.
01 Backend
MT5 Gateway
Connects the broker's MT5 server to the trading platform. It signs traders in, executes their orders on MT5, keeps accounts, balances, positions, and orders in sync, and streams prices — behind one secure REST and WebSocket API.
- Order execution: market, limit, stop, and stop-limit, with SL/TP
- Account sync: balance, equity, margin, free margin, margin level
- Positions, pending orders, deals, and history
- Live quotes, market depth, and chart history
- Sign-in through the broker's CRM, scoped to the trader's own accounts
02 Frontend
Trading Terminal UI
The screen your clients trade on. They sign in, watch live prices on TradingView charts, see their balance and positions update in real time, and place, modify, or close trades — on desktop and on their phone.
- Watchlist, charts, and market depth with live prices
- Order ticket: market and pending orders, SL/TP, volume presets
- Positions and orders: modify, partial close, close all
- Account summary, history, deals, alerts, and a trading journal
- Your brand, your layout, light and dark themes, mobile app shell
Architecture
From the trader's click
to your MT5 server.
The terminal never talks to MT5. Every request goes through the gateway, which owns the MT5 sessions, checks each request against the signed-in trader, and streams the results back.
- ClientTraderBrowser or phone→ HTTPS · WSS
- Frontend · we buildTrading TerminalReact SPA · TradingView charts→ REST · WebSocket
- Backend · we buildMT5 GatewayGo service · auth, trading, streaming→ Manager Web API
- Trade serverMetaTrader 5The broker's MT5 server→ Gateway API · FIX
- MarketLiquidityLPs and price feeds
01 · Backend · MT5 Gateway
One secure API
over MetaTrader 5.
A Go service on the MT5 Manager Web API. In the OPOTRADE build it exposes 76 REST routes and six realtime streams on one WebSocket endpoint — everything a terminal, an app, or a CRM needs.
API map 76 REST routes
| Area | Routes |
|---|---|
| Sign-in & sessionCRM sign-in exchanged for a short-lived JWT; session restore; logout | 5 |
| TradingSend a trade request, poll its result, rates, margin check, profit calculation | 7 |
| OrdersOpen and historical orders; modify and cancel | 11 |
| PositionsOpen positions with SL/TP, swap, and commission; update and close | 11 |
| Deals & historyDeals, per-fill executions, and account history | 16 |
| Symbols & pricesSymbol specs, last quotes, statistics, market depth, chart history | 12 |
| AccountAccount details and leverage | 4 |
| Terminal dataPrice alerts, saved workspaces, news, and economic calendar | 7 |
| PlatformCapabilities and server time (plus health and readiness checks) | 3 |
- quotes
- bid/ask, statistics, depth — batched every 250 ms, sent only on change
- positions
- open positions with SL/TP, swap, commission — every 3 s
- orders
- pending orders — every 3 s
- account
- balance, equity, margin, trade state — every 3 s
- executions
- every fill, as it happens
- alerts
- price alerts evaluated on the server
- accepted
- MT5 placed or filled it (return codes 10008, 10009, 10010)
- rejected
- MT5 refused it, with the reason in plain language
- unknown
- MT5 timed out (10012) — the terminal reconciles, never retries
- not_submitted
- the gateway stopped it before it reached MT5
The token travels in the WebSocket handshake, never in a URL; every subscription is checked against the trader's own accounts.
MT5 sessions that survive
A pool of authenticated Manager Web API sessions, each pinned to its own keep-alive connection, with pings, automatic re-login with backoff, and a safe replay of read requests after a session drops.
Circuit breaker and request merging
Transport failures open a breaker for 30 seconds instead of piling up on a struggling server; identical reads in flight share one MT5 call. Writes are never merged or retried.
Load that grows with symbols, not users
Identical subscriptions share one topic and one MT5 poll, so MT5 load scales with the number of symbols, not the number of traders. With NATS, one elected poller feeds every replica.
Security by default
Short-lived JWTs, per-account authorisation on every REST call and WebSocket, Redis rate limits, a login lockout, body size limits, an allow-listed CORS policy, and errors redacted so internal addresses never leak.
Nothing internal reaches the client
MT5 groups and other dealer data are stripped before a response leaves the gateway, and batch answers are filtered down to the caller's own accounts.
Built to operate
One static Go binary in a distroless container, roles that split across Kubernetes deployments with autoscaling, health and readiness checks, Prometheus metrics, Grafana dashboards, and graceful shutdown.
Gateway technology
- Go 1.26
- MT5 Manager Web API
- REST · WebSocket
- JWT
- PostgreSQL
- TimescaleDB
- Redis
- NATS
- Prometheus · Grafana
- Docker · Kubernetes
02 · Frontend · Trading Terminal UI
A terminal that keeps up
with the market.
A React and TypeScript single-page app on TradingView's Trading Platform library, fed by the gateway — fast with hundreds of ticks a second, honest when the connection is not.

Ticks without jank
Quotes live in a per-symbol store and fan out at most every 16 ms; a tick in one symbol re-renders nothing else — a test proves it. The watchlist is virtualised and subscribes only to visible rows.
Reconnects that recover state
WebSockets reconnect with jittered backoff, detect stale and half-open sockets, and re-sync by snapshot: subscribe, buffer, fetch, apply. The header shows when data is stale instead of hiding it.
TradingView, wired to MT5
A datafeed serves bars and quotes from the broker's own MT5 feed, and a broker adapter routes chart trading through the same ticket and checks as the order panel — one trading path.
Money is never a float
Prices and balances travel as decimal strings and MT5 ticket ids as strings (they exceed JavaScript's safe integer range). A missing value shows as unavailable, never as 0.
A workspace traders shape
Sixteen dockable widgets, saved layouts, multi-chart grids, a command palette, light and dark themes — and a separate five-tab shell on phones with deep links.
Locked down in the browser
The gateway token lives in memory and never in a URL, a strict Content Security Policy, frame-ancestors denied, HSTS, and an idle sign-out.
Terminal technology
- React 19
- TypeScript 5 (strict)
- Vite
- TradingView Trading Platform
- Zustand
- TanStack Query
- zod
- Tailwind CSS
- Vitest · Playwright
- nginx
Live demo · real market data
The terminal pattern,
on a live feed.
A web terminal of ours on a public exchange feed, working the way the terminal above works with the gateway: history loaded once, then one WebSocket streaming quotes, candles, depth and trades. The prices are real; the account is a demo. In a broker deployment it reads the gateway's streams instead.
- 24h change
- —
- 24h high
- —
- 24h low
- —
| Symbol | Side | Size | Current | P&L | Close | |
|---|---|---|---|---|---|---|
| Connecting to the market… | ||||||
- Balance
- 25,000.00
- Equity
- 25,000.00
- Margin
- 0.00
- Floating P&L
- +0.00
- One connection. A REST call loads the history; a single WebSocket then streams quotes, candles, depth and trades.
- Batched rendering. Updates arrive many times a second and reach the screen four times a second, so the page stays smooth on a phone.
- Connects when seen. The feed opens only while the terminal is on screen and the tab is visible, and reconnects by itself if the stream drops.
One trade, end to end
What happens when
a trader clicks Buy.
Six steps across three systems — and at no point does the screen show a fill MT5 has not confirmed.
Trading Terminal
MT5 Gateway
MetaTrader 5
- 1TerminalThe trader clicks Buy
The ticket checks volume step and minimum, the price grid, and SL/TP against the current price. Confirmation is a dialog whose Confirm button is not focused, so a stray Enter can't trade; one-click trading is opt-in and shows an armed indicator.
- 2Terminal → GatewayOne request, never two
The order goes to the gateway over HTTPS with the trader's JWT. The terminal blocks a second submit, and the gateway accepts an idempotency key, so a double click or a resend can never place the order twice.
- 3GatewayChecked before MT5 sees it
The gateway verifies the account belongs to the token, normalises the request (order type, expiry, SL/TP), and claims the idempotency key in Redis before anything is sent.
- 4Gateway → MT5Executed on the broker's MT5
The request goes to MT5 through a pooled, authenticated Manager Web API session behind a circuit breaker. The gateway polls for the result with a budget and keeps polling in the background if MT5 is slow.
- 5Gateway → TerminalAn honest answer
The MT5 return code becomes one of four outcomes — accepted, rejected, unknown, or not submitted — with a readable message. Nothing shows as filled until MT5 says so.
- 6RealtimeEvery screen agrees
The new position arrives on the positions stream and the account stream updates balance and margin. The terminal replaces its lists from the server's snapshot instead of guessing.
In production
OPOTRADE:
both halves, built by us.
OPOTRADE is the online Forex and CFD trading platform of Opofinance, a broker licensed by the FSCA of South Africa. Nima Dorostkar built its MT5 gateway in Go and its trading terminal in React and TypeScript.
The new gateway replaced an earlier service as a drop-in: same routes, same responses, same realtime contract, so the terminal and other clients moved over without changes — then it added idempotent trading, a circuit breaker, shared MT5 polling, and autoscaling.
The terminal brings sixteen dockable widgets, TradingView charts with trading on the chart, a phone layout, and strict rules: no trade is shown as filled before MT5 confirms it, no trade is retried automatically, and money is never a float.
- 76
- REST routes and 6 realtime streams in the gateway
- 250 ms
- quote batching from MT5, sent only on change
- ~8 MB
- gateway memory at light load, vs ~18 MB for the service it replaced
- < 50 ms
- gateway cold start, one static binary
- 16
- dockable terminal widgets, plus a mobile shell
- ~1,000
- terminal unit tests, plus 82 end-to-end cases
- 345
- Go tests, plus a 139-check suite against a mock MT5
- 3–50
- gateway replicas under autoscaling
Ways to start
Ready-built, customized,
or built to your spec.
- 01Fastest
Deploy both, under your brand
We deploy the gateway and terminal on your servers, connect them to your MT5 server and CRM, and apply your brand, symbols, and account types.
- 02Most common
Deploy, then customize
Start from the running platform and add what makes yours different: your own widgets, order flows, risk rules, funding and KYC inside the terminal.
- 03Your spec
Build one half, or both, new
Need only the gateway behind your own apps, or a terminal on your existing backend? We build either half to your spec — the source code is yours.
Questions
MT5 gateway & trading terminal FAQ
What does a broker need to let clients trade on MT5 in its own terminal?
Two components. An MT5 gateway (the backend) connects the broker's MetaTrader 5 server to the trading platform and handles order execution, account synchronisation, balances, positions, prices, and the trading API. A trading terminal (the frontend) is the interface where clients sign in, watch live prices, monitor balances and positions, and place, modify, or close trades. The gateway handles communication with MT5 and execution; the terminal is how traders use their accounts.
Why not connect the trading terminal to MT5 directly?
A browser should never hold MT5 manager credentials or talk to the trade server. The gateway keeps MT5 private, checks that every request belongs to the signed-in trader, limits request rates, hides dealer data such as MT5 groups, and turns MT5 return codes into clear outcomes. It also shares one MT5 poll between all traders watching the same symbol, so the server's load does not grow with every open terminal.
Which MT5 API does the gateway use?
The trader-facing gateway uses the MT5 Manager Web API over HTTPS, with a pool of authenticated sessions, automatic re-login, and a circuit breaker. Connecting MT5 to liquidity providers is a different job, done with the MT5 Gateway API and FIX — see the MT5 gateway development page and the MT5 API guide.
Can you customize the terminal for our brokerage?
Yes. Branding, layouts, widgets, order types, risk checks, translations, and funding or KYC flows inside the terminal are all changeable, and the source code is yours. Most brokers start from the running platform and customize it; some have us build the terminal on their own backend.
Do we need a TradingView licence?
For the full TradingView chart with trading on the chart, yes: the terminal uses TradingView's Trading Platform library, which TradingView licenses to the broker. The chart's bars and quotes come from your own MT5 feed, not from TradingView's market data.
What do we need on the MT5 side?
A MetaTrader 5 server (your own or a white label) with a manager account that has Manager Web API access, and the CRM or client portal your traders sign in with. Your MT5 server, groups, and accounts stay as they are.
How long does it take?
Deploying the existing gateway and terminal under your brand is the fastest route. Custom work on either half typically takes 2–4 months, like any focused component, including tests against a staging MT5 server and a monitored launch.
Can our own apps use the gateway's REST and WebSocket API?
Yes. The gateway's API is not tied to the terminal: a mobile app, a client portal, a copy trading engine, or an AI assistant can use the same REST routes and WebSocket streams, each with its own permissions. In the OPOTRADE build that is 76 REST routes in nine areas and six realtime streams over one WebSocket.
Does this replace the MetaTrader 5 web platform and mobile apps?
No, it runs beside them. The gateway works with your MT5 server through a manager account, so nothing changes for clients who trade in MetaQuotes' own terminals: MetaTrader 5 on desktop, on mobile, and in the browser keeps working on the same accounts. The trading terminal is an additional way in under your brand, and the place for what MetaQuotes' terminals do not have: your own widgets, order flows, and funding.
Can we take only the MT5 gateway, or only the trading terminal?
Yes. Some brokers need only the gateway, behind apps they already have; others want the terminal on a backend they already run. Each half is built and deployed on its own, and the source code is yours.
Start a project
Get your own MT5 gateway
and trading terminal.
Tell us about your MT5 server, your CRM, and what your traders need. You'll hear back from the engineer who built OPOTRADE, with questions, an architecture, and a realistic timeline.