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) in Python, Node.js and curl, on a demo account.
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 (Exness, IC Markets, Pepperstone, XM or another) 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. It polls, so it runs with no public server; on a server, position.opened and position.closed webhooks can replace the loop. Each pass 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.
- Connect Claude and ChatGPT to MetaTrader 5 when you want an AI assistant or agent to call the API for you.