SDK Module¶
mt5cli.sdk ¶
Programmatic SDK for MetaTrader 5 data collection.
__all__
module-attribute
¶
__all__ = [
"Mt5CliClient",
"account_info",
"build_config",
"collect_history",
"copy_rates_from",
"copy_rates_from_pos",
"copy_rates_range",
"copy_ticks_from",
"copy_ticks_range",
"history_deals",
"history_orders",
"last_error",
"market_book",
"orders",
"positions",
"symbol_info",
"symbol_info_tick",
"symbols",
"terminal_info",
"version",
]
Mt5CliClient ¶
Mt5CliClient(
*,
path: str | None = None,
login: int | None = None,
password: str | None = None,
server: str | None = None,
timeout: int | None = None,
config: Mt5Config | None = None,
)
Programmatic client for read-only MetaTrader 5 data access.
Initialize the SDK client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | None
|
Path to MetaTrader5 terminal EXE file. |
None
|
login
|
int | None
|
Trading account login. |
None
|
password
|
str | None
|
Trading account password. |
None
|
server
|
str | None
|
Trading server name. |
None
|
timeout
|
int | None
|
Connection timeout in milliseconds. |
None
|
config
|
Mt5Config | None
|
Optional pre-built |
None
|
Source code in mt5cli/sdk.py
__enter__ ¶
Open a persistent MT5 connection for multiple calls.
Returns:
| Type | Description |
|---|---|
Self
|
This client instance. |
Source code in mt5cli/sdk.py
__exit__ ¶
Shut down the persistent MT5 connection.
account_info ¶
copy_rates_from ¶
copy_rates_from(
symbol: str,
timeframe: int | str,
date_from: datetime | str,
count: int,
) -> DataFrame
Return rates starting from a date.
Source code in mt5cli/sdk.py
copy_rates_from_pos ¶
Return rates starting from a bar position.
Source code in mt5cli/sdk.py
copy_rates_range ¶
copy_rates_range(
symbol: str,
timeframe: int | str,
date_from: datetime | str,
date_to: datetime | str,
) -> DataFrame
Return rates for a date range.
Source code in mt5cli/sdk.py
copy_ticks_from ¶
copy_ticks_from(
symbol: str,
date_from: datetime | str,
count: int,
flags: int | str,
) -> DataFrame
Return ticks starting from a date.
Source code in mt5cli/sdk.py
copy_ticks_range ¶
copy_ticks_range(
symbol: str,
date_from: datetime | str,
date_to: datetime | str,
flags: int | str,
) -> DataFrame
Return ticks for a date range.
Source code in mt5cli/sdk.py
history_deals ¶
history_deals(
date_from: datetime | str | None = None,
date_to: datetime | str | None = None,
group: str | None = None,
symbol: str | None = None,
ticket: int | None = None,
position: int | None = None,
) -> DataFrame
Return historical deals.
Source code in mt5cli/sdk.py
history_orders ¶
history_orders(
date_from: datetime | str | None = None,
date_to: datetime | str | None = None,
group: str | None = None,
symbol: str | None = None,
ticket: int | None = None,
position: int | None = None,
) -> DataFrame
Return historical orders.
Source code in mt5cli/sdk.py
last_error ¶
market_book ¶
orders ¶
orders(
symbol: str | None = None,
group: str | None = None,
ticket: int | None = None,
) -> DataFrame
Return active orders.
Source code in mt5cli/sdk.py
positions ¶
positions(
symbol: str | None = None,
group: str | None = None,
ticket: int | None = None,
) -> DataFrame
Return open positions.
Source code in mt5cli/sdk.py
symbol_info ¶
symbol_info_tick ¶
symbols ¶
terminal_info ¶
account_info ¶
build_config ¶
build_config(
*,
path: str | None = None,
login: int | None = None,
password: str | None = None,
server: str | None = None,
timeout: int | None = None,
) -> Mt5Config
Build an Mt5Config from optional connection parameters.
Returns:
| Type | Description |
|---|---|
Mt5Config
|
Configured |
Source code in mt5cli/sdk.py
collect_history ¶
collect_history(
output: Path,
symbols: list[str],
date_from: datetime | str,
date_to: datetime | str,
*,
datasets: set[Dataset] | None = None,
timeframe: int | str = 1,
flags: int | str = 1,
if_exists: IfExists = FAIL,
with_views: bool = False,
config: Mt5Config | None = None,
) -> None
Collect historical datasets into a single SQLite database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
Path
|
SQLite database path. |
required |
symbols
|
list[str]
|
Symbols to collect. |
required |
date_from
|
datetime | str
|
Start date. |
required |
date_to
|
datetime | str
|
End date. |
required |
datasets
|
set[Dataset] | None
|
Datasets to include (defaults to all). |
None
|
timeframe
|
int | str
|
Rates timeframe as integer or name (e.g. |
1
|
flags
|
int | str
|
Tick copy flags as integer or name (e.g. |
1
|
if_exists
|
IfExists
|
Behavior when a target table already exists. |
FAIL
|
with_views
|
bool
|
Create |
False
|
config
|
Mt5Config | None
|
MT5 connection configuration. |
None
|
Source code in mt5cli/sdk.py
copy_rates_from ¶
copy_rates_from(
symbol: str,
timeframe: int | str,
date_from: datetime | str,
count: int,
*,
config: Mt5Config | None = None,
) -> DataFrame
Return rates starting from a date.
Source code in mt5cli/sdk.py
copy_rates_from_pos ¶
copy_rates_from_pos(
symbol: str,
timeframe: int | str,
start_pos: int,
count: int,
*,
config: Mt5Config | None = None,
) -> DataFrame
Return rates starting from a bar position.
Source code in mt5cli/sdk.py
copy_rates_range ¶
copy_rates_range(
symbol: str,
timeframe: int | str,
date_from: datetime | str,
date_to: datetime | str,
*,
config: Mt5Config | None = None,
) -> DataFrame
Return rates for a date range.
Source code in mt5cli/sdk.py
copy_ticks_from ¶
copy_ticks_from(
symbol: str,
date_from: datetime | str,
count: int,
flags: int | str,
*,
config: Mt5Config | None = None,
) -> DataFrame
Return ticks starting from a date.
Source code in mt5cli/sdk.py
copy_ticks_range ¶
copy_ticks_range(
symbol: str,
date_from: datetime | str,
date_to: datetime | str,
flags: int | str,
*,
config: Mt5Config | None = None,
) -> DataFrame
Return ticks for a date range.
Source code in mt5cli/sdk.py
history_deals ¶
history_deals(
date_from: datetime | str | None = None,
date_to: datetime | str | None = None,
group: str | None = None,
symbol: str | None = None,
ticket: int | None = None,
position: int | None = None,
*,
config: Mt5Config | None = None,
) -> DataFrame
Return historical deals.
Source code in mt5cli/sdk.py
history_orders ¶
history_orders(
date_from: datetime | str | None = None,
date_to: datetime | str | None = None,
group: str | None = None,
symbol: str | None = None,
ticket: int | None = None,
position: int | None = None,
*,
config: Mt5Config | None = None,
) -> DataFrame
Return historical orders.
Source code in mt5cli/sdk.py
last_error ¶
market_book ¶
orders ¶
orders(
symbol: str | None = None,
group: str | None = None,
ticket: int | None = None,
*,
config: Mt5Config | None = None,
) -> DataFrame
Return active orders.
Source code in mt5cli/sdk.py
positions ¶
positions(
symbol: str | None = None,
group: str | None = None,
ticket: int | None = None,
*,
config: Mt5Config | None = None,
) -> DataFrame
Return open positions.