Runnable MT5 API Examples in Python, Node.js and curl
Three runnable fxapis examples — a quickstart, click-to-trade for signal providers and a trade copier — each in Python, Node.js and curl, against a demo account.
In short
- fxapis-examples is three programs — a quickstart, click-to-trade and a trade copier — each in Python, Node.js/TypeScript and curl.
- Every example runs against a broker demo account with an API key and a .env file; nothing is simulated.
- Click-to-trade shows the signal-provider pattern: prepare the account when a member opens the signal, then one keyed order when they approve.
- The copier polls a master account's deals and mirrors each one to every follower in a single multi-account order.
On this page
The fastest way to see how the fxapis MetaTrader 5 API behaves is to run it. fxapis-examples holds three small programs, each in Python, Node.js/TypeScript and curl, that run against a real broker demo account: a quickstart, click-to-trade for signal providers, and a trade copier.
| Aspect | Python | Node.js / TypeScript | curl |
|---|---|---|---|
| Quickstart | python/quickstart.py | node/quickstart.ts | curl/quickstart.sh |
| Click-to-trade | python/click_to_trade.py | node/click-to-trade.ts | curl/click-to-trade.sh |
| Copy trader | python/copy_trader.py | node/copy-trader.ts | curl/multi-account-order.sh |
The Python and Node.js versions use the official SDKs (Python, TypeScript); the curl versions show the raw HTTP requests, which is useful when you are calling the API from another language.
Set it up once
- Create an API key in the console.
- Open a demo MT5 account with any broker and note its login, trading password and server name, exactly as MetaTrader shows it. Connecting accounts helps if you are unsure.
- Clone the repository, copy
.env.exampleto.env, fill it in, and export it.
git clone https://github.com/FXapis/fxapis-examples.git && cd fxapis-examples
cp .env.example .env # your key, login, password and server
set -a; . ./.env; set +a
Then pick a language:
cd python && pip install -r requirements.txt && python quickstart.py
cd node && npm install && node quickstart.ts # Node 22.18+ runs TypeScript directly
cd curl && ./quickstart.sh # needs curl and jq
The quickstart
It connects the account in warm_on_demand mode, brings it online and polls its status until ready — about ten seconds for a typical broker — then reads the account and a margin calculation, places a 0.01-lot market order and closes the position it opened. It is the whole lifecycle in one file, and the best place to start reading.
Click-to-trade for signal providers
For an app where each member approves a signal with a tap, on their own MT5 account, the example follows the pattern from the signals guide:
- Check the credentials when the member connects, by bringing the account online at once — a wrong password is caught on the connect screen, not on the first trade.
- Prepare on view. When a member opens a signal,
POST /v1/accounts/preparebrings their account online, so by the time they tap approve the order goes straight through. - One order per signal and member. The idempotency key is the signal id plus the member id, so a double tap or a retry returns the first answer and never opens a second position.
- Handle every outcome: filled, rejected (show the reason), unresolved (never resend — poll the order), and not sent (retry with the same key).
The trade copier
The copier watches a master account and mirrors its trades onto followers. There are no event webhooks yet, so it polls: it reconciles the master, reads its new deals, and sends each opening deal to every follower as one multi-account order, with the master deal id in the idempotency key so a restart never copies a deal twice. When the master closes, the followers' copies are closed. It is kept deliberately small — buys, sells and full closes — as a starting point, and the copy-trading guide goes further.
The rules every example follows
- An
Idempotency-Keyon every order and close. ORDER_UNRESOLVEDis never resent;SEND_FAILEDandACCOUNT_NOT_READYare resent with the same key.- Volumes and prices are strings, and stops are absolute prices.
- The API key stays on the backend.
Where to go next
- SDKs and examples and the quickstart in the docs.
- Multi-account orders for everything the copier's fan-out can do: per-account volumes, release times and barrier policies.
- The Next.js starter when you want a working app rather than a script.