mt5cli 0.4.3__tar.gz → 0.5.1__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.
- {mt5cli-0.4.3 → mt5cli-0.5.1}/PKG-INFO +34 -26
- {mt5cli-0.4.3 → mt5cli-0.5.1}/README.md +33 -25
- {mt5cli-0.4.3 → mt5cli-0.5.1}/docs/api/history.md +51 -0
- {mt5cli-0.4.3 → mt5cli-0.5.1}/docs/index.md +20 -9
- {mt5cli-0.4.3 → mt5cli-0.5.1}/mt5cli/__init__.py +52 -0
- {mt5cli-0.4.3 → mt5cli-0.5.1}/mt5cli/cli.py +56 -0
- {mt5cli-0.4.3 → mt5cli-0.5.1}/mt5cli/history.py +369 -9
- {mt5cli-0.4.3 → mt5cli-0.5.1}/mt5cli/sdk.py +371 -5
- {mt5cli-0.4.3 → mt5cli-0.5.1}/pyproject.toml +1 -1
- {mt5cli-0.4.3 → mt5cli-0.5.1}/tests/test_cli.py +113 -0
- {mt5cli-0.4.3 → mt5cli-0.5.1}/tests/test_history.py +466 -0
- {mt5cli-0.4.3 → mt5cli-0.5.1}/tests/test_sdk.py +447 -2
- {mt5cli-0.4.3 → mt5cli-0.5.1}/uv.lock +1 -1
- {mt5cli-0.4.3 → mt5cli-0.5.1}/.agents/skills/local-qa/SKILL.md +0 -0
- {mt5cli-0.4.3 → mt5cli-0.5.1}/.agents/skills/local-qa/scripts/qa.sh +0 -0
- {mt5cli-0.4.3 → mt5cli-0.5.1}/.agents/skills/mt5cli/SKILL.md +0 -0
- {mt5cli-0.4.3 → mt5cli-0.5.1}/.claude/agents/codex.md +0 -0
- {mt5cli-0.4.3 → mt5cli-0.5.1}/.claude/settings.json +0 -0
- {mt5cli-0.4.3 → mt5cli-0.5.1}/.github/FUNDING.yml +0 -0
- {mt5cli-0.4.3 → mt5cli-0.5.1}/.github/dependabot.yml +0 -0
- {mt5cli-0.4.3 → mt5cli-0.5.1}/.github/renovate.json +0 -0
- {mt5cli-0.4.3 → mt5cli-0.5.1}/.github/workflows/ci.yml +0 -0
- {mt5cli-0.4.3 → mt5cli-0.5.1}/.github/workflows/claude.yml +0 -0
- {mt5cli-0.4.3 → mt5cli-0.5.1}/.github/workflows/release.yml +0 -0
- {mt5cli-0.4.3 → mt5cli-0.5.1}/.gitignore +0 -0
- {mt5cli-0.4.3 → mt5cli-0.5.1}/AGENTS.md +0 -0
- {mt5cli-0.4.3 → mt5cli-0.5.1}/CLAUDE.md +0 -0
- {mt5cli-0.4.3 → mt5cli-0.5.1}/LICENSE +0 -0
- {mt5cli-0.4.3 → mt5cli-0.5.1}/docs/api/cli.md +0 -0
- {mt5cli-0.4.3 → mt5cli-0.5.1}/docs/api/index.md +0 -0
- {mt5cli-0.4.3 → mt5cli-0.5.1}/docs/api/sdk.md +0 -0
- {mt5cli-0.4.3 → mt5cli-0.5.1}/docs/api/utils.md +0 -0
- {mt5cli-0.4.3 → mt5cli-0.5.1}/mkdocs.yml +0 -0
- {mt5cli-0.4.3 → mt5cli-0.5.1}/mt5cli/__main__.py +0 -0
- {mt5cli-0.4.3 → mt5cli-0.5.1}/mt5cli/utils.py +0 -0
- {mt5cli-0.4.3 → mt5cli-0.5.1}/tests/__init__.py +0 -0
- {mt5cli-0.4.3 → mt5cli-0.5.1}/tests/test_utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mt5cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.1
|
|
4
4
|
Summary: Command-line tool for MetaTrader 5
|
|
5
5
|
Project-URL: Repository, https://github.com/dceoy/mt5cli.git
|
|
6
6
|
Author-email: dceoy <dceoy@users.noreply.github.com>
|
|
@@ -37,6 +37,7 @@ Built on top of [pdmt5](https://github.com/dceoy/pdmt5), a pandas-based data han
|
|
|
37
37
|
- **Comprehensive data access**: Rates, ticks, account info, symbols, orders, positions, and trading history
|
|
38
38
|
- **Flexible timeframes**: Named timeframes (M1, H1, D1, etc.) and numeric values
|
|
39
39
|
- **Connection management**: Optional credentials, server, and timeout configuration
|
|
40
|
+
- **SQLite rate loading**: Load mt5cli-managed rate tables/views for offline workflows
|
|
40
41
|
|
|
41
42
|
## Installation
|
|
42
43
|
|
|
@@ -74,30 +75,33 @@ python -m mt5cli -o account.csv account-info
|
|
|
74
75
|
|
|
75
76
|
## Commands
|
|
76
77
|
|
|
77
|
-
| Command
|
|
78
|
-
|
|
|
79
|
-
| `rates-from`
|
|
80
|
-
| `rates-from-pos`
|
|
81
|
-
| `rates
|
|
82
|
-
| `
|
|
83
|
-
| `ticks-
|
|
84
|
-
| `ticks-
|
|
85
|
-
| `
|
|
86
|
-
| `
|
|
87
|
-
| `
|
|
88
|
-
| `
|
|
89
|
-
| `
|
|
90
|
-
| `
|
|
91
|
-
| `symbol-info
|
|
92
|
-
| `
|
|
93
|
-
| `
|
|
94
|
-
| `
|
|
95
|
-
| `
|
|
96
|
-
| `
|
|
97
|
-
| `history-
|
|
98
|
-
| `
|
|
99
|
-
| `
|
|
100
|
-
| `
|
|
78
|
+
| Command | Description |
|
|
79
|
+
| ---------------------- | ------------------------------------------------------------------------------------------------------------ |
|
|
80
|
+
| `rates-from` | Export rates from a start date |
|
|
81
|
+
| `rates-from-pos` | Export rates from a start position |
|
|
82
|
+
| `latest-rates` | Export latest rates from a start position |
|
|
83
|
+
| `rates-range` | Export rates for a date range |
|
|
84
|
+
| `ticks-from` | Export ticks from a start date |
|
|
85
|
+
| `ticks-range` | Export ticks for a date range |
|
|
86
|
+
| `ticks-recent` | Export ticks from a recent trailing window |
|
|
87
|
+
| `account-info` | Export account information |
|
|
88
|
+
| `terminal-info` | Export terminal information |
|
|
89
|
+
| `version` | Export MetaTrader 5 version information |
|
|
90
|
+
| `last-error` | Export the last error information |
|
|
91
|
+
| `symbols` | Export symbol list |
|
|
92
|
+
| `symbol-info` | Export symbol details |
|
|
93
|
+
| `symbol-info-tick` | Export the last tick for a symbol |
|
|
94
|
+
| `minimum-margins` | Export minimum-volume buy and sell margin requirements |
|
|
95
|
+
| `market-book` | Export market depth (order book) |
|
|
96
|
+
| `orders` | Export active orders |
|
|
97
|
+
| `positions` | Export open positions |
|
|
98
|
+
| `history-orders` | Export historical orders |
|
|
99
|
+
| `history-deals` | Export historical deals |
|
|
100
|
+
| `recent-history-deals` | Export historical deals from a recent trailing window |
|
|
101
|
+
| `mt5-summary` | Export terminal/account status summary |
|
|
102
|
+
| `order-check` | Check funds sufficiency for a trade request |
|
|
103
|
+
| `order-send` | Send a trade request to the trade server (`--yes` required) |
|
|
104
|
+
| `collect-history` | Bundle rates, ticks, history-orders, and history-deals for one or more symbols into a single SQLite database |
|
|
101
105
|
|
|
102
106
|
Use `order-check` to validate a request payload before running `order-send --yes`.
|
|
103
107
|
|
|
@@ -153,7 +157,11 @@ update_history_with_config(
|
|
|
153
157
|
- **`update_history`**: incremental append based on existing SQLite `MAX(time)` per symbol (and timeframe for rates); account-level deals use a separate cursor when `include_account_events=True`.
|
|
154
158
|
- **`rates` table**: normalized storage with `symbol` and `timeframe` columns.
|
|
155
159
|
- **Rate compatibility views**: mt5cli manages all `rate_*` views. Naming is `rate_<symbol>__<timeframe>` when a symbol has one timeframe, otherwise `rate_<symbol>__<granularity>_<timeframe>` (for example `rate_EURUSD__M1_1`). Stale `rate_*` views are dropped and recreated when rates change for offline tools such as mteor optimize.
|
|
156
|
-
- **Rate view resolution**: use `
|
|
160
|
+
- **Rate view resolution**: use `resolve_rate_view_name()` / `resolve_rate_view_names()` to map symbols and granularities to existing SQLite compatibility views without creating databases. Both accept `None` (or a missing path) and return deterministic default names unless `require_existing=True`.
|
|
161
|
+
- **Rate view loading**: use `load_rate_data()` / `load_rate_data_from_connection()` to load a SQLite rate table or view into a `DatetimeIndex` DataFrame.
|
|
162
|
+
- **Multi-series rate loading**: use `build_rate_targets()` to build neutral `RateTarget(symbol, timeframe)` pairs, `resolve_rate_tables()` to map them to table/view names (pass `require_existing=True` for strict resolution), and `load_rate_series_from_sqlite()` to load them into a mapping keyed by `(symbol, integer timeframe)`. The loader requires existing managed views unless `explicit_tables` is supplied, and rejects duplicate `(symbol, timeframe)` targets.
|
|
163
|
+
- **Multi-account latest rates**: use `collect_latest_rates_for_accounts()` with `AccountSpec` to read the latest bars for several account groups, merged into a `(symbol, integer timeframe)` mapping.
|
|
164
|
+
- **MT5 session helper**: use the `mt5_session()` context manager to attach to (or, when `Mt5Config.path` is set, launch) an MT5 terminal, log in, and yield a connected `Mt5CliClient` that shuts down on exit.
|
|
157
165
|
- **SQLite export helpers**: use `export_dataframe_to_sqlite()` for append mode, optional index export, and post-write deduplication by key columns.
|
|
158
166
|
- **Recent ticks and margins**: `recent_ticks()` and `minimum_margins()` SDK helpers (and matching CLI commands) cover common downstream read-only queries.
|
|
159
167
|
|
|
@@ -13,6 +13,7 @@ Built on top of [pdmt5](https://github.com/dceoy/pdmt5), a pandas-based data han
|
|
|
13
13
|
- **Comprehensive data access**: Rates, ticks, account info, symbols, orders, positions, and trading history
|
|
14
14
|
- **Flexible timeframes**: Named timeframes (M1, H1, D1, etc.) and numeric values
|
|
15
15
|
- **Connection management**: Optional credentials, server, and timeout configuration
|
|
16
|
+
- **SQLite rate loading**: Load mt5cli-managed rate tables/views for offline workflows
|
|
16
17
|
|
|
17
18
|
## Installation
|
|
18
19
|
|
|
@@ -50,30 +51,33 @@ python -m mt5cli -o account.csv account-info
|
|
|
50
51
|
|
|
51
52
|
## Commands
|
|
52
53
|
|
|
53
|
-
| Command
|
|
54
|
-
|
|
|
55
|
-
| `rates-from`
|
|
56
|
-
| `rates-from-pos`
|
|
57
|
-
| `rates
|
|
58
|
-
| `
|
|
59
|
-
| `ticks-
|
|
60
|
-
| `ticks-
|
|
61
|
-
| `
|
|
62
|
-
| `
|
|
63
|
-
| `
|
|
64
|
-
| `
|
|
65
|
-
| `
|
|
66
|
-
| `
|
|
67
|
-
| `symbol-info
|
|
68
|
-
| `
|
|
69
|
-
| `
|
|
70
|
-
| `
|
|
71
|
-
| `
|
|
72
|
-
| `
|
|
73
|
-
| `history-
|
|
74
|
-
| `
|
|
75
|
-
| `
|
|
76
|
-
| `
|
|
54
|
+
| Command | Description |
|
|
55
|
+
| ---------------------- | ------------------------------------------------------------------------------------------------------------ |
|
|
56
|
+
| `rates-from` | Export rates from a start date |
|
|
57
|
+
| `rates-from-pos` | Export rates from a start position |
|
|
58
|
+
| `latest-rates` | Export latest rates from a start position |
|
|
59
|
+
| `rates-range` | Export rates for a date range |
|
|
60
|
+
| `ticks-from` | Export ticks from a start date |
|
|
61
|
+
| `ticks-range` | Export ticks for a date range |
|
|
62
|
+
| `ticks-recent` | Export ticks from a recent trailing window |
|
|
63
|
+
| `account-info` | Export account information |
|
|
64
|
+
| `terminal-info` | Export terminal information |
|
|
65
|
+
| `version` | Export MetaTrader 5 version information |
|
|
66
|
+
| `last-error` | Export the last error information |
|
|
67
|
+
| `symbols` | Export symbol list |
|
|
68
|
+
| `symbol-info` | Export symbol details |
|
|
69
|
+
| `symbol-info-tick` | Export the last tick for a symbol |
|
|
70
|
+
| `minimum-margins` | Export minimum-volume buy and sell margin requirements |
|
|
71
|
+
| `market-book` | Export market depth (order book) |
|
|
72
|
+
| `orders` | Export active orders |
|
|
73
|
+
| `positions` | Export open positions |
|
|
74
|
+
| `history-orders` | Export historical orders |
|
|
75
|
+
| `history-deals` | Export historical deals |
|
|
76
|
+
| `recent-history-deals` | Export historical deals from a recent trailing window |
|
|
77
|
+
| `mt5-summary` | Export terminal/account status summary |
|
|
78
|
+
| `order-check` | Check funds sufficiency for a trade request |
|
|
79
|
+
| `order-send` | Send a trade request to the trade server (`--yes` required) |
|
|
80
|
+
| `collect-history` | Bundle rates, ticks, history-orders, and history-deals for one or more symbols into a single SQLite database |
|
|
77
81
|
|
|
78
82
|
Use `order-check` to validate a request payload before running `order-send --yes`.
|
|
79
83
|
|
|
@@ -129,7 +133,11 @@ update_history_with_config(
|
|
|
129
133
|
- **`update_history`**: incremental append based on existing SQLite `MAX(time)` per symbol (and timeframe for rates); account-level deals use a separate cursor when `include_account_events=True`.
|
|
130
134
|
- **`rates` table**: normalized storage with `symbol` and `timeframe` columns.
|
|
131
135
|
- **Rate compatibility views**: mt5cli manages all `rate_*` views. Naming is `rate_<symbol>__<timeframe>` when a symbol has one timeframe, otherwise `rate_<symbol>__<granularity>_<timeframe>` (for example `rate_EURUSD__M1_1`). Stale `rate_*` views are dropped and recreated when rates change for offline tools such as mteor optimize.
|
|
132
|
-
- **Rate view resolution**: use `
|
|
136
|
+
- **Rate view resolution**: use `resolve_rate_view_name()` / `resolve_rate_view_names()` to map symbols and granularities to existing SQLite compatibility views without creating databases. Both accept `None` (or a missing path) and return deterministic default names unless `require_existing=True`.
|
|
137
|
+
- **Rate view loading**: use `load_rate_data()` / `load_rate_data_from_connection()` to load a SQLite rate table or view into a `DatetimeIndex` DataFrame.
|
|
138
|
+
- **Multi-series rate loading**: use `build_rate_targets()` to build neutral `RateTarget(symbol, timeframe)` pairs, `resolve_rate_tables()` to map them to table/view names (pass `require_existing=True` for strict resolution), and `load_rate_series_from_sqlite()` to load them into a mapping keyed by `(symbol, integer timeframe)`. The loader requires existing managed views unless `explicit_tables` is supplied, and rejects duplicate `(symbol, timeframe)` targets.
|
|
139
|
+
- **Multi-account latest rates**: use `collect_latest_rates_for_accounts()` with `AccountSpec` to read the latest bars for several account groups, merged into a `(symbol, integer timeframe)` mapping.
|
|
140
|
+
- **MT5 session helper**: use the `mt5_session()` context manager to attach to (or, when `Mt5Config.path` is set, launch) an MT5 terminal, log in, and yield a connected `Mt5CliClient` that shuts down on exit.
|
|
133
141
|
- **SQLite export helpers**: use `export_dataframe_to_sqlite()` for append mode, optional index export, and post-write deduplication by key columns.
|
|
134
142
|
- **Recent ticks and margins**: `recent_ticks()` and `minimum_margins()` SDK helpers (and matching CLI commands) cover common downstream read-only queries.
|
|
135
143
|
|
|
@@ -164,3 +164,54 @@ Resolution rules:
|
|
|
164
164
|
- Pass `require_existing=True` to raise `ValueError` instead of returning a
|
|
165
165
|
best-guess name when the database or view is missing.
|
|
166
166
|
- Accepts either a SQLite path or an open `sqlite3.Connection`.
|
|
167
|
+
|
|
168
|
+
### Rate data loading
|
|
169
|
+
|
|
170
|
+
Use `load_rate_data()` to load a table or view from a SQLite path, or
|
|
171
|
+
`load_rate_data_from_connection()` when you already have a connection:
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
from pathlib import Path
|
|
175
|
+
|
|
176
|
+
from mt5cli import load_rate_data
|
|
177
|
+
from mt5cli.history import resolve_rate_view_name
|
|
178
|
+
|
|
179
|
+
view = resolve_rate_view_name(Path("history.db"), "EURUSD", "M1", require_existing=True)
|
|
180
|
+
rates = load_rate_data(Path("history.db"), view, count=1000)
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
The loader accepts close-based OHLC rate data or tick-like bid/ask data. It
|
|
184
|
+
validates that `time` exists, parses timestamps with pandas, and returns a
|
|
185
|
+
DataFrame indexed by ascending `DatetimeIndex` named `time`.
|
|
186
|
+
|
|
187
|
+
### Multi-series rate loading
|
|
188
|
+
|
|
189
|
+
For loading many rate series at once, build neutral `RateTarget` pairs and load
|
|
190
|
+
them from SQLite in one call. View names are resolved via the same
|
|
191
|
+
compatibility-view rules, or you can pass `explicit_tables` to bypass resolution:
|
|
192
|
+
|
|
193
|
+
```python
|
|
194
|
+
from pathlib import Path
|
|
195
|
+
|
|
196
|
+
from mt5cli import build_rate_targets, load_rate_series_from_sqlite
|
|
197
|
+
|
|
198
|
+
targets = build_rate_targets(["EURUSD", "GBPUSD"], ["M1", "H1"])
|
|
199
|
+
series = load_rate_series_from_sqlite(Path("history.db"), targets, count=1000)
|
|
200
|
+
frame = series["EURUSD", 1] # keyed by (symbol, integer timeframe)
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
- `build_rate_targets()` returns `RateTarget(symbol, timeframe)` pairs in
|
|
204
|
+
row-major order, normalizing timeframe names such as `"M1"` to their integer
|
|
205
|
+
values; set `allow_missing_symbol=True` to address series solely by
|
|
206
|
+
`explicit_tables` (targets carry `symbol=None`).
|
|
207
|
+
- `resolve_rate_tables()` maps targets to table or view names and validates that
|
|
208
|
+
any `explicit_tables` count matches the target count. Pass
|
|
209
|
+
`require_existing=True` to raise `ValueError` instead of returning a
|
|
210
|
+
best-guess name when the database or managed view is missing. When
|
|
211
|
+
`explicit_tables` is provided, names are returned as-is and
|
|
212
|
+
`require_existing` is ignored.
|
|
213
|
+
- `load_rate_series_from_sqlite()` returns a mapping keyed by
|
|
214
|
+
`(symbol, integer timeframe)`. Unless `explicit_tables` is supplied, it
|
|
215
|
+
requires existing managed `rate_*` compatibility views and raises
|
|
216
|
+
`ValueError` when they are missing. Duplicate `(symbol, timeframe)` targets
|
|
217
|
+
are rejected.
|
|
@@ -13,6 +13,7 @@ mt5cli is a CLI application that exports MetaTrader 5 trading data to multiple f
|
|
|
13
13
|
- **Comprehensive data access**: Rates, ticks, account info, symbols, orders, positions, and trading history
|
|
14
14
|
- **Flexible timeframes**: Named timeframes (M1, H1, D1, etc.) and numeric values
|
|
15
15
|
- **Connection management**: Optional credentials, server, and timeout configuration
|
|
16
|
+
- **SQLite rate loading**: Load mt5cli-managed rate tables/views for offline workflows
|
|
16
17
|
|
|
17
18
|
## Installation
|
|
18
19
|
|
|
@@ -34,6 +35,7 @@ from mt5cli import (
|
|
|
34
35
|
copy_rates_range,
|
|
35
36
|
export_dataframe,
|
|
36
37
|
export_dataframe_to_sqlite,
|
|
38
|
+
load_rate_data,
|
|
37
39
|
minimum_margins,
|
|
38
40
|
recent_ticks,
|
|
39
41
|
)
|
|
@@ -49,7 +51,8 @@ rates = copy_rates_range(
|
|
|
49
51
|
export_dataframe(rates, Path("rates.csv"), "csv")
|
|
50
52
|
|
|
51
53
|
# Resolve SQLite rate compatibility views for downstream tools
|
|
52
|
-
view = resolve_rate_view_name(Path("history.db"), "EURUSD", "M1")
|
|
54
|
+
view = resolve_rate_view_name(Path("history.db"), "EURUSD", "M1", require_existing=True)
|
|
55
|
+
offline_rates = load_rate_data(Path("history.db"), view, count=1000)
|
|
53
56
|
|
|
54
57
|
# Recent tick window and minimum margin summary
|
|
55
58
|
ticks = recent_ticks("EURUSD", seconds=300)
|
|
@@ -59,6 +62,9 @@ margins = minimum_margins("EURUSD")
|
|
|
59
62
|
with Mt5CliClient(login=12345, password="secret", server="Broker-Demo") as client:
|
|
60
63
|
account = client.account_info()
|
|
61
64
|
positions = client.positions()
|
|
65
|
+
latest = client.latest_rates("EURUSD", "M1", count=100)
|
|
66
|
+
summary = client.mt5_summary()
|
|
67
|
+
summary_table = client.mt5_summary_as_df()
|
|
62
68
|
|
|
63
69
|
# Bulk SQLite collection (same behavior as the collect-history CLI command)
|
|
64
70
|
collect_history(
|
|
@@ -74,6 +80,8 @@ collect_history(
|
|
|
74
80
|
|
|
75
81
|
Timeframes, tick flags, and ISO 8601 date strings are accepted wherever noted in the SDK API.
|
|
76
82
|
|
|
83
|
+
`Mt5CliClient.mt5_summary()` returns the SDK structured form as plain nested Python values. Use `Mt5CliClient.mt5_summary_as_df()` when you need a one-row DataFrame for export. The `mt5-summary` CLI command uses this tabular form, so nested terminal/account fields are JSON-encoded strings that are safe for CSV, JSON, Parquet, and SQLite output.
|
|
84
|
+
|
|
77
85
|
## Quick Start
|
|
78
86
|
|
|
79
87
|
```bash
|
|
@@ -104,6 +112,7 @@ mt5cli --login 12345 --password mypass --server MyBroker-Demo \
|
|
|
104
112
|
| ---------------- | ---------------------------------- |
|
|
105
113
|
| `rates-from` | Export rates from a start date |
|
|
106
114
|
| `rates-from-pos` | Export rates from a start position |
|
|
115
|
+
| `latest-rates` | Export latest rates |
|
|
107
116
|
| `rates-range` | Export rates for a date range |
|
|
108
117
|
|
|
109
118
|
### Ticks
|
|
@@ -130,14 +139,16 @@ mt5cli --login 12345 --password mypass --server MyBroker-Demo \
|
|
|
130
139
|
|
|
131
140
|
### Trading
|
|
132
141
|
|
|
133
|
-
| Command
|
|
134
|
-
|
|
|
135
|
-
| `orders`
|
|
136
|
-
| `positions`
|
|
137
|
-
| `history-orders`
|
|
138
|
-
| `history-deals`
|
|
139
|
-
| `
|
|
140
|
-
| `
|
|
142
|
+
| Command | Description |
|
|
143
|
+
| ---------------------- | ----------------------------------------------------------- |
|
|
144
|
+
| `orders` | Export active orders |
|
|
145
|
+
| `positions` | Export open positions |
|
|
146
|
+
| `history-orders` | Export historical orders |
|
|
147
|
+
| `history-deals` | Export historical deals |
|
|
148
|
+
| `recent-history-deals` | Export historical deals from a trailing window |
|
|
149
|
+
| `mt5-summary` | Export terminal/account status summary |
|
|
150
|
+
| `order-check` | Check funds sufficiency for a trade request |
|
|
151
|
+
| `order-send` | Send a trade request to the trade server (`--yes` required) |
|
|
141
152
|
|
|
142
153
|
Use `order-check` to validate a request payload before running `order-send --yes`.
|
|
143
154
|
|
|
@@ -2,11 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
from importlib.metadata import version
|
|
4
4
|
|
|
5
|
+
from .history import (
|
|
6
|
+
RateTarget,
|
|
7
|
+
build_rate_targets,
|
|
8
|
+
build_rate_view_name,
|
|
9
|
+
load_rate_data,
|
|
10
|
+
load_rate_data_from_connection,
|
|
11
|
+
load_rate_series_from_sqlite,
|
|
12
|
+
resolve_history_datasets,
|
|
13
|
+
resolve_history_tick_flags,
|
|
14
|
+
resolve_history_timeframes,
|
|
15
|
+
resolve_rate_tables,
|
|
16
|
+
resolve_rate_view_name,
|
|
17
|
+
resolve_rate_view_names,
|
|
18
|
+
)
|
|
5
19
|
from .sdk import (
|
|
20
|
+
AccountSpec,
|
|
6
21
|
Mt5CliClient,
|
|
7
22
|
account_info,
|
|
8
23
|
build_config,
|
|
9
24
|
collect_history,
|
|
25
|
+
collect_latest_rates,
|
|
26
|
+
collect_latest_rates_for_accounts,
|
|
10
27
|
copy_rates_from,
|
|
11
28
|
copy_rates_from_pos,
|
|
12
29
|
copy_rates_range,
|
|
@@ -15,10 +32,15 @@ from .sdk import (
|
|
|
15
32
|
history_deals,
|
|
16
33
|
history_orders,
|
|
17
34
|
last_error,
|
|
35
|
+
latest_rates,
|
|
18
36
|
market_book,
|
|
19
37
|
minimum_margins,
|
|
38
|
+
mt5_session,
|
|
39
|
+
mt5_summary,
|
|
40
|
+
mt5_summary_as_df,
|
|
20
41
|
orders,
|
|
21
42
|
positions,
|
|
43
|
+
recent_history_deals,
|
|
22
44
|
recent_ticks,
|
|
23
45
|
symbol_info,
|
|
24
46
|
symbol_info_tick,
|
|
@@ -31,22 +53,35 @@ from .sdk import (
|
|
|
31
53
|
version as mt5_version,
|
|
32
54
|
)
|
|
33
55
|
from .utils import (
|
|
56
|
+
TICK_FLAG_MAP,
|
|
57
|
+
TIMEFRAME_MAP,
|
|
34
58
|
Dataset,
|
|
35
59
|
IfExists,
|
|
36
60
|
detect_format,
|
|
37
61
|
export_dataframe,
|
|
38
62
|
export_dataframe_to_sqlite,
|
|
63
|
+
parse_datetime,
|
|
64
|
+
parse_tick_flags,
|
|
65
|
+
parse_timeframe,
|
|
39
66
|
)
|
|
40
67
|
|
|
41
68
|
__version__ = version(__package__) if __package__ else None
|
|
42
69
|
|
|
43
70
|
__all__ = [
|
|
71
|
+
"TICK_FLAG_MAP",
|
|
72
|
+
"TIMEFRAME_MAP",
|
|
73
|
+
"AccountSpec",
|
|
44
74
|
"Dataset",
|
|
45
75
|
"IfExists",
|
|
46
76
|
"Mt5CliClient",
|
|
77
|
+
"RateTarget",
|
|
47
78
|
"account_info",
|
|
48
79
|
"build_config",
|
|
80
|
+
"build_rate_targets",
|
|
81
|
+
"build_rate_view_name",
|
|
49
82
|
"collect_history",
|
|
83
|
+
"collect_latest_rates",
|
|
84
|
+
"collect_latest_rates_for_accounts",
|
|
50
85
|
"copy_rates_from",
|
|
51
86
|
"copy_rates_from_pos",
|
|
52
87
|
"copy_rates_range",
|
|
@@ -58,12 +93,29 @@ __all__ = [
|
|
|
58
93
|
"history_deals",
|
|
59
94
|
"history_orders",
|
|
60
95
|
"last_error",
|
|
96
|
+
"latest_rates",
|
|
97
|
+
"load_rate_data",
|
|
98
|
+
"load_rate_data_from_connection",
|
|
99
|
+
"load_rate_series_from_sqlite",
|
|
61
100
|
"market_book",
|
|
62
101
|
"minimum_margins",
|
|
102
|
+
"mt5_session",
|
|
103
|
+
"mt5_summary",
|
|
104
|
+
"mt5_summary_as_df",
|
|
63
105
|
"mt5_version",
|
|
64
106
|
"orders",
|
|
107
|
+
"parse_datetime",
|
|
108
|
+
"parse_tick_flags",
|
|
109
|
+
"parse_timeframe",
|
|
65
110
|
"positions",
|
|
111
|
+
"recent_history_deals",
|
|
66
112
|
"recent_ticks",
|
|
113
|
+
"resolve_history_datasets",
|
|
114
|
+
"resolve_history_tick_flags",
|
|
115
|
+
"resolve_history_timeframes",
|
|
116
|
+
"resolve_rate_tables",
|
|
117
|
+
"resolve_rate_view_name",
|
|
118
|
+
"resolve_rate_view_names",
|
|
67
119
|
"symbol_info",
|
|
68
120
|
"symbol_info_tick",
|
|
69
121
|
"symbols",
|
|
@@ -222,6 +222,31 @@ def rates_from_pos(
|
|
|
222
222
|
)
|
|
223
223
|
|
|
224
224
|
|
|
225
|
+
@app.command()
|
|
226
|
+
def latest_rates(
|
|
227
|
+
ctx: typer.Context,
|
|
228
|
+
symbol: Annotated[str, typer.Option(help="Symbol name.")],
|
|
229
|
+
timeframe: Annotated[
|
|
230
|
+
int,
|
|
231
|
+
typer.Option(
|
|
232
|
+
click_type=TIMEFRAME_TYPE,
|
|
233
|
+
help="Timeframe.",
|
|
234
|
+
),
|
|
235
|
+
],
|
|
236
|
+
count: Annotated[int, typer.Option(help="Number of records.")],
|
|
237
|
+
start_pos: Annotated[
|
|
238
|
+
int,
|
|
239
|
+
typer.Option(help="Start position (0 = current bar)."),
|
|
240
|
+
] = 0,
|
|
241
|
+
) -> None:
|
|
242
|
+
"""Export latest rates from a start position."""
|
|
243
|
+
client = _sdk_client(ctx)
|
|
244
|
+
_execute_export(
|
|
245
|
+
ctx,
|
|
246
|
+
lambda: client.latest_rates(symbol, timeframe, count, start_pos=start_pos),
|
|
247
|
+
)
|
|
248
|
+
|
|
249
|
+
|
|
225
250
|
@app.command()
|
|
226
251
|
def rates_range(
|
|
227
252
|
ctx: typer.Context,
|
|
@@ -475,6 +500,37 @@ def history_deals(
|
|
|
475
500
|
)
|
|
476
501
|
|
|
477
502
|
|
|
503
|
+
@app.command()
|
|
504
|
+
def recent_history_deals(
|
|
505
|
+
ctx: typer.Context,
|
|
506
|
+
hours: Annotated[float, typer.Option(help="Lookback window in hours.")],
|
|
507
|
+
date_to: Annotated[
|
|
508
|
+
datetime | None,
|
|
509
|
+
typer.Option(click_type=DATETIME_TYPE, help="Window end date."),
|
|
510
|
+
] = None,
|
|
511
|
+
group: Annotated[str | None, typer.Option(help="Group filter.")] = None,
|
|
512
|
+
symbol: Annotated[str | None, typer.Option(help="Symbol filter.")] = None,
|
|
513
|
+
) -> None:
|
|
514
|
+
"""Export historical deals from a recent trailing window."""
|
|
515
|
+
client = _sdk_client(ctx)
|
|
516
|
+
_execute_export(
|
|
517
|
+
ctx,
|
|
518
|
+
lambda: client.recent_history_deals(
|
|
519
|
+
hours,
|
|
520
|
+
date_to=date_to,
|
|
521
|
+
group=group,
|
|
522
|
+
symbol=symbol,
|
|
523
|
+
),
|
|
524
|
+
)
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
@app.command()
|
|
528
|
+
def mt5_summary(ctx: typer.Context) -> None:
|
|
529
|
+
"""Export a compact terminal/account status summary."""
|
|
530
|
+
client = _sdk_client(ctx)
|
|
531
|
+
_execute_export(ctx, client.mt5_summary_as_df)
|
|
532
|
+
|
|
533
|
+
|
|
478
534
|
@app.command()
|
|
479
535
|
def version(ctx: typer.Context) -> None:
|
|
480
536
|
"""Export MetaTrader5 version information."""
|