Skip to content
Getting started

How to connect an MT4 account to a REST API

Connect an MT4 demo account, create a scoped API key and read broker quotes with curl. Understand account IDs, permissions and the demo trial.

Start with one account and one read

An MT4 REST API lets your application request account information and market data over HTTPS. MetaBridgeAPI connects to the broker account you supply, then exposes account data, order operations and streams through authenticated endpoints. It is useful for reporting tools, dashboards and other software that needs to work with MetaTrader accounts.

This walkthrough starts with a broker demo account and a read-only quote request. That gives you a small, repeatable check of the connection, account access and API key before adding more features. You can first run the same kind of request in the console without writing code. The MT4 API overview describes the platform’s supported features.

1. Use the details from your MT4 account

Create your MetaBridgeAPI account, confirm your email and create a workspace. In Trading accounts, choose MT4 and enter the broker login, exact server name and trading password. A broker’s website password is a different credential. An MT5 account also needs the MT5 platform selection, even if the broker or server names look similar.

  • Copy the server label from the account’s MetaTrader login details. Do not substitute the broker’s homepage address.
  • Keep the broker login as its full number. The API represents broker logins as strings to preserve precision.
  • If you use advanced connection setup, supply the broker address and port provided for that account.
  • Save the account, then select Connect. Saving credentials creates an account record; connecting verifies access at the broker.

Once connected, open Explore data and inspect Details. The workspace UUID and account UUID shown in the console identify resources in MetaBridgeAPI. Your broker login identifies the account at the broker. Use the two UUIDs in API URLs; a broker login number cannot replace either of them.

2. Activate access and choose a broker symbol

In Billing, activate the 14-day trial for one connected, broker-confirmed demo account. The trial begins when activated. Each owner can use one trial, and reconnecting the account or creating another workspace does not restart it. Paid plans cover the selected demo or live accounts. A connected account and an account with active API access are separate requirements.

In Explore data, open Symbols and copy an exact name from your broker’s list. A broker may use a suffix, so EURUSD and EURUSDm are not interchangeable. Open Quote, paste the selected symbol and inspect bid, ask and timestamp. This console test uses your signed-in session. A separate API key test checks the permissions your application will use.

3. Create a key for the account you need

Open API keys, give the integration a name and select accounts:read and market:read. Select this account explicitly and set an expiry if appropriate. Leaving account selection empty allows access to all accounts in the workspace, subject to the key’s permissions. For this walkthrough, a key restricted to the demo account is sufficient.

Copy the complete key when it is first displayed and store it in your server’s secret store. Supply it to your process through METABRIDGE_API_KEY. Also set METABRIDGE_WORKSPACE_ID, METABRIDGE_ACCOUNT_ID and METABRIDGE_SYMBOL using the values from the console. Keep keys out of public frontend code, source control, URLs and application logs.

4. Read the account and request a quote

With those environment variables set, run these read-only requests. The Authorization header uses Bearer followed by your API key. The first request checks account information; the second URL-encodes the broker symbol and requests its quote.

bash
BASE_URL='https://metabridgeapi.com/api/v1'
ACCOUNT_URL="$BASE_URL/organizations/$METABRIDGE_WORKSPACE_ID/accounts/$METABRIDGE_ACCOUNT_ID"

curl --fail-with-body --silent --show-error \
  --header "Authorization: Bearer $METABRIDGE_API_KEY" \
  "$ACCOUNT_URL/summary"

curl --fail-with-body --silent --show-error --get \
  --header "Authorization: Bearer $METABRIDGE_API_KEY" \
  --data-urlencode "symbol=$METABRIDGE_SYMBOL" \
  "$ACCOUNT_URL/quote"

Successful reads return a JSON object containing data. A quote includes symbol, bid, ask and time. Check the timestamp before using a value as current market data. HTTP errors carry an error object with a request ID; retain that ID for troubleshooting without logging your Authorization header.

Build on the verified connection

A 401 response points to authentication, 403 to permissions or account access, 402 to the selected account’s billing access, and 409 can indicate that the account is not connected. Use the connection troubleshooting guide to narrow the cause before changing credentials repeatedly.

From here, add the reads your application needs. Quote streaming requires streams:read and an HTTP client that supports server-sent events. Trading uses separate permissions and request bodies; an accepted operation must be checked for its broker outcome. The API guide documents routes and permissions, and the console playground lets you inspect real responses before implementing each next step.

Keep building.

All guides ↗