Building with fxapis

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.

Updated 3 min readLeer en español
On this page
  1. Set it up once
  2. The quickstart
  3. Click-to-trade for signal providers
  4. The trade copier
  5. The rules every example follows
  6. Where to go next

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.

AspectPythonNode.js / TypeScriptcurl
Quickstartpython/quickstart.pynode/quickstart.tscurl/quickstart.sh
Click-to-tradepython/click_to_trade.pynode/click-to-trade.tscurl/click-to-trade.sh
Copy traderpython/copy_trader.pynode/copy-trader.tscurl/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

  1. Create an API key in the console.
  2. 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.
  3. Clone the repository, copy .env.example to .env, fill it in, and export it.
cURL
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:

cURL
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/prepare brings 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-Key on every order and close.
  • ORDER_UNRESOLVED is never resent; SEND_FAILED and ACCOUNT_NOT_READY are 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

— Software architect and AI engineer with more than 15 years of building and scaling software systems. Designs and builds production-grade software and AI systems, and writes about how it's done.

elwizard.netGitHubInstagram

FAQ

Questions people also ask

Do the examples place real orders?

Yes — on whatever account you connect. Every fxapis key reaches a real broker, so run them against a broker demo account.

Which languages are covered?

Python and Node.js/TypeScript on the official SDKs, and curl with jq for the raw HTTP requests.

Is the copy trader production-ready?

No, deliberately: it copies buys and sells and full closes, and keeps its state in a file. It is a starting point that shows the pattern — polling deals, one multi-account order per master deal, keys per deal.

All in this topic
Building with fxapis

n8n and Postman Templates for the MT5 API

Explore the fxapis MT5 API in Postman and automate MT5 trades with n8n workflows: ready-made templates from fxapis-integrations, with demo accounts first.

2 min read
> Connect. Execute. Scale.

Trade MT5 from your own code.

Connect accounts by login, password and server, and place orders over HTTPS. We run MetaTrader 5; you install nothing.