CLI Module¶
mt5cli.cli ¶
Command-line interface for MetaTrader 5 data export.
app
module-attribute
¶
account_info ¶
collect_history ¶
collect_history(
ctx: Context,
symbol: Annotated[
list[str],
Option(
"--symbol",
"-s",
help="Symbol to collect (repeat for multiple symbols).",
),
],
date_from: Annotated[
datetime,
Option(
click_type=DATETIME_TYPE, help="Start date."
),
],
date_to: Annotated[
datetime,
Option(click_type=DATETIME_TYPE, help="End date."),
],
dataset: Annotated[
list[Dataset] | None,
Option(
"--dataset",
help="Dataset to include (repeat for multiple). Defaults to all: rates, ticks, history-orders, history-deals.",
),
] = None,
timeframe: Annotated[
int,
Option(
click_type=TIMEFRAME_TYPE,
help="Rates timeframe (e.g., M1, H1, D1).",
),
] = 1,
flags: Annotated[
int,
Option(
click_type=TICK_FLAGS_TYPE,
help="Tick copy flags (ALL, INFO, TRADE, or integer).",
),
] = "ALL",
if_exists: Annotated[
IfExists,
Option(
"--if-exists",
help="Behavior when a target table already exists.",
),
] = FAIL,
with_views: Annotated[
bool,
Option(
"--with-views",
help="Add cash_events and positions_reconstructed SQLite views derived from history_deals.",
),
] = False,
) -> None
Collect historical datasets into a single SQLite database.
Tables written depend on --dataset: rates, ticks,
history_orders, history_deals. History datasets are fetched per
symbol and concatenated. Rates rows carry the requested timeframe so
appended runs at different timeframes remain distinguishable.
With --with-views (requires the history-deals dataset), optional
views cash_events and positions_reconstructed are derived from
history_deals when the required columns are present.
Raises:
| Type | Description |
|---|---|
BadParameter
|
If the output format is not SQLite3. |
Source code in mt5cli/cli.py
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 | |
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
last_error ¶
latest_rates ¶
latest_rates(
ctx: Context,
symbol: Annotated[str, Option(help="Symbol name.")],
timeframe: Annotated[
int,
Option(
click_type=TIMEFRAME_TYPE, help="Timeframe."
),
],
count: Annotated[
int, Option(help="Number of records.")
],
start_pos: Annotated[
int,
Option(help="Start position (0 = current bar)."),
] = 0,
) -> None
Export latest rates from a start position.
Source code in mt5cli/cli.py
main ¶
market_book ¶
Export market depth (order book) for a symbol.
minimum_margins ¶
Export minimum-volume buy and sell margin requirements.
Source code in mt5cli/cli.py
mt5_summary ¶
order_check ¶
order_check(
ctx: Context,
request: Annotated[
dict[str, Any],
Option(
click_type=REQUEST_TYPE,
help=_REQUEST_OPTION_HELP,
),
],
) -> None
Check funds sufficiency for a trading operation.
Source code in mt5cli/cli.py
order_send ¶
order_send(
ctx: Context,
request: Annotated[
dict[str, Any],
Option(
click_type=REQUEST_TYPE,
help=_REQUEST_OPTION_HELP,
),
],
yes: Annotated[
bool,
Option(
"--yes", help="Confirm the live trade request."
),
] = False,
) -> None
Send a trading operation request to the trade server.
Raises:
| Type | Description |
|---|---|
BadParameter
|
If --yes is not provided. |
Source code in mt5cli/cli.py
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
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
recent_history_deals ¶
recent_history_deals(
ctx: Context,
hours: Annotated[
float, Option(help="Lookback window in hours.")
],
date_to: Annotated[
datetime | None,
Option(
click_type=DATETIME_TYPE,
help="Window end date.",
),
] = None,
group: Annotated[
str | None, Option(help="Group filter.")
] = None,
symbol: Annotated[
str | None, Option(help="Symbol filter.")
] = None,
) -> None
Export historical deals from a recent trailing window.
Source code in mt5cli/cli.py
symbol_info ¶
symbol_info_tick ¶
Export the last tick for a symbol.
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.
Source code in mt5cli/cli.py
ticks_recent ¶
ticks_recent(
ctx: Context,
symbol: Annotated[str, Option(help="Symbol name.")],
seconds: Annotated[
float, Option(help="Lookback window in seconds.")
],
date_to: Annotated[
datetime | None,
Option(
click_type=DATETIME_TYPE,
help="Window end date.",
),
] = None,
count: Annotated[
int,
Option(help="Maximum number of ticks to return."),
] = 10000,
flags: Annotated[
int,
Option(
click_type=TICK_FLAGS_TYPE,
help="Tick flags (ALL, INFO, TRADE, or integer).",
),
] = "ALL",
) -> None
Export ticks from a recent time window.