CLI Module¶
mt5cli.cli ¶
Command-line interface for MetaTrader 5 data export.
TICK_FLAG_MAP
module-attribute
¶
TIMEFRAME_MAP
module-attribute
¶
TIMEFRAME_MAP: dict[str, int] = {
"M1": 1,
"M2": 2,
"M3": 3,
"M4": 4,
"M5": 5,
"M6": 6,
"M10": 10,
"M12": 12,
"M15": 15,
"M20": 20,
"M30": 30,
"H1": 16385,
"H2": 16386,
"H3": 16387,
"H4": 16388,
"H6": 16390,
"H8": 16392,
"H12": 16396,
"D1": 16408,
"W1": 32769,
"MN1": 49153,
}
app
module-attribute
¶
LogLevel ¶
OutputFormat ¶
account_info ¶
detect_format ¶
Detect the output format from a file extension or explicit format string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_path
|
Path
|
Path to the output file. |
required |
explicit_format
|
str | None
|
Explicitly specified format, if any. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The detected format string. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the format cannot be determined. |
Source code in mt5cli/cli.py
export_dataframe ¶
export_dataframe(
df: DataFrame,
output_path: Path,
output_format: str,
table_name: str = "data",
) -> None
Export a pandas DataFrame to the specified file format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame to export. |
required |
output_path
|
Path
|
Path to the output file. |
required |
output_format
|
str
|
Output format (csv, json, parquet, or sqlite3). |
required |
table_name
|
str
|
Table name for SQLite3 output. |
'data'
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the output format is not supported. |
Source code in mt5cli/cli.py
history_deals ¶
history_deals(
ctx: Context,
date_from: Annotated[
datetime | None,
Option(
click_type=DATETIME_TYPE, help="Start date."
),
] = None,
date_to: Annotated[
datetime | None,
Option(click_type=DATETIME_TYPE, help="End date."),
] = None,
group: Annotated[
str | None, Option(help="Group filter.")
] = None,
symbol: Annotated[
str | None, Option(help="Symbol filter.")
] = None,
ticket: Annotated[
int | None, Option(help="Order ticket.")
] = None,
position: Annotated[
int | None, Option(help="Position ticket.")
] = None,
) -> None
Export historical deals.
Source code in mt5cli/cli.py
history_orders ¶
history_orders(
ctx: Context,
date_from: Annotated[
datetime | None,
Option(
click_type=DATETIME_TYPE, help="Start date."
),
] = None,
date_to: Annotated[
datetime | None,
Option(click_type=DATETIME_TYPE, help="End date."),
] = None,
group: Annotated[
str | None, Option(help="Group filter.")
] = None,
symbol: Annotated[
str | None, Option(help="Symbol filter.")
] = None,
ticket: Annotated[
int | None, Option(help="Order ticket.")
] = None,
position: Annotated[
int | None, Option(help="Position ticket.")
] = None,
) -> None
Export historical orders.
Source code in mt5cli/cli.py
main ¶
orders ¶
orders(
ctx: Context,
symbol: Annotated[
str | None, Option(help="Symbol filter.")
] = None,
group: Annotated[
str | None, Option(help="Group filter.")
] = None,
ticket: Annotated[
int | None, Option(help="Ticket filter.")
] = None,
) -> None
Export active orders.
Source code in mt5cli/cli.py
parse_datetime ¶
Parse an ISO 8601 datetime string to a timezone-aware datetime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
ISO 8601 datetime string (e.g., '2024-01-01' or '2024-01-01T12:00:00+00:00'). |
required |
Returns:
| Type | Description |
|---|---|
datetime
|
Parsed datetime with UTC timezone if no timezone is specified. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the string cannot be parsed. |
Source code in mt5cli/cli.py
parse_tick_flags ¶
Parse tick flags string or integer value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
Tick flag name (ALL, INFO, TRADE) or integer value. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Integer tick flag value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the flag is invalid. |
Source code in mt5cli/cli.py
parse_timeframe ¶
Parse a timeframe string or integer value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
Timeframe name (e.g., 'M1', 'H1', 'D1') or integer value. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Integer timeframe value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the timeframe is invalid. |
Source code in mt5cli/cli.py
positions ¶
positions(
ctx: Context,
symbol: Annotated[
str | None, Option(help="Symbol filter.")
] = None,
group: Annotated[
str | None, Option(help="Group filter.")
] = None,
ticket: Annotated[
int | None, Option(help="Ticket filter.")
] = None,
) -> None
Export open positions.
Source code in mt5cli/cli.py
rates_from ¶
rates_from(
ctx: Context,
symbol: Annotated[str, Option(help="Symbol name.")],
timeframe: Annotated[
int,
Option(
click_type=TIMEFRAME_TYPE,
help="Timeframe (e.g., M1, H1, D1, or integer).",
),
],
date_from: Annotated[
datetime,
Option(
click_type=DATETIME_TYPE,
help="Start date in ISO 8601 format.",
),
],
count: Annotated[
int, Option(help="Number of records.")
],
) -> None
Export rates from a start date.
Source code in mt5cli/cli.py
rates_from_pos ¶
rates_from_pos(
ctx: Context,
symbol: Annotated[str, Option(help="Symbol name.")],
timeframe: Annotated[
int,
Option(
click_type=TIMEFRAME_TYPE, help="Timeframe."
),
],
start_pos: Annotated[
int,
Option(help="Start position (0 = current bar)."),
],
count: Annotated[
int, Option(help="Number of records.")
],
) -> None
Export rates from a start position.
Source code in mt5cli/cli.py
rates_range ¶
rates_range(
ctx: Context,
symbol: Annotated[str, Option(help="Symbol name.")],
timeframe: Annotated[
int,
Option(
click_type=TIMEFRAME_TYPE, help="Timeframe."
),
],
date_from: Annotated[
datetime,
Option(
click_type=DATETIME_TYPE, help="Start date."
),
],
date_to: Annotated[
datetime,
Option(click_type=DATETIME_TYPE, help="End date."),
],
) -> None
Export rates for a date range.
Source code in mt5cli/cli.py
symbol_info ¶
Export symbol details.
symbols ¶
symbols(
ctx: Context,
group: Annotated[
str | None,
Option(help="Symbol group filter (e.g., *USD*)."),
] = None,
) -> None
Export symbol list.
Source code in mt5cli/cli.py
terminal_info ¶
ticks_from ¶
ticks_from(
ctx: Context,
symbol: Annotated[str, Option(help="Symbol name.")],
date_from: Annotated[
datetime,
Option(
click_type=DATETIME_TYPE, help="Start date."
),
],
count: Annotated[int, Option(help="Number of ticks.")],
flags: Annotated[
int,
Option(
click_type=TICK_FLAGS_TYPE,
help="Tick flags (ALL, INFO, TRADE, or integer).",
),
],
) -> None
Export ticks from a start date.
Source code in mt5cli/cli.py
ticks_range ¶
ticks_range(
ctx: Context,
symbol: Annotated[str, Option(help="Symbol name.")],
date_from: Annotated[
datetime,
Option(
click_type=DATETIME_TYPE, help="Start date."
),
],
date_to: Annotated[
datetime,
Option(click_type=DATETIME_TYPE, help="End date."),
],
flags: Annotated[
int,
Option(
click_type=TICK_FLAGS_TYPE, help="Tick flags."
),
],
) -> None
Export ticks for a date range.