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

Published 2026-10-08 by fxapis. Canonical: https://fxapis.com/blog/mt5-api-examples-python-node-curl

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

The fastest way to see how the fxapis MetaTrader 5 API behaves is to run it. [fxapis-examples](https://github.com/FXapis/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.

| | 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](https://fxapis.com/blog/mt5-api-python-sdk), [TypeScript](https://fxapis.com/blog/mt5-api-typescript-sdk)); 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](https://fxapis.com/dashboard/keys).
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](https://docs.fxapis.com/guides/connect-accounts) helps if you are unsure.
3. Clone the repository, copy `.env.example` to `.env`, fill it in, and export it.

```bash
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:

```bash
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](https://docs.fxapis.com/signals):

- **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](https://docs.fxapis.com/guides/copy-trading) 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

- [SDKs and examples](https://docs.fxapis.com/sdks) and the [quickstart](https://docs.fxapis.com/quickstart) in the docs.
- [Multi-account orders](https://docs.fxapis.com/guides/multi-account-orders) for everything the copier's fan-out can do: per-account volumes, release times and barrier policies.
- The [Next.js starter](https://fxapis.com/blog/nextjs-mt5-trading-dashboard-starter) when you want a working app rather than a script.

## Questions

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