mt5cli 0.1.0__tar.gz → 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. mt5cli-0.3.0/.agents/skills/local-qa/SKILL.md +22 -0
  2. mt5cli-0.3.0/.agents/skills/local-qa/scripts/qa.sh +26 -0
  3. mt5cli-0.3.0/.agents/skills/mt5cli/SKILL.md +113 -0
  4. {mt5cli-0.1.0 → mt5cli-0.3.0}/.github/workflows/ci.yml +1 -15
  5. mt5cli-0.3.0/.github/workflows/release.yml +44 -0
  6. mt5cli-0.3.0/PKG-INFO +132 -0
  7. mt5cli-0.3.0/README.md +108 -0
  8. mt5cli-0.3.0/docs/index.md +154 -0
  9. mt5cli-0.3.0/mt5cli/cli.py +1452 -0
  10. {mt5cli-0.1.0 → mt5cli-0.3.0}/pyproject.toml +1 -1
  11. mt5cli-0.3.0/tests/test_cli.py +1632 -0
  12. {mt5cli-0.1.0 → mt5cli-0.3.0}/uv.lock +10 -10
  13. mt5cli-0.1.0/.agents/skills/local-qa/SKILL.md +0 -25
  14. mt5cli-0.1.0/.agents/skills/local-qa/scripts/qa.sh +0 -19
  15. mt5cli-0.1.0/.agents/skills/mt5cli/SKILL.md +0 -104
  16. mt5cli-0.1.0/.github/workflows/release.yml +0 -94
  17. mt5cli-0.1.0/PKG-INFO +0 -109
  18. mt5cli-0.1.0/README.md +0 -85
  19. mt5cli-0.1.0/docs/index.md +0 -117
  20. mt5cli-0.1.0/mt5cli/cli.py +0 -752
  21. mt5cli-0.1.0/tests/test_cli.py +0 -751
  22. {mt5cli-0.1.0 → mt5cli-0.3.0}/.claude/agents/codex.md +0 -0
  23. {mt5cli-0.1.0 → mt5cli-0.3.0}/.claude/settings.json +0 -0
  24. {mt5cli-0.1.0 → mt5cli-0.3.0}/.github/FUNDING.yml +0 -0
  25. {mt5cli-0.1.0 → mt5cli-0.3.0}/.github/dependabot.yml +0 -0
  26. {mt5cli-0.1.0 → mt5cli-0.3.0}/.github/renovate.json +0 -0
  27. {mt5cli-0.1.0 → mt5cli-0.3.0}/.github/workflows/claude.yml +0 -0
  28. {mt5cli-0.1.0 → mt5cli-0.3.0}/.gitignore +0 -0
  29. {mt5cli-0.1.0 → mt5cli-0.3.0}/AGENTS.md +0 -0
  30. {mt5cli-0.1.0 → mt5cli-0.3.0}/CLAUDE.md +0 -0
  31. {mt5cli-0.1.0 → mt5cli-0.3.0}/LICENSE +0 -0
  32. {mt5cli-0.1.0 → mt5cli-0.3.0}/docs/api/cli.md +0 -0
  33. {mt5cli-0.1.0 → mt5cli-0.3.0}/docs/api/index.md +0 -0
  34. {mt5cli-0.1.0 → mt5cli-0.3.0}/mkdocs.yml +0 -0
  35. {mt5cli-0.1.0 → mt5cli-0.3.0}/mt5cli/__init__.py +0 -0
  36. {mt5cli-0.1.0 → mt5cli-0.3.0}/mt5cli/__main__.py +0 -0
  37. {mt5cli-0.1.0 → mt5cli-0.3.0}/tests/__init__.py +0 -0
@@ -0,0 +1,22 @@
1
+ ---
2
+ name: local-qa
3
+ description: Run local QA including formatting, linting, and testing for the repository. Use whenever any file has been updated.
4
+ disable-model-invocation: false
5
+ ---
6
+
7
+ # Local QA (format, lint, and test)
8
+
9
+ Run the local QA script `scripts/qa.sh` in this skill.
10
+
11
+ ## Procedure
12
+
13
+ - Execute the script exactly as shown above when this skill is triggered.
14
+ - Capture and summarize key output (success/failure, major warnings, and any files modified).
15
+ - If the script fails due to missing tooling (`command not found`, missing executable, or equivalent), install the missing tool(s) and rerun `./scripts/qa.sh`.
16
+ - Install tools using this order of preference:
17
+ 1. Use the project's package manager when applicable (`uv`/`poetry` for Python, package manager scripts/dependencies for Node.js).
18
+ 2. Use a system package manager (`brew` on macOS, `apt` on Debian/Ubuntu) when project-local install is not applicable.
19
+ 3. Use language-specific installers as fallback (`pipx`/`pip`, `npm`, `go install`, etc.).
20
+ - If multiple tools are missing, repeat install -> rerun until QA completes or you hit a blocker.
21
+ - If installation fails or requires unavailable privileges, report what was attempted, the exact failure, and stop.
22
+ - Do not run unrelated commands; only run commands needed for QA and missing-tool installation.
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -euox pipefail
4
+ cd "$(git rev-parse --show-toplevel)"
5
+
6
+ # Python
7
+ uv run ruff format .
8
+ uv run ruff check --fix .
9
+ uv run pyright .
10
+ uv run pytest
11
+
12
+ # Markdown
13
+ npx -y prettier --write './**/*.md'
14
+
15
+ # GitHub Actions
16
+ case "${OSTYPE}" in
17
+ darwin* | linux* )
18
+ zizmor --fix=safe .github/workflows
19
+ git ls-files -z -- '.github/workflows/*.yml' | xargs -0 -t actionlint
20
+ git ls-files -z -- '.github/workflows/*.yml' | xargs -0 -t yamllint -d '{"extends": "relaxed", "rules": {"line-length": "disable"}}'
21
+ checkov --framework=all --output=github_failed_only --directory=.
22
+ ;;
23
+ * )
24
+ echo "GitHub Actions linting is only supported on Linux and macOS."
25
+ ;;
26
+ esac
@@ -0,0 +1,113 @@
1
+ ---
2
+ name: mt5cli
3
+ description: Use the `mt5cli` CLI to export MetaTrader 5 data (rates, ticks, account, symbols, orders, positions, history) to CSV, JSON, Parquet, or SQLite3. Invoke when the user asks to export, dump, download, or fetch MT5 market data or account data to a file.
4
+ ---
5
+
6
+ # mt5cli
7
+
8
+ Export MetaTrader 5 data to CSV, JSON, Parquet, or SQLite3 via the `mt5cli`
9
+ command. Output format is auto-detected from the file extension (`.csv`,
10
+ `.json`, `.parquet`/`.pq`, `.db`/`.sqlite`/`.sqlite3`) or overridden with
11
+ `--format/-f`.
12
+
13
+ ## Requirements
14
+
15
+ - Python 3.11+ on Windows with MetaTrader 5 installed (pdmt5 requires the
16
+ MT5 terminal).
17
+ - Install: `pip install -U mt5cli MetaTrader5`.
18
+ - In this repo, run via `uv run mt5cli ...` or `uv run python -m mt5cli ...`.
19
+
20
+ ## Invocation shape
21
+
22
+ ```
23
+ mt5cli [GLOBAL OPTIONS] -o OUTPUT COMMAND [COMMAND OPTIONS]
24
+ ```
25
+
26
+ Global options MUST precede the subcommand.
27
+
28
+ ### Global options (apply to every subcommand)
29
+
30
+ | Option | Purpose |
31
+ | --------------------- | ------------------------------------------------------------- |
32
+ | `-o, --output PATH` | Output file path (required). |
33
+ | `-f, --format FORMAT` | `csv`, `json`, `parquet`, or `sqlite3` (auto from extension). |
34
+ | `--table NAME` | Table name for SQLite3 output (default: `data`). |
35
+ | `--login INT` | MT5 trading account login. |
36
+ | `--password TEXT` | MT5 trading account password. |
37
+ | `--server TEXT` | MT5 trading server name. |
38
+ | `--path TEXT` | Path to MetaTrader 5 terminal EXE. |
39
+ | `--timeout INT` | Connection timeout in milliseconds. |
40
+ | `--log-level LEVEL` | `DEBUG`, `INFO`, `WARNING` (default), `ERROR`. |
41
+
42
+ ### Parameter value formats
43
+
44
+ - **Datetimes** (`--date-from`, `--date-to`): ISO 8601 (`2024-01-01` or
45
+ `2024-01-01T12:00:00+00:00`). Naive values are treated as UTC.
46
+ - **Timeframe** (`--timeframe`): `M1`, `M2`, `M3`, `M4`, `M5`, `M6`, `M10`,
47
+ `M12`, `M15`, `M20`, `M30`, `H1`, `H2`, `H3`, `H4`, `H6`, `H8`, `H12`,
48
+ `D1`, `W1`, `MN1`, or the raw integer.
49
+ - **Tick flags** (`--flags`): `ALL`, `INFO`, `TRADE`, or the raw integer.
50
+
51
+ ## Commands
52
+
53
+ | Command | Required options | Optional options |
54
+ | ----------------- | ----------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
55
+ | `rates-from` | `--symbol`, `--timeframe`, `--date-from`, `--count` | — |
56
+ | `rates-from-pos` | `--symbol`, `--timeframe`, `--start-pos`, `--count` | — |
57
+ | `rates-range` | `--symbol`, `--timeframe`, `--date-from`, `--date-to` | — |
58
+ | `ticks-from` | `--symbol`, `--date-from`, `--count`, `--flags` | — |
59
+ | `ticks-range` | `--symbol`, `--date-from`, `--date-to`, `--flags` | — |
60
+ | `account-info` | — | — |
61
+ | `terminal-info` | — | — |
62
+ | `symbols` | — | `--group` (e.g., `*USD*`) |
63
+ | `symbol-info` | `--symbol` | — |
64
+ | `orders` | — | `--symbol`, `--group`, `--ticket` |
65
+ | `positions` | — | `--symbol`, `--group`, `--ticket` |
66
+ | `history-orders` | — | `--date-from`, `--date-to`, `--group`, `--symbol`, `--ticket`, `--position` |
67
+ | `history-deals` | — | `--date-from`, `--date-to`, `--group`, `--symbol`, `--ticket`, `--position` |
68
+ | `collect-history` | `--symbol` (repeatable), `--date-from`, `--date-to` | `--dataset` (repeatable; rates/ticks/history-orders/history-deals; default all), `--timeframe` (M1; recorded on rates), `--flags` (ALL), `--if-exists` (append/replace/fail; default fail), `--with-views` (SQLite3 output only) |
69
+
70
+ ## Examples
71
+
72
+ ```bash
73
+ # Account snapshot as CSV.
74
+ mt5cli -o account.csv account-info
75
+
76
+ # EURUSD M1 bars (1000 rows) from a start date to Parquet.
77
+ mt5cli -o rates.parquet rates-from \
78
+ --symbol EURUSD --timeframe M1 --date-from 2024-01-01 --count 1000
79
+
80
+ # EURUSD tick stream for a date range to JSON.
81
+ mt5cli -o ticks.json ticks-range \
82
+ --symbol EURUSD --date-from 2024-01-01 --date-to 2024-01-02 --flags ALL
83
+
84
+ # USD symbols into a named table in SQLite3.
85
+ mt5cli -o data.db --table symbols symbols --group "*USD*"
86
+
87
+ # Historical deals filtered by symbol (using an already-logged-in MT5 terminal).
88
+ mt5cli -o deals.csv history-deals --symbol EURUSD --date-from 2024-01-01
89
+
90
+ # Bundle selected historical datasets into one SQLite db, appending to any
91
+ # existing tables, plus cash_events and positions_reconstructed views.
92
+ mt5cli -o history.db collect-history \
93
+ --symbol EURUSD --symbol GBPUSD \
94
+ --date-from 2024-01-01 --date-to 2024-02-01 \
95
+ --dataset rates --dataset history-deals \
96
+ --timeframe M1 --flags ALL --if-exists append --with-views
97
+ ```
98
+
99
+ ## Guidelines
100
+
101
+ - Pick the output extension to avoid passing `--format`.
102
+ - Use `--table` only with SQLite3 outputs; it is otherwise ignored.
103
+ - `--count` is required for `rates-from`, `rates-from-pos`, and `ticks-from`.
104
+ Prefer `rates-range` / `ticks-range` when a fixed window is known.
105
+ - Credentials (`--login`, `--password`, `--server`) are optional when the
106
+ local MT5 terminal is already logged in.
107
+ - Avoid passing `--password` on the command line in shared or logged
108
+ environments — it is visible in `ps`, shell history, and CI logs. Prefer
109
+ logging in through the MT5 terminal first, then omit credentials here.
110
+ - Reach for `--log-level DEBUG` when a command fails silently — MT5
111
+ connection errors surface there.
112
+ - If the user asks to run from source in this repo, prefix with `uv run`
113
+ (e.g., `uv run mt5cli -o out.csv account-info`).
@@ -35,7 +35,7 @@ jobs:
35
35
  || (github.event_name == 'workflow_dispatch' && inputs.workflow == 'lint-and-test')
36
36
  permissions:
37
37
  contents: read
38
- uses: dceoy/gh-actions-for-devops/.github/workflows/python-package-lint-and-scan.yml@main # zizmor: ignore[unpinned-uses]
38
+ uses: dceoy/gh-actions-for-devops/.github/workflows/python-package-lint-and-scan.yml@main # zizmor: ignore[unpinned-uses]
39
39
  with:
40
40
  package-path: .
41
41
  runs-on: windows-latest
@@ -59,23 +59,9 @@ jobs:
59
59
  uses: dceoy/gh-actions-for-devops/.github/workflows/python-package-mkdocs-gh-deploy.yml@main # zizmor: ignore[unpinned-uses]
60
60
  with:
61
61
  package-path: .
62
- mkdocs-theme: material
63
62
  runs-on: ubuntu-slim
64
63
  secrets:
65
64
  GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
66
- python-package-release:
67
- if: >
68
- github.event_name == 'push'
69
- || (github.event_name == 'workflow_dispatch' && inputs.workflow == 'lint-and-test')
70
- permissions:
71
- contents: write
72
- id-token: write
73
- uses: dceoy/gh-actions-for-devops/.github/workflows/python-package-release-on-pypi-and-github.yml@main # zizmor: ignore[unpinned-uses]
74
- with:
75
- package-path: .
76
- create-releases: false
77
- secrets:
78
- GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
79
65
  dependabot-auto-merge:
80
66
  if: >
81
67
  github.event_name == 'pull_request' && github.actor == 'dependabot[bot]'
@@ -0,0 +1,44 @@
1
+ ---
2
+ name: Release
3
+ on:
4
+ workflow_dispatch:
5
+ permissions:
6
+ contents: read
7
+ defaults:
8
+ run:
9
+ shell: bash -euo pipefail {0}
10
+ working-directory: .
11
+ jobs:
12
+ build-and-release:
13
+ permissions:
14
+ contents: write
15
+ id-token: write
16
+ uses: dceoy/gh-actions-for-devops/.github/workflows/python-package-release-on-pypi-and-github.yml@main # zizmor: ignore[unpinned-uses]
17
+ with:
18
+ package-path: .
19
+ create-github-release: true
20
+ publish-to-pypi: false
21
+ secrets:
22
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23
+ publish-to-pypi:
24
+ name: Publish the Python 🐍 distribution 📦 to PyPI
25
+ if: >
26
+ startsWith(github.ref, 'refs/tags/')
27
+ needs:
28
+ - build-and-release
29
+ runs-on: ubuntu-latest
30
+ environment:
31
+ name: pypi
32
+ url: https://pypi.org/p/${{ needs.build-and-release.outputs.project-name }}
33
+ permissions:
34
+ id-token: write # IMPORTANT: mandatory for trusted publishing
35
+ steps:
36
+ - name: Download all the dists
37
+ uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
38
+ with:
39
+ name: ${{ needs.build-and-release.outputs.distribution-artifact-name }}
40
+ path: dist/
41
+ - name: Publish distribution 📦 to PyPI
42
+ uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0
43
+ with:
44
+ verbose: true
mt5cli-0.3.0/PKG-INFO ADDED
@@ -0,0 +1,132 @@
1
+ Metadata-Version: 2.4
2
+ Name: mt5cli
3
+ Version: 0.3.0
4
+ Summary: Command-line tool for MetaTrader 5
5
+ Project-URL: Repository, https://github.com/dceoy/mt5cli.git
6
+ Author-email: dceoy <dceoy@users.noreply.github.com>
7
+ Maintainer-email: dceoy <dceoy@users.noreply.github.com>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Financial and Insurance Industry
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Operating System :: Microsoft :: Windows
15
+ Classifier: Programming Language :: Python
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Topic :: Office/Business :: Financial :: Investment
18
+ Requires-Python: <3.14,>=3.11
19
+ Requires-Dist: click>=8.1.0
20
+ Requires-Dist: pdmt5>=0.2.3
21
+ Requires-Dist: pyarrow>=19.0.0
22
+ Requires-Dist: typer>=0.15.0
23
+ Description-Content-Type: text/markdown
24
+
25
+ # mt5cli
26
+
27
+ [![CI/CD](https://github.com/dceoy/mt5cli/actions/workflows/ci.yml/badge.svg)](https://github.com/dceoy/mt5cli/actions/workflows/ci.yml)
28
+
29
+ Command-line tool for exporting MetaTrader 5 data to CSV, JSON, Parquet, and SQLite3.
30
+
31
+ Built on top of [pdmt5](https://github.com/dceoy/pdmt5), a pandas-based data handler for MetaTrader 5.
32
+
33
+ ## Features
34
+
35
+ - **Multi-format export**: CSV, JSON, Parquet, and SQLite3 output formats
36
+ - **Auto-detection**: Format detection from file extensions
37
+ - **Comprehensive data access**: Rates, ticks, account info, symbols, orders, positions, and trading history
38
+ - **Flexible timeframes**: Named timeframes (M1, H1, D1, etc.) and numeric values
39
+ - **Connection management**: Optional credentials, server, and timeout configuration
40
+
41
+ ## Installation
42
+
43
+ ```bash
44
+ pip install -U mt5cli MetaTrader5
45
+ ```
46
+
47
+ ## Usage
48
+
49
+ ```bash
50
+ # Export account information to CSV
51
+ mt5cli -o account.csv account-info
52
+
53
+ # Export EURUSD M1 rates to Parquet
54
+ mt5cli -o rates.parquet rates-from --symbol EURUSD --timeframe M1 \
55
+ --date-from 2024-01-01 --count 1000
56
+
57
+ # Export ticks to JSON
58
+ mt5cli -o ticks.json ticks-from --symbol EURUSD \
59
+ --date-from 2024-01-01 --count 500 --flags ALL
60
+
61
+ # Export symbols to SQLite3 with custom table name
62
+ mt5cli -o data.db --table symbols symbols --group "*USD*"
63
+
64
+ # Export with connection credentials
65
+ mt5cli --login 12345 --password mypass --server MyBroker-Demo \
66
+ -o positions.csv positions
67
+ ```
68
+
69
+ Run as a Python module:
70
+
71
+ ```bash
72
+ python -m mt5cli -o account.csv account-info
73
+ ```
74
+
75
+ ## Commands
76
+
77
+ | Command | Description |
78
+ | ------------------ | ------------------------------------------------------------------------------------------------------------ |
79
+ | `rates-from` | Export rates from a start date |
80
+ | `rates-from-pos` | Export rates from a start position |
81
+ | `rates-range` | Export rates for a date range |
82
+ | `ticks-from` | Export ticks from a start date |
83
+ | `ticks-range` | Export ticks for a date range |
84
+ | `account-info` | Export account information |
85
+ | `terminal-info` | Export terminal information |
86
+ | `version` | Export MetaTrader 5 version information |
87
+ | `last-error` | Export the last error information |
88
+ | `symbols` | Export symbol list |
89
+ | `symbol-info` | Export symbol details |
90
+ | `symbol-info-tick` | Export the last tick for a symbol |
91
+ | `market-book` | Export market depth (order book) |
92
+ | `orders` | Export active orders |
93
+ | `positions` | Export open positions |
94
+ | `history-orders` | Export historical orders |
95
+ | `history-deals` | Export historical deals |
96
+ | `order-check` | Check funds sufficiency for a trade request |
97
+ | `order-send` | Send a trade request to the trade server (`--yes` required) |
98
+ | `collect-history` | Bundle rates, ticks, history-orders, and history-deals for one or more symbols into a single SQLite database |
99
+
100
+ Use `order-check` to validate a request payload before running `order-send --yes`.
101
+
102
+ ### `collect-history`
103
+
104
+ Collect several historical datasets per symbol into one SQLite database in a single MT5 session. Pick datasets with repeatable `--dataset` (default: all four), choose conflict behavior with `--if-exists append|replace|fail` (default: `fail`), and optionally derive `cash_events` / `positions_reconstructed` views from `history_deals` via `--with-views`.
105
+
106
+ ```bash
107
+ mt5cli -o history.db collect-history \
108
+ --symbol EURUSD --symbol GBPUSD \
109
+ --date-from 2024-01-01 --date-to 2024-02-01 \
110
+ --dataset rates --dataset history-deals \
111
+ --timeframe M1 --flags ALL --if-exists append --with-views
112
+ ```
113
+
114
+ History orders and deals are fetched per symbol and concatenated, so the symbol filter is applied consistently across all datasets. The `cash_events` view is derived from symbol-filtered `history_deals`, so account-level cash events with empty or non-matching symbols may be excluded. The `rates` table records the requested `timeframe` so appended runs at different timeframes remain distinguishable. The `positions_reconstructed` view aggregates trade deals by `position_id`, excludes positions without closing deals, and uses volume-weighted open/close prices; reversal deals (`DEAL_ENTRY_INOUT`) are reported via `volume_reversal` / `reversal_count` columns and do not contribute to the weighted prices.
115
+
116
+ ## Requirements
117
+
118
+ - Python 3.11+
119
+ - Windows OS (MetaTrader 5 requirement)
120
+ - MetaTrader 5 platform installed
121
+
122
+ ## Development
123
+
124
+ ```bash
125
+ git clone https://github.com/dceoy/mt5cli.git
126
+ cd mt5cli
127
+ uv sync
128
+ ```
129
+
130
+ ## License
131
+
132
+ [MIT](LICENSE)
mt5cli-0.3.0/README.md ADDED
@@ -0,0 +1,108 @@
1
+ # mt5cli
2
+
3
+ [![CI/CD](https://github.com/dceoy/mt5cli/actions/workflows/ci.yml/badge.svg)](https://github.com/dceoy/mt5cli/actions/workflows/ci.yml)
4
+
5
+ Command-line tool for exporting MetaTrader 5 data to CSV, JSON, Parquet, and SQLite3.
6
+
7
+ Built on top of [pdmt5](https://github.com/dceoy/pdmt5), a pandas-based data handler for MetaTrader 5.
8
+
9
+ ## Features
10
+
11
+ - **Multi-format export**: CSV, JSON, Parquet, and SQLite3 output formats
12
+ - **Auto-detection**: Format detection from file extensions
13
+ - **Comprehensive data access**: Rates, ticks, account info, symbols, orders, positions, and trading history
14
+ - **Flexible timeframes**: Named timeframes (M1, H1, D1, etc.) and numeric values
15
+ - **Connection management**: Optional credentials, server, and timeout configuration
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ pip install -U mt5cli MetaTrader5
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ```bash
26
+ # Export account information to CSV
27
+ mt5cli -o account.csv account-info
28
+
29
+ # Export EURUSD M1 rates to Parquet
30
+ mt5cli -o rates.parquet rates-from --symbol EURUSD --timeframe M1 \
31
+ --date-from 2024-01-01 --count 1000
32
+
33
+ # Export ticks to JSON
34
+ mt5cli -o ticks.json ticks-from --symbol EURUSD \
35
+ --date-from 2024-01-01 --count 500 --flags ALL
36
+
37
+ # Export symbols to SQLite3 with custom table name
38
+ mt5cli -o data.db --table symbols symbols --group "*USD*"
39
+
40
+ # Export with connection credentials
41
+ mt5cli --login 12345 --password mypass --server MyBroker-Demo \
42
+ -o positions.csv positions
43
+ ```
44
+
45
+ Run as a Python module:
46
+
47
+ ```bash
48
+ python -m mt5cli -o account.csv account-info
49
+ ```
50
+
51
+ ## Commands
52
+
53
+ | Command | Description |
54
+ | ------------------ | ------------------------------------------------------------------------------------------------------------ |
55
+ | `rates-from` | Export rates from a start date |
56
+ | `rates-from-pos` | Export rates from a start position |
57
+ | `rates-range` | Export rates for a date range |
58
+ | `ticks-from` | Export ticks from a start date |
59
+ | `ticks-range` | Export ticks for a date range |
60
+ | `account-info` | Export account information |
61
+ | `terminal-info` | Export terminal information |
62
+ | `version` | Export MetaTrader 5 version information |
63
+ | `last-error` | Export the last error information |
64
+ | `symbols` | Export symbol list |
65
+ | `symbol-info` | Export symbol details |
66
+ | `symbol-info-tick` | Export the last tick for a symbol |
67
+ | `market-book` | Export market depth (order book) |
68
+ | `orders` | Export active orders |
69
+ | `positions` | Export open positions |
70
+ | `history-orders` | Export historical orders |
71
+ | `history-deals` | Export historical deals |
72
+ | `order-check` | Check funds sufficiency for a trade request |
73
+ | `order-send` | Send a trade request to the trade server (`--yes` required) |
74
+ | `collect-history` | Bundle rates, ticks, history-orders, and history-deals for one or more symbols into a single SQLite database |
75
+
76
+ Use `order-check` to validate a request payload before running `order-send --yes`.
77
+
78
+ ### `collect-history`
79
+
80
+ Collect several historical datasets per symbol into one SQLite database in a single MT5 session. Pick datasets with repeatable `--dataset` (default: all four), choose conflict behavior with `--if-exists append|replace|fail` (default: `fail`), and optionally derive `cash_events` / `positions_reconstructed` views from `history_deals` via `--with-views`.
81
+
82
+ ```bash
83
+ mt5cli -o history.db collect-history \
84
+ --symbol EURUSD --symbol GBPUSD \
85
+ --date-from 2024-01-01 --date-to 2024-02-01 \
86
+ --dataset rates --dataset history-deals \
87
+ --timeframe M1 --flags ALL --if-exists append --with-views
88
+ ```
89
+
90
+ History orders and deals are fetched per symbol and concatenated, so the symbol filter is applied consistently across all datasets. The `cash_events` view is derived from symbol-filtered `history_deals`, so account-level cash events with empty or non-matching symbols may be excluded. The `rates` table records the requested `timeframe` so appended runs at different timeframes remain distinguishable. The `positions_reconstructed` view aggregates trade deals by `position_id`, excludes positions without closing deals, and uses volume-weighted open/close prices; reversal deals (`DEAL_ENTRY_INOUT`) are reported via `volume_reversal` / `reversal_count` columns and do not contribute to the weighted prices.
91
+
92
+ ## Requirements
93
+
94
+ - Python 3.11+
95
+ - Windows OS (MetaTrader 5 requirement)
96
+ - MetaTrader 5 platform installed
97
+
98
+ ## Development
99
+
100
+ ```bash
101
+ git clone https://github.com/dceoy/mt5cli.git
102
+ cd mt5cli
103
+ uv sync
104
+ ```
105
+
106
+ ## License
107
+
108
+ [MIT](LICENSE)
@@ -0,0 +1,154 @@
1
+ # mt5cli
2
+
3
+ Command-line tool for MetaTrader 5 data export.
4
+
5
+ ## Overview
6
+
7
+ mt5cli is a CLI application that exports MetaTrader 5 trading data to multiple file formats. It is built on top of [pdmt5](https://github.com/dceoy/pdmt5), a pandas-based data handler for MetaTrader 5.
8
+
9
+ ## Features
10
+
11
+ - **Multi-format export**: CSV, JSON, Parquet, and SQLite3 output formats
12
+ - **Auto-detection**: Format detection from file extensions
13
+ - **Comprehensive data access**: Rates, ticks, account info, symbols, orders, positions, and trading history
14
+ - **Flexible timeframes**: Named timeframes (M1, H1, D1, etc.) and numeric values
15
+ - **Connection management**: Optional credentials, server, and timeout configuration
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ pip install mt5cli
21
+ ```
22
+
23
+ ## Quick Start
24
+
25
+ ```bash
26
+ # Export account information to CSV
27
+ mt5cli -o account.csv account-info
28
+
29
+ # Export EURUSD M1 rates to Parquet
30
+ mt5cli -o rates.parquet rates-from --symbol EURUSD --timeframe M1 \
31
+ --date-from 2024-01-01 --count 1000
32
+
33
+ # Export ticks to JSON
34
+ mt5cli -o ticks.json ticks-from --symbol EURUSD \
35
+ --date-from 2024-01-01 --count 500 --flags ALL
36
+
37
+ # Export symbols to SQLite3 with custom table name
38
+ mt5cli -o data.db --table symbols symbols --group "*USD*"
39
+
40
+ # Export with connection credentials
41
+ mt5cli --login 12345 --password mypass --server MyBroker-Demo \
42
+ -o positions.csv positions
43
+ ```
44
+
45
+ ## Commands
46
+
47
+ ### Rates
48
+
49
+ | Command | Description |
50
+ | ---------------- | ---------------------------------- |
51
+ | `rates-from` | Export rates from a start date |
52
+ | `rates-from-pos` | Export rates from a start position |
53
+ | `rates-range` | Export rates for a date range |
54
+
55
+ ### Ticks
56
+
57
+ | Command | Description |
58
+ | ------------- | ------------------------------ |
59
+ | `ticks-from` | Export ticks from a start date |
60
+ | `ticks-range` | Export ticks for a date range |
61
+
62
+ ### Information
63
+
64
+ | Command | Description |
65
+ | ------------------ | --------------------------------------- |
66
+ | `account-info` | Export account information |
67
+ | `terminal-info` | Export terminal information |
68
+ | `version` | Export MetaTrader 5 version information |
69
+ | `last-error` | Export the last error information |
70
+ | `symbols` | Export symbol list |
71
+ | `symbol-info` | Export symbol details |
72
+ | `symbol-info-tick` | Export the last tick for a symbol |
73
+ | `market-book` | Export market depth (order book) |
74
+
75
+ ### Trading
76
+
77
+ | Command | Description |
78
+ | ---------------- | ----------------------------------------------------------- |
79
+ | `orders` | Export active orders |
80
+ | `positions` | Export open positions |
81
+ | `history-orders` | Export historical orders |
82
+ | `history-deals` | Export historical deals |
83
+ | `order-check` | Check funds sufficiency for a trade request |
84
+ | `order-send` | Send a trade request to the trade server (`--yes` required) |
85
+
86
+ Use `order-check` to validate a request payload before running `order-send --yes`.
87
+
88
+ ### Bulk Collection
89
+
90
+ | Command | Description |
91
+ | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
92
+ | `collect-history` | Collect rates, ticks, history-orders, and history-deals for one or more symbols into a single SQLite database (optional cash-event/position views) |
93
+
94
+ ```bash
95
+ mt5cli -o history.db collect-history \
96
+ --symbol EURUSD --symbol GBPUSD \
97
+ --date-from 2024-01-01 --date-to 2024-02-01 \
98
+ --dataset rates --dataset history-deals \
99
+ --timeframe M1 --flags ALL --if-exists append --with-views
100
+ ```
101
+
102
+ `collect-history` options:
103
+
104
+ | Option | Default | Description |
105
+ | -------------- | ---------- | --------------------------------------------------------------------------------------------- |
106
+ | `--symbol/-s` | _required_ | Symbol to collect (repeat for multiple). |
107
+ | `--date-from` | _required_ | Start date in ISO 8601. |
108
+ | `--date-to` | _required_ | End date in ISO 8601. |
109
+ | `--dataset` | all four | Repeatable: `rates`, `ticks`, `history-orders`, `history-deals`. |
110
+ | `--timeframe` | `M1` | Rates timeframe; recorded in a `timeframe` column on the `rates` table. |
111
+ | `--flags` | `ALL` | Tick copy flags forwarded to `copy_ticks_range`. |
112
+ | `--if-exists` | `fail` | `append`, `replace`, or `fail` when a target table already exists. |
113
+ | `--with-views` | off | Add `cash_events` and `positions_reconstructed` views (requires the `history-deals` dataset). |
114
+
115
+ History orders and deals are fetched per symbol and concatenated, so the symbol filter is applied consistently across all datasets. The `cash_events` view is derived from symbol-filtered `history_deals`, so account-level cash events with empty or non-matching symbols may be excluded. The `positions_reconstructed` view excludes positions with no closing deal, uses volume-weighted open/close prices, and reports reversal deals (`DEAL_ENTRY_INOUT`) via `volume_reversal` / `reversal_count`.
116
+
117
+ ## Global Options
118
+
119
+ | Option | Description |
120
+ | -------------- | ------------------------------------------------------- |
121
+ | `-o, --output` | Output file path (required) |
122
+ | `-f, --format` | Output format (auto-detected from extension if omitted) |
123
+ | `--table` | Table name for SQLite3 output (default: "data") |
124
+ | `--login` | Trading account login |
125
+ | `--password` | Trading account password |
126
+ | `--server` | Trading server name |
127
+ | `--path` | Path to MetaTrader5 terminal EXE file |
128
+ | `--timeout` | Connection timeout in milliseconds |
129
+ | `--log-level` | Logging level (DEBUG, INFO, WARNING, ERROR) |
130
+
131
+ ## Requirements
132
+
133
+ - Python 3.11+
134
+ - Windows OS (MetaTrader 5 requirement)
135
+ - MetaTrader 5 platform
136
+
137
+ ## API Reference
138
+
139
+ Browse the API documentation for detailed module information:
140
+
141
+ - [CLI Module](api/cli.md) - CLI application with export commands and utility functions
142
+
143
+ ## Development
144
+
145
+ This project follows strict code quality standards:
146
+
147
+ - Type hints required (strict mode)
148
+ - Comprehensive linting with Ruff
149
+ - Test coverage tracking
150
+ - Google-style docstrings
151
+
152
+ ## License
153
+
154
+ MIT License - see [LICENSE](https://github.com/dceoy/mt5cli/blob/main/LICENSE) file for details.