How to get a MetaTrader 5 API key

MT5 has no API key; Python logs in with your account number, password and server.

About 15 minutes 4 steps Checked November 2026

Before you start

  • Windows (or Wine) with the MT5 terminal installed
  • A demo or live MT5 account

Create your MetaTrader 5 API key

  1. 1

    Open a demo account

    In the terminal choose File → Open an Account and pick your broker’s demo server.

  2. 2

    Enable algo trading

    Click Algo Trading in the toolbar and allow it under Tools → Options → Expert Advisors.

  3. 3

    Install the package

    Run pip install MetaTrader5 in the same Windows Python.

  4. 4

    Store login details

    Save MT5_LOGIN, MT5_PASSWORD and MT5_SERVER (and MT5_TERMINAL_PATH if needed).

Test the key

Before wiring the key into a strategy, make one request by hand. It separates “the key is wrong” from “my code is wrong”.

import MetaTrader5 as mt5
print(mt5.initialize(), mt5.account_info())
True and your account info mean Python is connected.

Keep the credentials safe

  • Store values in a password manager or a git-ignored .env, never in code or notebooks you share.
  • In an AlgoGP project you can still add them under APIs & keys (encrypted at rest) and read them with strategy_runtime.secrets.get("MT5_LOGIN").
  • Give each bot its own credential so you can revoke one without stopping the others.
MT5_LOGIN=paste-your-value-here
MT5_PASSWORD=paste-your-value-here
MT5_SERVER=paste-your-value-here
# MT5_TERMINAL_PATH=
.env for local runs

Design and backtest your MetaTrader 5 strategy first

AlgoGP turns an idea into Python and tests it on years of history before you connect it to MetaTrader 5. The exported code keeps the broker behind four small adapter methods.

  • AI copilot writes and revises the rules
  • Backtests with realistic costs
  • Exported Python ready to wire to MetaTrader 5

Free plan, no card required.

How the MetaTrader 5 API works

AlgoGP is not affiliated with MetaTrader 5. Menus get renamed from time to time; if a label differs, the official documentation has the current path.