Skip to content

A MetaTrader 5 historical data API for candles and trade history

Updated 2026-11-22

FiveSocket returns historical candles, deals and orders from any MT5 broker account over HTTPS. Call GET https://api.fivesocket.com/v1/accounts/{accountId}/candles for OHLC bars, and the deals, orders and history export endpoints for trade history. The data comes from your broker's own MT5 server through a terminal that FiveSocket hosts, so you run no Windows machine and no MT5 terminal.

7-day free trial. Paid plans start at $9.99 a month. See pricing

What you can read

  • Candles: completed OHLC bars for a symbol on M1, M5, M15, H1, H4 or D1, with tick volume, real volume and spread.
  • Deals: the raw MT5 deals for a time window, including commission and swap.
  • Historical orders: the orders for a time window, filled or cancelled.
  • History export: the full deal or order history of an account, as one certified export.

Prices and bar times come from the broker. There is no external price feed, and FiveSocket calculates no indicators and resamples nothing.

Everything is plain JSON over HTTPS with a Bearer API key that has the data:read scope. Link the account once, then call it from any language. Read about the MT5 REST API

Get the last 200 H1 candles

Pass the symbol name exactly as your broker spells it, a timeframe, and a count of recent completed bars from 1 to 1,000. The bars come back oldest first, with prices as decimal strings.

curl -G -H "Authorization: Bearer $FIVESOCKET_KEY" \
  --data-urlencode "symbol=EURUSD" \
  --data-urlencode "timeframe=H1" \
  --data-urlencode "count=200" \
  https://api.fivesocket.com/v1/accounts/acc_7Hq2Xv/candles

A symbol the account does not have returns 404 with the code symbol_not_found and up to five suggested names, such as XAUUSDm for XAUUSD. Retry with one of the suggestions.

Page through a date range

For a longer span, send from and to as UTC times instead of count, with an optional limit from 1 to 1,000 that defaults to 200. Count and a from and to range cannot be combined. A range selects bars by open time in [from, to). Each response carries nextTo. Keep everything else the same, replace to with nextTo, and stop when it is null.

import os
import time
import requests

url = "https://api.fivesocket.com/v1/accounts/acc_7Hq2Xv/candles"
headers = {"Authorization": f"Bearer {os.environ['FIVESOCKET_KEY']}"}
params = {
    "symbol": "EURUSD",
    "timeframe": "H1",
    "from": "2026-10-01T00:00:00Z",
    "to": "2026-11-01T00:00:00Z",
    "limit": 1000,
}

bars = []
while True:
    response = requests.get(url, headers=headers, params=params, timeout=60)
    if response.status_code == 503:
        time.sleep(int(response.headers.get("Retry-After", "5")))
        continue
    response.raise_for_status()
    page = response.json()
    bars = page["data"] + bars
    if page["nextTo"] is None:
        break
    params["to"] = page["nextTo"]

print(len(bars), bars[0]["openTime"], bars[-1]["close"])

A 503 with the code candle_history_unavailable and a Retry-After header means the terminal has not loaded that history yet. It is typically brief after a session wakes up or a bar closes. Wait the number of seconds given and send the same request again.

Read deals and orders for a window

The deals and orders endpoints take a time window of at most 90 days per request. The first request must give an explicit to time. Each response includes nextCursor, and you send it back as the cursor parameter to get the next page. The cursor carries the original window, so leave from and to out of those later requests.

  • GET https://api.fivesocket.com/v1/accounts/{accountId}/deals?from=...&to=...
  • GET https://api.fivesocket.com/v1/accounts/{accountId}/orders?from=...&to=...

Add requireSynced=true to a windowed read when you need a complete window. The response then comes back only after the window has been confirmed, and otherwise returns 503 history_unsettled with Retry-After.

Export your full trade history

To get an account's whole history in one pass, call the export endpoint with dataset set to deals or orders. It is always a complete, certified read, so the first request can return 503 history_unsettled with a Retry-After header and an exportToken in the error details. Wait, then repeat the request with the exportToken. Once pages arrive, follow nextCursor until it is null.

curl -G -H "Authorization: Bearer $FIVESOCKET_KEY" \
  --data-urlencode "dataset=deals" \
  --data-urlencode "limit=1000" \
  https://api.fivesocket.com/v1/accounts/acc_7Hq2Xv/history/export
import os
import time
import requests

url = "https://api.fivesocket.com/v1/accounts/acc_7Hq2Xv/history/export"
headers = {"Authorization": f"Bearer {os.environ['FIVESOCKET_KEY']}"}
base = {"dataset": "deals", "limit": 1000}

rows = []
cursor = None
token = None
while True:
    params = {**base}
    if cursor:
        params["cursor"] = cursor
    elif token:
        params["exportToken"] = token
    response = requests.get(url, headers=headers, params=params, timeout=120)
    if response.status_code == 503:
        token = response.json()["error"].get("details", {}).get("exportToken", token)
        time.sleep(int(response.headers.get("Retry-After", "5")))
        continue
    if response.status_code == 410:
        rows, cursor = [], None
        continue
    response.raise_for_status()
    page = response.json()
    rows += page["data"]
    cursor = page["nextCursor"]
    if cursor is None:
        break

print(len(rows), page["settledThrough"])
  • A 410 with the code cursor_expired means the cursor is gone. Start the export again from a request with no cursor, and clear the rows you collected.
  • Save rows by their external ID so a replayed page does no harm.
  • The final page carries settledThrough. Treat it as your watermark, then sync new history from that time with the windowed deals and orders endpoints.

The response is JSON. If you want a CSV file, write the rows out yourself from the JSON.

Ask an assistant instead

Claude, ChatGPT and Cursor can read the same data through the FiveSocket MCP connector at https://api.fivesocket.com/mcp. The tools are get_candles, list_deals, list_historical_orders and export_history_page. Ask for the last 100 H4 candles of a symbol, or for every deal from last month, and the assistant calls the tool for you. Connect an assistant over MCP

The same history is what an AI review of your trading reads. Build an AI trade journal for MT5

Limits

  • Timeframes are M1, M5, M15, H1, H4 and D1.
  • One candles request returns at most 1,000 bars. Page for more.
  • MT5's chart-history limit applies, so how far back you can read depends on what your broker keeps. A range that starts before the retained history is refused.
  • Candles are bars only. FiveSocket has no historical tick data.
  • Bars are completed bars. The bar that is still forming is not returned.
  • Candle paging runs fresh reads, so it is not a frozen snapshot of the broker's history.
  • Windowed deals and orders reads cover at most 90 days per request.

There is no MetaTrader 5 Python package to install and no Windows machine to keep running, so the same code works on macOS, Linux and in serverless functions. MetaTrader5 for Python on a Mac

The same applies on a Linux server. MetaTrader5 for Python on Linux

Frequently asked questions

Which timeframes can I read?
M1, M5, M15, H1, H4 and D1.
How far back does the history go?
As far as your broker's MT5 server keeps it. MT5's chart-history limit applies. One candles request returns at most 1,000 bars, so use nextTo to page backward through a longer range.
Is this tick data?
No. FiveSocket returns completed candles, not historical ticks. Each candle includes its tick volume, real volume and spread.
Does it work on Mac and Linux?
Yes. It is an HTTPS API, so any language on any operating system can call it. You need no Windows machine and no MT5 terminal.
Can I export my full trade history to CSV?
The history export endpoint returns your full deal or order history as JSON, one page at a time. FiveSocket does not produce CSV, so write the rows to a CSV file yourself in your own code.
Where do the prices come from?
From your own broker's MT5 server. FiveSocket uses no external price feed and does not calculate indicators or resample bars.
How much does it cost?
Plans start at $9.99 a month for one MT5 account. Link your MT5 account and try it free, no card: 24 hours or 100 calls, whichever comes first. Then a 7-day free trial, card required. Cancel anytime. The trial includes one connected MT5 account.

Try it on your own account.

Link your MT5 account and try it free, no card: 24 hours or 100 calls, whichever comes first. Then a 7-day free trial, card required. Cancel anytime. The trial includes one connected MT5 account. Cancel before the trial ends and you are not charged. A demo account is the safest place to start.

7-day free trial. Paid plans start at $9.99 a month. See pricing