How to Test an MT5 API Without Risking Real Money
Test an MT5 trading API safely: connect a broker demo account, read from it, place a small demo order and check the result. A test key alone is no sandbox.
In short
- Test with a broker demo account: real prices and real broker behaviour, with play money.
- fxapis has no simulated market. A key labelled test still reaches real brokers — what makes a test safe is the account, not the key.
- Work up in four steps: connect the demo account, read from it, place the smallest order, and check what came back.
- Then test the failures on purpose: a closed market, a too-large volume, a double click.
On this page
You can build and test a whole MT5 integration without putting a cent at risk — if you test with the right thing. The safety comes from the account, not the API key. Use a broker demo account, and work up from reading to trading.
A test key is not a sandbox
Many APIs have a sandbox: test keys that hit a fake market. fxapis does not. Keys are labelled fx_live_ and fx_test_ so you can tell configurations apart, but both reach real brokers. A test key connected to a real-money account places real trades.
Brokers already run the best sandbox there is: demo accounts. They trade on real prices with play money, on servers built for the purpose.
Step 1: connect a demo account
Open a free MT5 demo account with your broker and note three things: the login, the password, and the demo server name — usually ending in -Demo. Then connect it:
curl -X POST https://api.fxapis.com/v1/accounts \
-H "Authorization: Bearer $FXAPIS_KEY" \
-H "Content-Type: application/json" \
-d '{ "login": "26177561", "server": "VantageMarkets-Demo",
"password": "the-demo-password", "mode": "warm_on_demand",
"label": "demo" }'
Bring it online with POST /v1/accounts/{id}/warm and poll GET /v1/accounts/{id}/status until the state is ready — about 10 seconds in our measurements. If it lands in invalid_credentials, check the server name first.
Step 2: read before you write
Make requests that cannot change anything:
curl https://api.fxapis.com/v1/accounts/$ACCOUNT_ID/positions -H "Authorization: Bearer $FXAPIS_KEY"
curl "https://api.fxapis.com/v1/accounts/$ACCOUNT_ID/symbols?search=EURUSD" -H "Authorization: Bearer $FXAPIS_KEY"
The second shows how your broker names the symbol and its volume rules (volumeMin, volumeStep). If you want to know an order will pass the margin check, POST /v1/accounts/{id}/calculate answers without opening anything.
Step 3: place the smallest order
Send the minimum volume, with an idempotency key:
curl -X POST https://api.fxapis.com/v1/accounts/$ACCOUNT_ID/orders/market \
-H "Authorization: Bearer $FXAPIS_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{ "symbol": "EURUSD", "side": "buy", "volume": "0.01" }'
Note that the volume is a string, "0.01" — fxapis refuses JSON numbers so no size is rounded on the way.
Step 4: check what came back
Do not stop at a 201. Read the result:
stateshould befilled, with afilledPriceand the broker's own order number.GET /v1/accounts/{id}/positionsshould now show the position.- Close it with
POST /v1/accounts/{id}/positions/{ticket}/close, again with an idempotency key, and check the position has gone.
Compare against what MetaTrader shows for the demo account. Your integration is working when the two agree.
Step 5: test the failures on purpose
The happy path is the easy part. On the demo account, try:
| Try | Expect |
|---|---|
| An order when the market is closed (a weekend, for forex) | ORDER_REJECTED, not retryable |
| A volume far above the account's margin | ORDER_REJECTED for insufficient margin |
The same request twice with the same Idempotency-Key | The first response, replayed — one position |
| A typo in the server name | The account in invalid_credentials |
Each failure should end where your code expects it to. The errors reference lists every code and whether to retry.
Going live
When the demo behaves, connect a live account and start with the smallest sizes. Keep separate keys for test and live configurations — the label makes a test key in production easy to spot — and keep the demo account for regression tests.
Next steps
- Quickstart — the same steps with Python and Node.js samples.
- Why an MT5 trade can fail — reading a rejection.
- Create your key and connect your first demo account.