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.

Updated 2 min readLeer en español
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. MetaTrader 5's help, Open an Account, puts it plainly: on a demo account "all trading operations only involve virtual money".

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, with the server name exactly as MetaTrader shows it (for example Exness-MT5Trial8, ICMarketsSC-Demo or Pepperstone-Demo — fxapis works with any MT5 broker):

cURL
curl -X POST https://api.fxapis.com/v1/accounts \
  -H "Authorization: Bearer $FXAPIS_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "login": "26177561", "server": "YourBroker-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

— 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

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?

Yes, with a 14-day free trial of the plan you pick: that plan's features and limits on demo accounts (up to 5; Personal's trial has 2), with no card. At the end you pay for the plan or stop; there is no free plan.

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 in this topic
Orders and reliability

Market Orders vs Pending Orders in an MT5 API

A market order trades now; a pending order waits at the broker for your price. How each behaves in an MT5 API, with one example and a comparison table.

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.