Deployment Guide (Windows Service)¶
This guide describes how to deploy the mt5api REST API as a Windows service alongside the MetaTrader 5 terminal.
This is a Windows-only deployment target. The API server cannot run on Linux or
macOS because the MetaTrader5 Python package is supported only on Windows.
Prerequisites¶
- Windows 10/11
- MetaTrader 5 installed and logged in
- Python 3.11+
mt5apiinstalled- PowerShell access with permission to install and manage services
Service Setup (NSSM)¶
- Download NSSM: https://nssm.cc/download
- Open an elevated PowerShell session.
- Create a service:
-
Set the application path and arguments:
-
Path:
C:\Path\To\Python\python.exe - Arguments:
-m uvicorn mt5api.main:app --host 0.0.0.0 --port 8000 -
Startup directory: your project directory
-
Set environment variables in the NSSM GUI:
# Optional: set MT5API_SECRET_KEY only when you want to require X-API-Key headers.
MT5API_SECRET_KEY=your-secret-api-key
MT5API_LOG_LEVEL=INFO
MT5API_MAX_MARKET_BOOK_SUBSCRIPTIONS=100
MT5API_ROUTER_PREFIX=/api/v1
- Start the service:
Validation¶
In PowerShell, use curl.exe if curl resolves to Invoke-WebRequest.
Expected status: healthy (or unhealthy if MT5 is not connected).
Troubleshooting¶
- Ensure the MT5 terminal is running and logged in.
- Confirm firewall rules allow inbound traffic on the API port.
- Check Windows Event Viewer for NSSM service logs.