# MetaTrader REST API. Any broker, no VPS.

Source: https://pipsocket.com/metatrader-rest-api

Connect a MetaTrader login and trade it over HTTPS. Place orders, read positions and history, and flatten the account, from any language that can make a request.

$15 per account, per month. MT5 today, MT4 next.

- [Get an API key](https://app.pipsocket.com)
- [Read the quickstart](https://docs.pipsocket.com/quickstart)

## Place an order

cURL:

```bash
curl https://api.pipsocket.com/v1/accounts/$ACCOUNT/orders \
    -H "Authorization: Bearer $PIPSOCKET_KEY" \
    -H "Idempotency-Key: $(uuidgen)" \
    -H "Content-Type: application/json" \
    -d '{ "symbol": "EURUSD", "type": "buy",
          "volume": 0.10, "type_filling": "ioc" }'
```

Python:

```python
import os, uuid, requests

response = requests.post(
    f"https://api.pipsocket.com/v1/accounts/{os.environ['ACCOUNT']}/orders",
    headers={
        "Authorization": f"Bearer {os.environ['PIPSOCKET_KEY']}",
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json={"symbol": "EURUSD", "type": "buy", "volume": 0.10, "type_filling": "ioc"},
)
print(response.status_code, response.json()["state"])
```

Node:

```js
const response = await fetch(`https://api.pipsocket.com/v1/accounts/${process.env.ACCOUNT}/orders`, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.PIPSOCKET_KEY}`,
    "Idempotency-Key": crypto.randomUUID(),
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ symbol: "EURUSD", type: "buy", volume: 0.1, type_filling: "ioc" }),
})
console.log(response.status, (await response.json()).state)
```

The answer, `200 OK` (shortened):

```json
{
  "request": "req_5f0c2a9e41d7b3a8c6e2f190",
  "state": "done",
  "result": {
    "retcode": 10009,
    "retcode_name": "TRADE_RETCODE_DONE",
    "deal": 771203455,
    "volume": 0.1,
    "price": 1.08412
  }
}
```

## How a call behaves

- **One call, one MT5 request.** Sent once, exactly as you wrote it. No splitting, rounding or hidden retries.
- **MT5's answer, as it is.** A fill or a rejection comes back with the broker's own retcode.
- **Five seconds for the broker.** No answer by then and you get a request id to look up. It is never resent.
- **Safe to retry.** Send an Idempotency-Key and a repeat returns the first order instead of trading twice.

## Everything the terminal does, as an endpoint.

Every field maps to its MT5 field, so what you know about MqlTradeRequest still applies. One base URL for every account: `https://api.pipsocket.com/v1/accounts/{account}`. Paths below are relative to it.

### Orders

- `POST /orders`: a market or pending order, sent once
- `POST /orders/check`: MT5's dry run, with the margin it needs
- `POST /positions/{ticket}/close`: close all or part of a position
- `GET /requests/{request}`: a trade request and the broker's answer

### Account data and control

- `GET /`: status, balance, equity and margin
- `GET /positions`: open positions, read fresh from the terminal
- `GET /history/deals`: deals and past orders in a time range
- `GET /symbols/{symbol}/tick`: the broker's latest price for a symbol
- `POST /kill-switch`: block new orders, then try to close everything

Full API reference: https://docs.pipsocket.com/api/place-an-order (every docs page as Markdown: https://docs.pipsocket.com/llms.txt).

## From MetaTrader login to first order. Three steps, no Windows.

### Connect your MT5 login

Server, login and password, from any MT5 broker. Your terminal starts next to your broker's trade server and stays on.

### Make your API key

One key for your workspace, shown once. Keep it on your server and roll it whenever you like.

### Send your first order

Python, Node, Go, a spreadsheet script. If it can make an HTTPS request, it can trade.

## Why not a bridge EA on your own VPS?

|                      | Bridge EA on a VPS                                          | Pipsocket REST API                                                            |
| -------------------- | ----------------------------------------------------------- | ----------------------------------------------------------------------------- |
| Hosting              | A Windows VPS to rent, patch and log into                   | Nothing to host. We run the MT5 terminal.                                     |
| When it hangs at 3am | Nobody notices until the morning                            | Restarted and reconnected to your broker automatically                        |
| Order behaviour      | Whatever the EA's author decided, often with silent retries | One MT5 request per call, idempotent, with the broker's retcode               |
| Security             | A port open on the VPS for your bot to reach                | No open ports. Terminals dial out, and your key is checked for every account. |
| More accounts        | Another terminal, another EA install, another config        | Connect it in the dashboard. Same API, new account id.                        |

## MetaTrader REST API questions

### Does MetaTrader 5 have a REST API?

Not for traders. MetaQuotes' Python package needs a Windows terminal running on the same machine. Pipsocket runs that terminal for you and puts an HTTPS API in front of it.

### Does it work with my broker?

If your broker gives you an MT5 login, yes. You keep your broker and your account. Symbol names are the broker's own, so EURUSD on one can be EURUSD.r on another.

### Can I use it with a prop firm account?

If the firm gives you an MT5 login, it connects like any other. Check your firm's rules on automated trading before you point a bot at it.

### Is MT4 supported?

Not yet. MT5 is live today and MT4 is next.

### What does it cost?

$15 per account, per month. REST, WebSocket, TradingView alerts, MCP and the kill switch are all included. No per-trade fees.

## The same account, other ways in

- [MetaTrader WebSocket API](https://pipsocket.com/metatrader-websocket-api.md) (`wss://wss.pipsocket.com`): ticks, fills and deals pushed as they happen.
- [TradingView to MetaTrader](https://pipsocket.com/tradingview-to-metatrader.md) (`hooks.pipsocket.com`): turn alerts into orders on every account you pick.
- [MetaTrader MCP server](https://pipsocket.com/metatrader-mcp-server.md) (`mcp.pipsocket.com`): let Claude or any agent read and trade your account.
