Orders and reliability

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.

The fxapis team2 min read

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
  1. A test key is not a sandbox
  2. Step 1: connect a demo account
  3. Step 2: read before you write
  4. Step 3: place the smallest order
  5. Step 4: check what came back
  6. Step 5: test the failures on purpose
  7. Going live
  8. Next steps

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

  • state should be filled, with a filledPrice and the broker's own order number.
  • GET /v1/accounts/{id}/positions should 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:

TryExpect
An order when the market is closed (a weekend, for forex)ORDER_REJECTED, not retryable
A volume far above the account's marginORDER_REJECTED for insufficient margin
The same request twice with the same Idempotency-KeyThe first response, replayed — one position
A typo in the server nameThe 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.
FAQ

Questions people also ask

Does fxapis have a sandbox?

No. There is no simulated market. Every key, including fx_test_ keys, reaches real broker servers. To test without risk, connect demo accounts from your broker.

Where do I get an MT5 demo account?

From your broker. Most brokers offer free MetaTrader 5 demo accounts from their website or from inside MetaTrader. Note the login, password and the demo server name they give you.

Can I test for free?

While fxapis offers its Free plan, it includes one MT5 account and 100 market orders a month with no card, which is enough to connect a demo account and test market orders end to end.

Is a demo account exactly like a live one?

Close, not identical. Demo servers use real prices, but fills, slippage and some rules can differ from the broker's live servers. Test your integration on demo, then go live with small sizes.

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.