mt5cli 0.4.2__tar.gz → 0.5.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.
- {mt5cli-0.4.2 → mt5cli-0.5.0}/PKG-INFO +33 -23
- {mt5cli-0.4.2 → mt5cli-0.5.0}/README.md +32 -22
- {mt5cli-0.4.2 → mt5cli-0.5.0}/docs/api/history.md +54 -0
- {mt5cli-0.4.2 → mt5cli-0.5.0}/docs/api/index.md +20 -0
- {mt5cli-0.4.2 → mt5cli-0.5.0}/docs/index.md +43 -14
- {mt5cli-0.4.2 → mt5cli-0.5.0}/mt5cli/__init__.py +25 -1
- {mt5cli-0.4.2 → mt5cli-0.5.0}/mt5cli/cli.py +104 -0
- {mt5cli-0.4.2 → mt5cli-0.5.0}/mt5cli/history.py +363 -2
- {mt5cli-0.4.2 → mt5cli-0.5.0}/mt5cli/sdk.py +404 -6
- {mt5cli-0.4.2 → mt5cli-0.5.0}/mt5cli/utils.py +55 -10
- {mt5cli-0.4.2 → mt5cli-0.5.0}/pyproject.toml +1 -1
- {mt5cli-0.4.2 → mt5cli-0.5.0}/tests/test_cli.py +173 -1
- {mt5cli-0.4.2 → mt5cli-0.5.0}/tests/test_history.py +420 -0
- {mt5cli-0.4.2 → mt5cli-0.5.0}/tests/test_sdk.py +443 -3
- {mt5cli-0.4.2 → mt5cli-0.5.0}/tests/test_utils.py +108 -0
- {mt5cli-0.4.2 → mt5cli-0.5.0}/uv.lock +1 -1
- {mt5cli-0.4.2 → mt5cli-0.5.0}/.agents/skills/local-qa/SKILL.md +0 -0
- {mt5cli-0.4.2 → mt5cli-0.5.0}/.agents/skills/local-qa/scripts/qa.sh +0 -0
- {mt5cli-0.4.2 → mt5cli-0.5.0}/.agents/skills/mt5cli/SKILL.md +0 -0
- {mt5cli-0.4.2 → mt5cli-0.5.0}/.claude/agents/codex.md +0 -0
- {mt5cli-0.4.2 → mt5cli-0.5.0}/.claude/settings.json +0 -0
- {mt5cli-0.4.2 → mt5cli-0.5.0}/.github/FUNDING.yml +0 -0
- {mt5cli-0.4.2 → mt5cli-0.5.0}/.github/dependabot.yml +0 -0
- {mt5cli-0.4.2 → mt5cli-0.5.0}/.github/renovate.json +0 -0
- {mt5cli-0.4.2 → mt5cli-0.5.0}/.github/workflows/ci.yml +0 -0
- {mt5cli-0.4.2 → mt5cli-0.5.0}/.github/workflows/claude.yml +0 -0
- {mt5cli-0.4.2 → mt5cli-0.5.0}/.github/workflows/release.yml +0 -0
- {mt5cli-0.4.2 → mt5cli-0.5.0}/.gitignore +0 -0
- {mt5cli-0.4.2 → mt5cli-0.5.0}/AGENTS.md +0 -0
- {mt5cli-0.4.2 → mt5cli-0.5.0}/CLAUDE.md +0 -0
- {mt5cli-0.4.2 → mt5cli-0.5.0}/LICENSE +0 -0
- {mt5cli-0.4.2 → mt5cli-0.5.0}/docs/api/cli.md +0 -0
- {mt5cli-0.4.2 → mt5cli-0.5.0}/docs/api/sdk.md +0 -0
- {mt5cli-0.4.2 → mt5cli-0.5.0}/docs/api/utils.md +0 -0
- {mt5cli-0.4.2 → mt5cli-0.5.0}/mkdocs.yml +0 -0
- {mt5cli-0.4.2 → mt5cli-0.5.0}/mt5cli/__main__.py +0 -0
- {mt5cli-0.4.2 → mt5cli-0.5.0}/tests/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mt5cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
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,28 +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
|
-
| `
|
|
85
|
-
| `
|
|
86
|
-
| `
|
|
87
|
-
| `
|
|
88
|
-
| `
|
|
89
|
-
| `
|
|
90
|
-
| `
|
|
91
|
-
| `
|
|
92
|
-
| `
|
|
93
|
-
| `
|
|
94
|
-
| `
|
|
95
|
-
| `
|
|
96
|
-
| `
|
|
97
|
-
| `
|
|
98
|
-
| `
|
|
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 |
|
|
99
105
|
|
|
100
106
|
Use `order-check` to validate a request payload before running `order-send --yes`.
|
|
101
107
|
|
|
@@ -151,6 +157,10 @@ update_history_with_config(
|
|
|
151
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`.
|
|
152
158
|
- **`rates` table**: normalized storage with `symbol` and `timeframe` columns.
|
|
153
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.
|
|
160
|
+
- **Rate view resolution**: use `mt5cli.history.resolve_rate_view_name()` / `resolve_rate_view_names()` to map symbols and granularities to existing SQLite compatibility views without creating databases.
|
|
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
|
+
- **SQLite export helpers**: use `export_dataframe_to_sqlite()` for append mode, optional index export, and post-write deduplication by key columns.
|
|
163
|
+
- **Recent ticks and margins**: `recent_ticks()` and `minimum_margins()` SDK helpers (and matching CLI commands) cover common downstream read-only queries.
|
|
154
164
|
|
|
155
165
|
## Requirements
|
|
156
166
|
|
|
@@ -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,28 +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
|
-
| `
|
|
61
|
-
| `
|
|
62
|
-
| `
|
|
63
|
-
| `
|
|
64
|
-
| `
|
|
65
|
-
| `
|
|
66
|
-
| `
|
|
67
|
-
| `
|
|
68
|
-
| `
|
|
69
|
-
| `
|
|
70
|
-
| `
|
|
71
|
-
| `
|
|
72
|
-
| `
|
|
73
|
-
| `
|
|
74
|
-
| `
|
|
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 |
|
|
75
81
|
|
|
76
82
|
Use `order-check` to validate a request payload before running `order-send --yes`.
|
|
77
83
|
|
|
@@ -127,6 +133,10 @@ update_history_with_config(
|
|
|
127
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`.
|
|
128
134
|
- **`rates` table**: normalized storage with `symbol` and `timeframe` columns.
|
|
129
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.
|
|
136
|
+
- **Rate view resolution**: use `mt5cli.history.resolve_rate_view_name()` / `resolve_rate_view_names()` to map symbols and granularities to existing SQLite compatibility views without creating databases.
|
|
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
|
+
- **SQLite export helpers**: use `export_dataframe_to_sqlite()` for append mode, optional index export, and post-write deduplication by key columns.
|
|
139
|
+
- **Recent ticks and margins**: `recent_ticks()` and `minimum_margins()` SDK helpers (and matching CLI commands) cover common downstream read-only queries.
|
|
130
140
|
|
|
131
141
|
## Requirements
|
|
132
142
|
|
|
@@ -129,3 +129,57 @@ when required columns are missing.
|
|
|
129
129
|
The `update_history` SDK path uses the same base tables and optional
|
|
130
130
|
`cash_events` / `positions_reconstructed` views. It additionally maintains
|
|
131
131
|
`rate_<symbol>__<timeframe>` compatibility views when `create_rate_views=True`.
|
|
132
|
+
|
|
133
|
+
### Rate view resolution
|
|
134
|
+
|
|
135
|
+
Downstream tools can resolve mt5cli-managed compatibility view names from an
|
|
136
|
+
existing SQLite history database without creating files or guessing legacy
|
|
137
|
+
naming schemes:
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
from pathlib import Path
|
|
141
|
+
|
|
142
|
+
from mt5cli.history import resolve_rate_view_name, resolve_rate_view_names
|
|
143
|
+
|
|
144
|
+
# Single symbol and granularity
|
|
145
|
+
view = resolve_rate_view_name(Path("history.db"), "EURUSD", "M1")
|
|
146
|
+
|
|
147
|
+
# Batch resolution in row-major order
|
|
148
|
+
views = resolve_rate_view_names(
|
|
149
|
+
Path("history.db"),
|
|
150
|
+
["EURUSD", "GBPUSD"],
|
|
151
|
+
["M1", "H1"],
|
|
152
|
+
)
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Resolution rules:
|
|
156
|
+
|
|
157
|
+
- Returns `rate_<symbol>__<timeframe>` when a symbol stores one timeframe.
|
|
158
|
+
- Returns `rate_<symbol>__<granularity>_<timeframe>` when multiple timeframes
|
|
159
|
+
are stored for the same symbol.
|
|
160
|
+
- When multiple naming candidates apply, prefers an existing managed
|
|
161
|
+
`rate_*__*` view from the candidate list.
|
|
162
|
+
- Falls back to single-timeframe naming when the database path is missing or
|
|
163
|
+
`rates` metadata is unavailable.
|
|
164
|
+
- Pass `require_existing=True` to raise `ValueError` instead of returning a
|
|
165
|
+
best-guess name when the database or view is missing.
|
|
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`.
|
|
@@ -65,12 +65,18 @@ from datetime import UTC, datetime
|
|
|
65
65
|
from pathlib import Path
|
|
66
66
|
|
|
67
67
|
from mt5cli import (
|
|
68
|
+
Dataset,
|
|
69
|
+
IfExists,
|
|
68
70
|
Mt5CliClient,
|
|
69
71
|
collect_history,
|
|
70
72
|
copy_rates_range,
|
|
71
73
|
detect_format,
|
|
72
74
|
export_dataframe,
|
|
75
|
+
export_dataframe_to_sqlite,
|
|
76
|
+
minimum_margins,
|
|
77
|
+
recent_ticks,
|
|
73
78
|
)
|
|
79
|
+
from mt5cli.history import resolve_rate_view_name
|
|
74
80
|
|
|
75
81
|
# Fetch rates programmatically
|
|
76
82
|
rates = copy_rates_range(
|
|
@@ -86,6 +92,20 @@ fmt = detect_format(Path("output.parquet")) # Returns "parquet"
|
|
|
86
92
|
# Export a DataFrame
|
|
87
93
|
export_dataframe(rates, Path("output.csv"), "csv")
|
|
88
94
|
|
|
95
|
+
# Append to SQLite with deduplication
|
|
96
|
+
export_dataframe_to_sqlite(
|
|
97
|
+
rates,
|
|
98
|
+
Path("history.db"),
|
|
99
|
+
"rates",
|
|
100
|
+
if_exists=IfExists.APPEND,
|
|
101
|
+
deduplicate_on=("symbol", "timeframe", "time"),
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
# Resolve rate compatibility views and fetch recent ticks
|
|
105
|
+
view = resolve_rate_view_name(Path("history.db"), "EURUSD", "M1")
|
|
106
|
+
ticks = recent_ticks("EURUSD", seconds=300)
|
|
107
|
+
margins = minimum_margins("EURUSD")
|
|
108
|
+
|
|
89
109
|
# Collect history into SQLite
|
|
90
110
|
collect_history(
|
|
91
111
|
Path("history.db"),
|
|
@@ -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
|
|
|
@@ -22,13 +23,23 @@ pip install mt5cli
|
|
|
22
23
|
|
|
23
24
|
## Programmatic usage / SDK usage
|
|
24
25
|
|
|
25
|
-
mt5cli can be used as a small Python SDK for read-only MetaTrader 5 data collection. SDK functions return pandas DataFrames without writing files. Use `export_dataframe` when you need to persist results.
|
|
26
|
+
mt5cli can be used as a small Python SDK for read-only MetaTrader 5 data collection. SDK functions return pandas DataFrames without writing files. Use `export_dataframe` or `export_dataframe_to_sqlite` when you need to persist results.
|
|
26
27
|
|
|
27
28
|
```python
|
|
28
29
|
from datetime import UTC, datetime
|
|
29
30
|
from pathlib import Path
|
|
30
31
|
|
|
31
|
-
from mt5cli import
|
|
32
|
+
from mt5cli import (
|
|
33
|
+
Mt5CliClient,
|
|
34
|
+
collect_history,
|
|
35
|
+
copy_rates_range,
|
|
36
|
+
export_dataframe,
|
|
37
|
+
export_dataframe_to_sqlite,
|
|
38
|
+
load_rate_data,
|
|
39
|
+
minimum_margins,
|
|
40
|
+
recent_ticks,
|
|
41
|
+
)
|
|
42
|
+
from mt5cli.history import resolve_rate_view_name
|
|
32
43
|
|
|
33
44
|
# One-off fetch with module-level helpers
|
|
34
45
|
rates = copy_rates_range(
|
|
@@ -39,10 +50,21 @@ rates = copy_rates_range(
|
|
|
39
50
|
)
|
|
40
51
|
export_dataframe(rates, Path("rates.csv"), "csv")
|
|
41
52
|
|
|
53
|
+
# Resolve SQLite rate compatibility views for downstream tools
|
|
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)
|
|
56
|
+
|
|
57
|
+
# Recent tick window and minimum margin summary
|
|
58
|
+
ticks = recent_ticks("EURUSD", seconds=300)
|
|
59
|
+
margins = minimum_margins("EURUSD")
|
|
60
|
+
|
|
42
61
|
# Reuse one MT5 connection for multiple calls
|
|
43
62
|
with Mt5CliClient(login=12345, password="secret", server="Broker-Demo") as client:
|
|
44
63
|
account = client.account_info()
|
|
45
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()
|
|
46
68
|
|
|
47
69
|
# Bulk SQLite collection (same behavior as the collect-history CLI command)
|
|
48
70
|
collect_history(
|
|
@@ -58,6 +80,8 @@ collect_history(
|
|
|
58
80
|
|
|
59
81
|
Timeframes, tick flags, and ISO 8601 date strings are accepted wherever noted in the SDK API.
|
|
60
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
|
+
|
|
61
85
|
## Quick Start
|
|
62
86
|
|
|
63
87
|
```bash
|
|
@@ -88,14 +112,16 @@ mt5cli --login 12345 --password mypass --server MyBroker-Demo \
|
|
|
88
112
|
| ---------------- | ---------------------------------- |
|
|
89
113
|
| `rates-from` | Export rates from a start date |
|
|
90
114
|
| `rates-from-pos` | Export rates from a start position |
|
|
115
|
+
| `latest-rates` | Export latest rates |
|
|
91
116
|
| `rates-range` | Export rates for a date range |
|
|
92
117
|
|
|
93
118
|
### Ticks
|
|
94
119
|
|
|
95
|
-
| Command
|
|
96
|
-
|
|
|
97
|
-
| `ticks-from`
|
|
98
|
-
| `ticks-range`
|
|
120
|
+
| Command | Description |
|
|
121
|
+
| -------------- | ----------------------------------- |
|
|
122
|
+
| `ticks-from` | Export ticks from a start date |
|
|
123
|
+
| `ticks-range` | Export ticks for a date range |
|
|
124
|
+
| `ticks-recent` | Export ticks from a trailing window |
|
|
99
125
|
|
|
100
126
|
### Information
|
|
101
127
|
|
|
@@ -108,18 +134,21 @@ mt5cli --login 12345 --password mypass --server MyBroker-Demo \
|
|
|
108
134
|
| `symbols` | Export symbol list |
|
|
109
135
|
| `symbol-info` | Export symbol details |
|
|
110
136
|
| `symbol-info-tick` | Export the last tick for a symbol |
|
|
137
|
+
| `minimum-margins` | Export minimum-volume margin summary |
|
|
111
138
|
| `market-book` | Export market depth (order book) |
|
|
112
139
|
|
|
113
140
|
### Trading
|
|
114
141
|
|
|
115
|
-
| Command
|
|
116
|
-
|
|
|
117
|
-
| `orders`
|
|
118
|
-
| `positions`
|
|
119
|
-
| `history-orders`
|
|
120
|
-
| `history-deals`
|
|
121
|
-
| `
|
|
122
|
-
| `
|
|
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) |
|
|
123
152
|
|
|
124
153
|
Use `order-check` to validate a request payload before running `order-send --yes`.
|
|
125
154
|
|
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
from importlib.metadata import version
|
|
4
4
|
|
|
5
|
+
from .history import load_rate_data, load_rate_data_from_connection
|
|
5
6
|
from .sdk import (
|
|
6
7
|
Mt5CliClient,
|
|
7
8
|
account_info,
|
|
8
9
|
build_config,
|
|
9
10
|
collect_history,
|
|
11
|
+
collect_latest_rates,
|
|
10
12
|
copy_rates_from,
|
|
11
13
|
copy_rates_from_pos,
|
|
12
14
|
copy_rates_range,
|
|
@@ -15,9 +17,15 @@ from .sdk import (
|
|
|
15
17
|
history_deals,
|
|
16
18
|
history_orders,
|
|
17
19
|
last_error,
|
|
20
|
+
latest_rates,
|
|
18
21
|
market_book,
|
|
22
|
+
minimum_margins,
|
|
23
|
+
mt5_summary,
|
|
24
|
+
mt5_summary_as_df,
|
|
19
25
|
orders,
|
|
20
26
|
positions,
|
|
27
|
+
recent_history_deals,
|
|
28
|
+
recent_ticks,
|
|
21
29
|
symbol_info,
|
|
22
30
|
symbol_info_tick,
|
|
23
31
|
symbols,
|
|
@@ -28,7 +36,13 @@ from .sdk import (
|
|
|
28
36
|
from .sdk import (
|
|
29
37
|
version as mt5_version,
|
|
30
38
|
)
|
|
31
|
-
from .utils import
|
|
39
|
+
from .utils import (
|
|
40
|
+
Dataset,
|
|
41
|
+
IfExists,
|
|
42
|
+
detect_format,
|
|
43
|
+
export_dataframe,
|
|
44
|
+
export_dataframe_to_sqlite,
|
|
45
|
+
)
|
|
32
46
|
|
|
33
47
|
__version__ = version(__package__) if __package__ else None
|
|
34
48
|
|
|
@@ -39,6 +53,7 @@ __all__ = [
|
|
|
39
53
|
"account_info",
|
|
40
54
|
"build_config",
|
|
41
55
|
"collect_history",
|
|
56
|
+
"collect_latest_rates",
|
|
42
57
|
"copy_rates_from",
|
|
43
58
|
"copy_rates_from_pos",
|
|
44
59
|
"copy_rates_range",
|
|
@@ -46,13 +61,22 @@ __all__ = [
|
|
|
46
61
|
"copy_ticks_range",
|
|
47
62
|
"detect_format",
|
|
48
63
|
"export_dataframe",
|
|
64
|
+
"export_dataframe_to_sqlite",
|
|
49
65
|
"history_deals",
|
|
50
66
|
"history_orders",
|
|
51
67
|
"last_error",
|
|
68
|
+
"latest_rates",
|
|
69
|
+
"load_rate_data",
|
|
70
|
+
"load_rate_data_from_connection",
|
|
52
71
|
"market_book",
|
|
72
|
+
"minimum_margins",
|
|
73
|
+
"mt5_summary",
|
|
74
|
+
"mt5_summary_as_df",
|
|
53
75
|
"mt5_version",
|
|
54
76
|
"orders",
|
|
55
77
|
"positions",
|
|
78
|
+
"recent_history_deals",
|
|
79
|
+
"recent_ticks",
|
|
56
80
|
"symbol_info",
|
|
57
81
|
"symbol_info_tick",
|
|
58
82
|
"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,
|
|
@@ -300,6 +325,44 @@ def ticks_range(
|
|
|
300
325
|
)
|
|
301
326
|
|
|
302
327
|
|
|
328
|
+
@app.command()
|
|
329
|
+
def ticks_recent(
|
|
330
|
+
ctx: typer.Context,
|
|
331
|
+
symbol: Annotated[str, typer.Option(help="Symbol name.")],
|
|
332
|
+
seconds: Annotated[
|
|
333
|
+
float,
|
|
334
|
+
typer.Option(help="Lookback window in seconds."),
|
|
335
|
+
],
|
|
336
|
+
date_to: Annotated[
|
|
337
|
+
datetime | None,
|
|
338
|
+
typer.Option(click_type=DATETIME_TYPE, help="Window end date."),
|
|
339
|
+
] = None,
|
|
340
|
+
count: Annotated[
|
|
341
|
+
int,
|
|
342
|
+
typer.Option(help="Maximum number of ticks to return."),
|
|
343
|
+
] = 10000,
|
|
344
|
+
flags: Annotated[
|
|
345
|
+
int,
|
|
346
|
+
typer.Option(
|
|
347
|
+
click_type=TICK_FLAGS_TYPE,
|
|
348
|
+
help="Tick flags (ALL, INFO, TRADE, or integer).",
|
|
349
|
+
),
|
|
350
|
+
] = 1,
|
|
351
|
+
) -> None:
|
|
352
|
+
"""Export ticks from a recent time window."""
|
|
353
|
+
client = _sdk_client(ctx)
|
|
354
|
+
_execute_export(
|
|
355
|
+
ctx,
|
|
356
|
+
lambda: client.recent_ticks(
|
|
357
|
+
symbol,
|
|
358
|
+
seconds,
|
|
359
|
+
date_to=date_to,
|
|
360
|
+
count=count,
|
|
361
|
+
flags=flags,
|
|
362
|
+
),
|
|
363
|
+
)
|
|
364
|
+
|
|
365
|
+
|
|
303
366
|
@app.command()
|
|
304
367
|
def account_info(ctx: typer.Context) -> None:
|
|
305
368
|
"""Export account information."""
|
|
@@ -335,6 +398,16 @@ def symbol_info(
|
|
|
335
398
|
_execute_export(ctx, lambda: client.symbol_info(symbol))
|
|
336
399
|
|
|
337
400
|
|
|
401
|
+
@app.command()
|
|
402
|
+
def minimum_margins(
|
|
403
|
+
ctx: typer.Context,
|
|
404
|
+
symbol: Annotated[str, typer.Option(help="Symbol name.")],
|
|
405
|
+
) -> None:
|
|
406
|
+
"""Export minimum-volume buy and sell margin requirements."""
|
|
407
|
+
client = _sdk_client(ctx)
|
|
408
|
+
_execute_export(ctx, lambda: client.minimum_margins(symbol))
|
|
409
|
+
|
|
410
|
+
|
|
338
411
|
@app.command()
|
|
339
412
|
def orders(
|
|
340
413
|
ctx: typer.Context,
|
|
@@ -427,6 +500,37 @@ def history_deals(
|
|
|
427
500
|
)
|
|
428
501
|
|
|
429
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
|
+
|
|
430
534
|
@app.command()
|
|
431
535
|
def version(ctx: typer.Context) -> None:
|
|
432
536
|
"""Export MetaTrader5 version information."""
|