Why syntiq-mt5?¶
The raw MetaTrader5 Python package returns untyped structs, stores errors in global state, and requires you to know integer constants by heart. syntiq-mt5 fixes all of that.
-
Typed Models
Pydantic v2 models with full IDE completion. No more guessing field names or types.
-
No Exceptions
Every operation returns
Result[T]. Handle success and failure explicitly — no surprises. -
Named Constants
Use
ORDER_TYPE_BUYinstead of0. UseTIMEFRAME_H1instead of16385. Self-documenting code. -
Automatic Cleanup
Context manager support.
shutdown()is called automatically — even on exceptions.
Raw MT5 vs syntiq-mt5¶
| Raw MT5 | syntiq-mt5 |
|---|---|
| Untyped namedtuples | Pydantic models with IDE completion |
mt5.last_error() after every call |
result.error_code / result.error_message |
Magic integers (0, 1, 16385) |
Named constants (ORDER_TYPE_BUY, TIMEFRAME_H1) |
| Raises on connection failure | Returns Result.fail(...) |
Manual mt5.shutdown() |
Automatic via context manager |
Quick example¶
from pydantic import SecretStr
from syntiq_mt5 import LoginCredential, MetaTrader5Client, constants
creds = LoginCredential(
login=12345678,
password=SecretStr("your-password"),
server="Broker-Demo",
)
with MetaTrader5Client() as mt5:
mt5.initialize(creds)
mt5.login(creds)
res = mt5.positions()
if res.success:
for p in res.data:
print(f"{p.symbol} {p.volume} lots {p.pips_profit:+.1f} pips")
import MetaTrader5 as mt5
if not mt5.initialize():
print("initialize() failed")
quit()
if not mt5.login(12345678, password="your-password", server="Broker-Demo"):
print("login() failed, error code =", mt5.last_error())
mt5.shutdown()
quit()
positions = mt5.positions_get()
if positions is None:
print("No positions, error code =", mt5.last_error())
elif len(positions) > 0:
for p in positions:
# p is a namedtuple — no IDE completion, no type hints
print(p.symbol, p.volume, p.profit)
mt5.shutdown()
Install¶
Requirements
- Windows — the MT5 Python API is Windows-only
- MetaTrader 5 terminal installed (download)
- Python 3.12+
What's next?¶
-
Full working example in under 60 seconds
-
Understand
initialize → login → use → shutdown -
Copy-paste recipes for every operation
-
Complete auto-generated API documentation