MetaTrader®, MT4® and MT5® are trademarks of MetaQuotes Ltd. This is an independent service and is not affiliated with, authorized by, or endorsed by MetaQuotes.

Guides · 8 min read · 2026-06-09

How to Migrate from MetaApi to MetaTrader API Without Rebuilding Your Whole App

By MetaTrader API Editorial Team

How to Migrate from MetaApi to MetaTrader API Without Rebuilding Your Whole App

Step-by-step guide to migrating from MetaApi to MetaTrader API: map endpoints, handle authentication and switch your WebSockets smoothly.

When SaaS founders and developers realize they need to migrate from MetaApi—often due to high scaling costs or latency issues—their first fear is that they will have to rip out their entire backend architecture and start from scratch.

Fortunately, if you are looking to replace MetaApi with a plain REST and WebSocket API like MetaTrader API, the core logic of your application remains exactly the same. Your database, your UI, and your trading algorithms don't change. You only need to update the data-transport layer.

In this developer guide, we will walk you through a practical MetaApi migration. We cover exactly what you need before you start, how to map your endpoints, and a testing checklist to ensure your app transitions smoothly.


1. What You Need Before Migration

Before you update any code to switch from MetaApi, ensure you have the following prerequisites ready:


2. Authentication Changes: Provisioning vs Connecting

The biggest architectural difference you will encounter during a MetaApi alternative migration is how accounts are authenticated.

How to map it in your code: Wherever you previously called the MetaApi provisioning SDK, replace it with one GET /ConnectEx request (query parameters, authenticated with your management key or a full-access API key). wait is in seconds; keep it at 60 or less and poll /ConnectState?id= if the account is not ACTIVE yet.

curl -G "https://api.metatraderapi.net/ConnectEx" \
  -H "Authorization: Bearer $MTAPI_MGMT_KEY" \
  --data-urlencode "user=123456" \
  --data-urlencode "password=broker_main_password" \
  --data-urlencode "server=Broker-Server-Live" \
  --data-urlencode "platform=MT5" \
  --data-urlencode "wait=60"
{"id": "7f123497-63b2-496d-864d-cf3657f73b1f", "status": "ACTIVE", "connected": true, "statusReason": null, "apiKey": "mt5api_...", "apiKeyId": "fd41e389-2fd9-44fc-86e3-06fe13f775c1", "platform": "MT5", "brokerServer": "Broker-Server-Live", "note": "..."}

Store the id and the apiKey (it is shown only in this response). You pass the id as ?id= and the key as the x-api-key header on all subsequent API calls. Because /ConnectEx carries the password in the URL, a backend should prefer POST /v1/seats with a JSON body.


3. Order Placement Differences

Executing a trade remains a straightforward REST call, and the parameters follow MetaTrader's own order model.

How to map it in your code: Replace your old trade execution function with a GET /OrderSend request; every parameter goes in the query string.

operation takes the names Buy, Sell, BuyLimit, SellLimit, BuyStop, SellStop (and the MT5-only stop-limit types), or the standard MetaTrader codes (0 = Buy, 1 = Sell, 2 = Buy Limit, ...). Market orders need no price.

curl -s -H "x-api-key: $MTAPI_KEY" \
  "https://api.metatraderapi.net/OrderSend?id=$MTAPI_ID&symbol=EURUSD&operation=Buy&volume=0.1&slippage=3&stoploss=1.0850&takeprofit=1.0950&expertId=999111&comment=SaaS_Trade&clientOrderId=saas-trade-000123"

The response is an order object: ticket, symbol, orderType, lots, volume (lots × 10,000), openPrice, state, openTimestampUTC and more. A broker refusal is HTTP 200 with state other than 10009, so check state instead of the status code. The clientOrderId makes the call safe to retry: the same id never opens a second order.


4. WebSocket / Streaming Changes

If your app relies on real-time copy trading or instant dashboard updates, you are likely streaming data rather than polling.

How to map it in your code: You no longer need a heavy SDK. You can use standard WebSocket libraries (like ws in Node.js or websockets in Python).

Simply connect one WebSocket per account, wss://api.metatraderapi.net/v1/stream?id=YOUR_ACCOUNT_ID, with your key in the x-api-key header. Every frame is {"type": "...", "data": {...}}:

When an order opens, closes, or hits a stop loss, a TRADE frame with the deal (symbol, type, entry, volume, price, profit, magic) reaches your backend, usually within about a second, followed by the updated POSITIONS list.

(For a deep dive into building a full streaming architecture, read our guide on How to Build a Copy Trading Platform).


5. Testing Checklist for Your Migration

Before you push your MetaApi migration to production, run through this final checklist on your staging server:

  1. Authentication Loop: Does your app store the account id returned by /ConnectEx (or POST /v1/seats) and reuse it? The id is permanent: if the broker connection drops (e.g., weekend server maintenance), it is restored automatically, requests answer 503 meanwhile, and your code should retry reads rather than connect the account again.
  2. Load Check: Execute 30 parallel trades on a demo account using /OrderSend (the limit is a burst of 40 requests, then 20 per second, per API key). Verify that your backend handles the volume and that a 429 is retried after Retry-After.
  3. Socket Reconnection: Force-close your /v1/stream WebSocket and ensure your app automatically reconnects, subscribes to its symbols again, and syncs missed state from the POSITIONS snapshot (MT5; on MT4 read /OpenedOrders) plus /OrderHistory for the gap.
  4. Dependency cleanup: Ensure you have completely removed the old proprietary SDK dependencies from your package.json or requirements.txt to reduce your app's footprint.

Need Help With Your Migration?

If you are managing a large user base and want to ensure zero downtime during your transition, you don't have to do it alone.

Already using MetaApi and considering a switch?
👉 Contact MetaTrader API Support and our engineers will check your current setup, answer your architectural questions, and help you determine exactly how your backend can be migrated.


Ready to integrate the MetaTrader API?

REST, WebSocket and gRPC for MT4 and MT5. Pay per connected account.

Create account