# MT5Client Sub-module π€
Welcome to the **MT5Client** documentation! This is your all-in-one Python interface for MetaTrader 5 automation: connect, trade, analyze, and manage your MT5 terminal with a single, unified client. Perfect for algo trading, analytics, and robust trading automation! π
---
## Purpose π―
The `MT5Client` class is the main entry point for all MetaTrader 5 operations in this library. It wraps and unifies connection, account, market, order, and history management into a single, easy-to-use object.
---
## Class Overview ποΈ
```python
from metatrader_client.client import MT5Client
```
- **Class:** `MT5Client`
- **Location:** `src/metatrader_client/client.py`
- **Submodules:**
- `.account` β Account info and status
- `.market` β Market data and symbol info
- `.order` β Trading and order management
- `.history` β Historical deals and orders
- `.connection` β Terminal connection management
---
## Initialization βοΈ
```python
from metatrader_client.client import MT5Client
config = {
"login": 12345678,
"password": "your_password",
"server": "Broker-Server",
# Optional: path, timeout, portable, debug, etc.
}
client = MT5Client(config)
```
---
## Main Attributes & Methods π§©
### Attributes (Submodules)
- `client.account` β Account operations (balance, equity, margin, etc.)
- `client.market` β Market data (symbols, prices, candles)
- `client.order` β Order management (positions, orders, trading)
- `client.history` β Historical deals/orders/statistics
### Connection Methods
- `connect()` β Connect to the MT5 terminal and login
- `disconnect()` β Disconnect from the terminal
- `is_connected()` β Check connection status
- `get_terminal_info()` β Get terminal details
- `get_version()` β Get terminal version
- `last_error()` β Get last error code/description
---
## Example Usage π‘
```python
from metatrader_client.client import MT5Client
config = {
"login": 12345678,
"password": "your_password",
"server": "Broker-Server"
}
client = MT5Client(config)
if client.connect():
print("Connected! π")
print("Balance:", client.account.get_balance())
print("EURUSD price:", client.market.get_symbol_price("EURUSD"))
client.order.place_market_order(type="buy", symbol="EURUSD", volume=0.1)
print("Recent deals:", client.history.get_deals())
client.disconnect()
else:
print("Failed to connect. π¨")
```
---
## Submodule Docs π
- [Connection](./_connection.md)
- [Account](./_account.md)
- [Market](./_market.md)
- [Order](./_order.md)
- [History](./_history.md)
---
## Tips & Troubleshooting π‘οΈ
- Ensure the [MetaTrader5 Python package](https://pypi.org/project/MetaTrader5/) is installed.
- Use the `debug` flag in your config for more logs.
- Handle exceptions for robust automation.
- See submodule docs above for detailed info.
---
## Happy Trading! ππ€
For more details, see the source code in `src/metatrader_client/client.py` and the submodules.