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 — each in Python, Node.js and curl, against a demo account.

The fxapis team2 min read

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
  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 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. 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-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

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 articles
> 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.