# CLI - mt5cli API Documentation
Author: dceoy

# CLI Module

## mt5cli.cli

Command-line interface for MetaTrader 5 data export.

### app `module-attribute`

    app = Typer(
        name="mt5cli",
        help="Export MetaTrader5 data to CSV, JSON, Parquet, or SQLite3.",
    )

### logger `module-attribute`

    logger = getLogger(__name__)

### account_info

    account_info(ctx: Context) -> None

Export account information.

Source code in `mt5cli/cli.py`

    380
    381
    382
    383

    @app.command()
    def account_info(ctx: typer.Context) -> None:
        """Export account information."""
        _export_command(ctx, lambda client: client.account_info())

### close_positions

    close_positions(
        ctx: Context,
        symbol: Annotated[
            list[str] | None,
            Option(
                "--symbol",
                "-s",
                help="Symbol to close (repeat for multiple symbols).",
            ),
        ] = None,
        ticket: Annotated[
            list[int] | None,
            Option(
                "--ticket",
                "-t",
                help="Position ticket to close (repeat for multiple tickets).",
            ),
        ] = None,
        dry_run: Annotated[
            bool,
            Option(
                "--dry-run",
                help="Preview close orders without executing them.",
            ),
        ] = False,
        yes: Annotated[
            bool,
            Option(
                "--yes", help="Confirm live position closing."
            ),
        ] = False,
    ) -> None

Close open positions by symbol or ticket.

Delegates to :func:`mt5cli.trading.close_open_positions`. At least one `--symbol` or `--ticket` must be provided to avoid accidentally closing all positions. Use `--dry-run` to preview without executing; `--yes` is required for live execution.

`order-send` is the expert raw-request path. `close-positions` is the safer high-level helper that builds correct close requests automatically.

Raises:

Type | Description
--- | ---
`BadParameter` | If neither `--symbol` nor `--ticket` is given, or if `--yes` is missing for a live (non-dry-run) run.

Source code in `mt5cli/cli.py`

    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

    @app.command()
    def close_positions(
        ctx: typer.Context,
        symbol: Annotated[
            list[str] | None,
            typer.Option(
                "--symbol",
                "-s",
                help="Symbol to close (repeat for multiple symbols).",
            ),
        ] = None,
        ticket: Annotated[
            list[int] | None,
            typer.Option(
                "--ticket",
                "-t",
                help="Position ticket to close (repeat for multiple tickets).",
            ),
        ] = None,
        dry_run: Annotated[
            bool,
            typer.Option("--dry-run", help="Preview close orders without executing them."),
        ] = False,
        yes: Annotated[
            bool,
            typer.Option("--yes", help="Confirm live position closing."),
        ] = False,
    ) -> None:
        """Close open positions by symbol or ticket.

        Delegates to :func:`mt5cli.trading.close_open_positions`. At least one
        ``--symbol`` or ``--ticket`` must be provided to avoid accidentally closing
        all positions. Use ``--dry-run`` to preview without executing; ``--yes`` is
        required for live execution.

        ``order-send`` is the expert raw-request path. ``close-positions`` is the
        safer high-level helper that builds correct close requests automatically.

        Raises:
            typer.BadParameter: If neither ``--symbol`` nor ``--ticket`` is given,
                or if ``--yes`` is missing for a live (non-dry-run) run.
        """
        if not symbol and not ticket:
            msg = "Provide at least one --symbol or --ticket to close positions."
            raise typer.BadParameter(msg)
        if not dry_run and not yes:
            msg = "Pass --yes to close live positions."
            raise typer.BadParameter(msg, param_hint="--yes")
        export_ctx = _get_export_context(ctx)
        client = create_trading_client(config=export_ctx.config)
        try:
            results = close_open_positions(
                client,
                symbols=list(symbol) if symbol else None,
                tickets=list(ticket) if ticket else None,
                dry_run=dry_run,
            )
        finally:
            client.shutdown()
        df = _execution_results_to_df(results)
        _execute_export(ctx, lambda: df)

### 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`

    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
    756
    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
    777
    778
    779
    780
    781
    782
    783
    784
    785
    786
    787
    788

    @app.command()
    def collect_history(
        ctx: typer.Context,
        symbol: Annotated[
            list[str],
            typer.Option(
                "--symbol",
                "-s",
                help="Symbol to collect (repeat for multiple symbols).",
            ),
        ],
        date_from: Annotated[
            datetime,
            typer.Option(click_type=DATETIME_TYPE, help="Start date."),
        ],
        date_to: Annotated[
            datetime,
            typer.Option(click_type=DATETIME_TYPE, help="End date."),
        ],
        dataset: Annotated[
            list[Dataset] | None,
            typer.Option(
                "--dataset",
                help=(
                    "Dataset to include (repeat for multiple)."
                    " Defaults to all: rates, ticks, history-orders, history-deals."
                ),
            ),
        ] = None,
        timeframe: Annotated[
            int,
            typer.Option(
                click_type=TIMEFRAME_TYPE,
                help="Rates timeframe (e.g., M1, H1, D1).",
            ),
        ] = 1,
        flags: Annotated[
            int,
            typer.Option(
                click_type=TICK_FLAGS_TYPE,
                help="Tick copy flags (ALL, INFO, TRADE, or integer).",
            ),
        ] = "ALL",  # pyright: ignore[reportArgumentType]
        if_exists: Annotated[
            IfExists,
            typer.Option(
                "--if-exists",
                help="Behavior when a target table already exists.",
            ),
        ] = IfExists.FAIL,
        with_views: Annotated[
            bool,
            typer.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:
            typer.BadParameter: If the output format is not SQLite3.
        """
        export_ctx = _get_export_context(ctx)
        if export_ctx.output_format != "sqlite3":
            msg = (
                "collect-history requires SQLite3 output."
                " Use a .db/.sqlite/.sqlite3 extension or --format sqlite3."
            )
            raise typer.BadParameter(msg)
        datasets = set(dataset) if dataset else set(Dataset)
        sdk.collect_history(
            output=export_ctx.output,
            symbols=symbol,
            date_from=date_from,
            date_to=date_to,
            datasets=datasets,
            timeframe=timeframe,
            flags=flags,
            if_exists=if_exists,
            with_views=with_views,
            config=export_ctx.config,
        )

### 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`

    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507

    @app.command()
    def history_deals(
        ctx: typer.Context,
        date_from: Annotated[
            datetime | None,
            typer.Option(click_type=DATETIME_TYPE, help="Start date."),
        ] = None,
        date_to: Annotated[
            datetime | None,
            typer.Option(click_type=DATETIME_TYPE, help="End date."),
        ] = None,
        group: Annotated[str | None, typer.Option(help="Group filter.")] = None,
        symbol: Annotated[str | None, typer.Option(help="Symbol filter.")] = None,
        ticket: Annotated[int | None, typer.Option(help="Order ticket.")] = None,
        position: Annotated[int | None, typer.Option(help="Position ticket.")] = None,
    ) -> None:
        """Export historical deals."""
        _export_command(
            ctx,
            lambda client: client.history_deals(
                date_from=date_from,
                date_to=date_to,
                group=group,
                symbol=symbol,
                ticket=ticket,
                position=position,
            ),
        )

### 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`

    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477

    @app.command()
    def history_orders(
        ctx: typer.Context,
        date_from: Annotated[
            datetime | None,
            typer.Option(click_type=DATETIME_TYPE, help="Start date."),
        ] = None,
        date_to: Annotated[
            datetime | None,
            typer.Option(click_type=DATETIME_TYPE, help="End date."),
        ] = None,
        group: Annotated[str | None, typer.Option(help="Group filter.")] = None,
        symbol: Annotated[str | None, typer.Option(help="Symbol filter.")] = None,
        ticket: Annotated[int | None, typer.Option(help="Order ticket.")] = None,
        position: Annotated[int | None, typer.Option(help="Position ticket.")] = None,
    ) -> None:
        """Export historical orders."""
        _export_command(
            ctx,
            lambda client: client.history_orders(
                date_from=date_from,
                date_to=date_to,
                group=group,
                symbol=symbol,
                ticket=ticket,
                position=position,
            ),
        )

### last_error

    last_error(ctx: Context) -> None

Export the last error information.

Source code in `mt5cli/cli.py`

    545
    546
    547
    548

    @app.command()
    def last_error(ctx: typer.Context) -> None:
        """Export the last error information."""
        _export_command(ctx, lambda client: client.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`

    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265

    @app.command()
    def latest_rates(
        ctx: typer.Context,
        symbol: Annotated[str, typer.Option(help="Symbol name.")],
        timeframe: Annotated[
            int,
            typer.Option(
                click_type=TIMEFRAME_TYPE,
                help="Timeframe.",
            ),
        ],
        count: Annotated[int, typer.Option(help="Number of records.")],
        start_pos: Annotated[
            int,
            typer.Option(help="Start position (0 = current bar)."),
        ] = 0,
    ) -> None:
        """Export latest rates from a start position."""
        _export_command(
            ctx,
            lambda client: client.latest_rates(
                symbol,
                timeframe,
                count,
                start_pos=start_pos,
            ),
        )

### main

    main() -> None

Run the mt5cli CLI.

Source code in `mt5cli/cli.py`

    791
    792
    793

    def main() -> None:
        """Run the mt5cli CLI."""
        app()

### market_book

    market_book(
        ctx: Context,
        symbol: Annotated[str, Option(help="Symbol name.")],
    ) -> None

Export market depth (order book) for a symbol.

Source code in `mt5cli/cli.py`

    560
    561
    562
    563
    564
    565
    566

    @app.command()
    def market_book(
        ctx: typer.Context,
        symbol: Annotated[str, typer.Option(help="Symbol name.")],
    ) -> None:
        """Export market depth (order book) for a symbol."""
        _export_command(ctx, lambda client: client.market_book(symbol))

### minimum_margins

    minimum_margins(
        ctx: Context,
        symbol: Annotated[str, Option(help="Symbol name.")],
    ) -> None

Export minimum-volume buy and sell margin requirements.

Source code in `mt5cli/cli.py`

    413
    414
    415
    416
    417
    418
    419

    @app.command()
    def minimum_margins(
        ctx: typer.Context,
        symbol: Annotated[str, typer.Option(help="Symbol name.")],
    ) -> None:
        """Export minimum-volume buy and sell margin requirements."""
        _export_command(ctx, lambda client: client.minimum_margins(symbol))

### mt5_summary

    mt5_summary(ctx: Context) -> None

Export a compact terminal/account status summary.

Source code in `mt5cli/cli.py`

    533
    534
    535
    536

    @app.command()
    def mt5_summary(ctx: typer.Context) -> None:
        """Export a compact terminal/account status summary."""
        _export_command(ctx, lambda client: client.mt5_summary_as_df())

### 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`

    569
    570
    571
    572
    573
    574
    575
    576
    577
    578

    @app.command()
    def order_check(
        ctx: typer.Context,
        request: Annotated[
            dict[str, Any],
            typer.Option(click_type=REQUEST_TYPE, help=_REQUEST_OPTION_HELP),
        ],
    ) -> None:
        """Check funds sufficiency for a trading operation."""
        _export_command(ctx, lambda client: client.order_check(request))

### 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`

    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601

    @app.command()
    def order_send(
        ctx: typer.Context,
        request: Annotated[
            dict[str, Any],
            typer.Option(click_type=REQUEST_TYPE, help=_REQUEST_OPTION_HELP),
        ],
        yes: Annotated[
            bool,
            typer.Option("--yes", help="Confirm the live trade request."),
        ] = False,
    ) -> None:
        """Send a trading operation request to the trade server.

        Raises:
            typer.BadParameter: If --yes is not provided.
        """
        if not yes:
            msg = "Pass --yes to send a live trade request."
            raise typer.BadParameter(msg, param_hint="--yes")
        _export_command(ctx, lambda client: client.order_send(request))

### 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`

    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433

    @app.command()
    def orders(
        ctx: typer.Context,
        symbol: Annotated[str | None, typer.Option(help="Symbol filter.")] = None,
        group: Annotated[str | None, typer.Option(help="Group filter.")] = None,
        ticket: Annotated[int | None, typer.Option(help="Ticket filter.")] = None,
    ) -> None:
        """Export active orders."""
        _export_command(
            ctx,
            lambda client: client.orders(symbol=symbol, group=group, ticket=ticket),
        )

### 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`

    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447

    @app.command()
    def positions(
        ctx: typer.Context,
        symbol: Annotated[str | None, typer.Option(help="Symbol filter.")] = None,
        group: Annotated[str | None, typer.Option(help="Group filter.")] = None,
        ticket: Annotated[int | None, typer.Option(help="Ticket filter.")] = None,
    ) -> None:
        """Export open positions."""
        _export_command(
            ctx,
            lambda client: client.positions(symbol=symbol, group=group, ticket=ticket),
        )

### 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`

    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210

    @app.command()
    def rates_from(
        ctx: typer.Context,
        symbol: Annotated[str, typer.Option(help="Symbol name.")],
        timeframe: Annotated[
            int,
            typer.Option(
                click_type=TIMEFRAME_TYPE,
                help="Timeframe (e.g., M1, H1, D1, or integer).",
            ),
        ],
        date_from: Annotated[
            datetime,
            typer.Option(
                click_type=DATETIME_TYPE,
                help="Start date in ISO 8601 format.",
            ),
        ],
        count: Annotated[int, typer.Option(help="Number of records.")],
    ) -> None:
        """Export rates from a start date."""
        _export_command(
            ctx,
            lambda client: client.copy_rates_from(symbol, timeframe, date_from, count),
        )

### 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`

    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236

    @app.command()
    def rates_from_pos(
        ctx: typer.Context,
        symbol: Annotated[str, typer.Option(help="Symbol name.")],
        timeframe: Annotated[
            int,
            typer.Option(
                click_type=TIMEFRAME_TYPE,
                help="Timeframe.",
            ),
        ],
        start_pos: Annotated[int, typer.Option(help="Start position (0 = current bar).")],
        count: Annotated[int, typer.Option(help="Number of records.")],
    ) -> None:
        """Export rates from a start position."""
        _export_command(
            ctx,
            lambda client: client.copy_rates_from_pos(
                symbol,
                timeframe,
                start_pos,
                count,
            ),
        )

### 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`

    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292

    @app.command()
    def rates_range(
        ctx: typer.Context,
        symbol: Annotated[str, typer.Option(help="Symbol name.")],
        timeframe: Annotated[
            int,
            typer.Option(
                click_type=TIMEFRAME_TYPE,
                help="Timeframe.",
            ),
        ],
        date_from: Annotated[
            datetime,
            typer.Option(click_type=DATETIME_TYPE, help="Start date."),
        ],
        date_to: Annotated[
            datetime,
            typer.Option(click_type=DATETIME_TYPE, help="End date."),
        ],
    ) -> None:
        """Export rates for a date range."""
        _export_command(
            ctx,
            lambda client: client.copy_rates_range(symbol, timeframe, date_from, date_to),
        )

### 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`

    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530

    @app.command()
    def recent_history_deals(
        ctx: typer.Context,
        hours: Annotated[float, typer.Option(help="Lookback window in hours.")],
        date_to: Annotated[
            datetime | None,
            typer.Option(click_type=DATETIME_TYPE, help="Window end date."),
        ] = None,
        group: Annotated[str | None, typer.Option(help="Group filter.")] = None,
        symbol: Annotated[str | None, typer.Option(help="Symbol filter.")] = None,
    ) -> None:
        """Export historical deals from a recent trailing window."""
        _export_command(
            ctx,
            lambda client: client.recent_history_deals(
                hours,
                date_to=date_to,
                group=group,
                symbol=symbol,
            ),
        )

### symbol_info

    symbol_info(
        ctx: Context,
        symbol: Annotated[str, Option(help="Symbol name.")],
    ) -> None

Export symbol details.

Source code in `mt5cli/cli.py`

    404
    405
    406
    407
    408
    409
    410

    @app.command()
    def symbol_info(
        ctx: typer.Context,
        symbol: Annotated[str, typer.Option(help="Symbol name.")],
    ) -> None:
        """Export symbol details."""
        _export_command(ctx, lambda client: client.symbol_info(symbol))

### symbol_info_tick

    symbol_info_tick(
        ctx: Context,
        symbol: Annotated[str, Option(help="Symbol name.")],
    ) -> None

Export the last tick for a symbol.

Source code in `mt5cli/cli.py`

    551
    552
    553
    554
    555
    556
    557

    @app.command()
    def symbol_info_tick(
        ctx: typer.Context,
        symbol: Annotated[str, typer.Option(help="Symbol name.")],
    ) -> None:
        """Export the last tick for a symbol."""
        _export_command(ctx, lambda client: client.symbol_info_tick(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`

    392
    393
    394
    395
    396
    397
    398
    399
    400
    401

    @app.command()
    def symbols(
        ctx: typer.Context,
        group: Annotated[
            str | None,
            typer.Option(help="Symbol group filter (e.g., *USD*)."),
        ] = None,
    ) -> None:
        """Export symbol list."""
        _export_command(ctx, lambda client: client.symbols(group=group))

### terminal_info

    terminal_info(ctx: Context) -> None

Export terminal information.

Source code in `mt5cli/cli.py`

    386
    387
    388
    389

    @app.command()
    def terminal_info(ctx: typer.Context) -> None:
        """Export terminal information."""
        _export_command(ctx, lambda client: client.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`

    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316

    @app.command()
    def ticks_from(
        ctx: typer.Context,
        symbol: Annotated[str, typer.Option(help="Symbol name.")],
        date_from: Annotated[
            datetime,
            typer.Option(click_type=DATETIME_TYPE, help="Start date."),
        ],
        count: Annotated[int, typer.Option(help="Number of ticks.")],
        flags: Annotated[
            int,
            typer.Option(
                click_type=TICK_FLAGS_TYPE,
                help="Tick flags (ALL, INFO, TRADE, or integer).",
            ),
        ],
    ) -> None:
        """Export ticks from a start date."""
        _export_command(
            ctx,
            lambda client: client.copy_ticks_from(symbol, date_from, count, flags),
        )

### 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`

    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340

    @app.command()
    def ticks_range(
        ctx: typer.Context,
        symbol: Annotated[str, typer.Option(help="Symbol name.")],
        date_from: Annotated[
            datetime,
            typer.Option(click_type=DATETIME_TYPE, help="Start date."),
        ],
        date_to: Annotated[
            datetime,
            typer.Option(click_type=DATETIME_TYPE, help="End date."),
        ],
        flags: Annotated[
            int,
            typer.Option(click_type=TICK_FLAGS_TYPE, help="Tick flags."),
        ],
    ) -> None:
        """Export ticks for a date range."""
        _export_command(
            ctx,
            lambda client: client.copy_ticks_range(symbol, date_from, date_to, flags),
        )

### 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.

Source code in `mt5cli/cli.py`

    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377

    @app.command()
    def ticks_recent(
        ctx: typer.Context,
        symbol: Annotated[str, typer.Option(help="Symbol name.")],
        seconds: Annotated[
            float,
            typer.Option(help="Lookback window in seconds."),
        ],
        date_to: Annotated[
            datetime | None,
            typer.Option(click_type=DATETIME_TYPE, help="Window end date."),
        ] = None,
        count: Annotated[
            int,
            typer.Option(help="Maximum number of ticks to return."),
        ] = 10000,
        flags: Annotated[
            int,
            typer.Option(
                click_type=TICK_FLAGS_TYPE,
                help="Tick flags (ALL, INFO, TRADE, or integer).",
            ),
        ] = "ALL",  # pyright: ignore[reportArgumentType]
    ) -> None:
        """Export ticks from a recent time window."""
        _export_command(
            ctx,
            lambda client: client.recent_ticks(
                symbol,
                seconds,
                date_to=date_to,
                count=count,
                flags=flags,
            ),
        )

### version

    version(ctx: Context) -> None

Export MetaTrader5 version information.

Source code in `mt5cli/cli.py`

    539
    540
    541
    542

    @app.command()
    def version(ctx: typer.Context) -> None:
        """Export MetaTrader5 version information."""
        _export_command(ctx, lambda client: client.version())

#### Search

From here you can search these documents. Enter your search terms below.

#### Keyboard Shortcuts

Keys | Action
--- | ---
`?` | Open this help
`n` | Next page
`p` | Previous page
`s` | Search