mt5cli 0.3.0__tar.gz → 0.4.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.3.0 → mt5cli-0.4.1}/AGENTS.md +3 -1
- {mt5cli-0.3.0 → mt5cli-0.4.1}/PKG-INFO +41 -2
- {mt5cli-0.3.0 → mt5cli-0.4.1}/README.md +40 -1
- {mt5cli-0.3.0 → mt5cli-0.4.1}/docs/api/index.md +39 -6
- mt5cli-0.4.1/docs/api/sdk.md +3 -0
- mt5cli-0.4.1/docs/api/sqlite_history.md +131 -0
- mt5cli-0.4.1/docs/api/utils.md +3 -0
- {mt5cli-0.3.0 → mt5cli-0.4.1}/docs/index.md +43 -1
- {mt5cli-0.3.0 → mt5cli-0.4.1}/mkdocs.yml +4 -0
- mt5cli-0.4.1/mt5cli/__init__.py +62 -0
- mt5cli-0.4.1/mt5cli/cli.py +612 -0
- mt5cli-0.4.1/mt5cli/sdk.py +917 -0
- mt5cli-0.4.1/mt5cli/sqlite_history.py +1176 -0
- mt5cli-0.4.1/mt5cli/utils.py +408 -0
- {mt5cli-0.3.0 → mt5cli-0.4.1}/pyproject.toml +2 -5
- {mt5cli-0.3.0 → mt5cli-0.4.1}/tests/test_cli.py +15 -319
- mt5cli-0.4.1/tests/test_sdk.py +810 -0
- mt5cli-0.4.1/tests/test_sqlite_history.py +1497 -0
- mt5cli-0.4.1/tests/test_utils.py +335 -0
- {mt5cli-0.3.0 → mt5cli-0.4.1}/uv.lock +1 -1
- mt5cli-0.3.0/mt5cli/__init__.py +0 -12
- mt5cli-0.3.0/mt5cli/cli.py +0 -1452
- {mt5cli-0.3.0 → mt5cli-0.4.1}/.agents/skills/local-qa/SKILL.md +0 -0
- {mt5cli-0.3.0 → mt5cli-0.4.1}/.agents/skills/local-qa/scripts/qa.sh +0 -0
- {mt5cli-0.3.0 → mt5cli-0.4.1}/.agents/skills/mt5cli/SKILL.md +0 -0
- {mt5cli-0.3.0 → mt5cli-0.4.1}/.claude/agents/codex.md +0 -0
- {mt5cli-0.3.0 → mt5cli-0.4.1}/.claude/settings.json +0 -0
- {mt5cli-0.3.0 → mt5cli-0.4.1}/.github/FUNDING.yml +0 -0
- {mt5cli-0.3.0 → mt5cli-0.4.1}/.github/dependabot.yml +0 -0
- {mt5cli-0.3.0 → mt5cli-0.4.1}/.github/renovate.json +0 -0
- {mt5cli-0.3.0 → mt5cli-0.4.1}/.github/workflows/ci.yml +0 -0
- {mt5cli-0.3.0 → mt5cli-0.4.1}/.github/workflows/claude.yml +0 -0
- {mt5cli-0.3.0 → mt5cli-0.4.1}/.github/workflows/release.yml +0 -0
- {mt5cli-0.3.0 → mt5cli-0.4.1}/.gitignore +0 -0
- {mt5cli-0.3.0 → mt5cli-0.4.1}/CLAUDE.md +0 -0
- {mt5cli-0.3.0 → mt5cli-0.4.1}/LICENSE +0 -0
- {mt5cli-0.3.0 → mt5cli-0.4.1}/docs/api/cli.md +0 -0
- {mt5cli-0.3.0 → mt5cli-0.4.1}/mt5cli/__main__.py +0 -0
- {mt5cli-0.3.0 → mt5cli-0.4.1}/tests/__init__.py +0 -0
|
@@ -29,9 +29,11 @@ uv sync
|
|
|
29
29
|
- `mt5cli/`: Main package directory
|
|
30
30
|
- `__init__.py`: Package initialization and exports (`detect_format`, `export_dataframe`)
|
|
31
31
|
- `cli.py`: CLI application with typer-based commands for data export
|
|
32
|
+
- `utils.py`: Constants, enums, parameter types, parsers, and export utilities
|
|
32
33
|
- `__main__.py`: Entry point for `python -m mt5cli`
|
|
33
34
|
- `tests/`: Comprehensive test suite (pytest-based)
|
|
34
|
-
- `test_cli.py`: Tests for CLI commands
|
|
35
|
+
- `test_cli.py`: Tests for CLI commands and collect-history behavior
|
|
36
|
+
- `test_utils.py`: Tests for utility constants, parameter types, parsers, and export functions
|
|
35
37
|
- `docs/`: MkDocs documentation with API reference
|
|
36
38
|
- `docs/index.md`: Main documentation
|
|
37
39
|
- `docs/api/`: Auto-generated API documentation for all modules
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mt5cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.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>
|
|
@@ -111,7 +111,46 @@ mt5cli -o history.db collect-history \
|
|
|
111
111
|
--timeframe M1 --flags ALL --if-exists append --with-views
|
|
112
112
|
```
|
|
113
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
|
|
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-side entries, and uses volume-weighted open/close prices; reversal deals (`DEAL_ENTRY_INOUT`) are reported via `volume_reversal` / `reversal_count` columns.
|
|
115
|
+
|
|
116
|
+
### Incremental history SDK
|
|
117
|
+
|
|
118
|
+
For automated pipelines, use the importable incremental API instead of re-fetching fixed date ranges:
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
from pdmt5 import Mt5Config, Mt5DataClient
|
|
122
|
+
from mt5cli import Dataset, update_history, update_history_with_config
|
|
123
|
+
|
|
124
|
+
# Reuse an already-connected pdmt5 client (does not open/close MT5)
|
|
125
|
+
client = Mt5DataClient(config=Mt5Config(login=12345))
|
|
126
|
+
client.initialize_and_login_mt5()
|
|
127
|
+
try:
|
|
128
|
+
update_history(
|
|
129
|
+
client=client,
|
|
130
|
+
output="history.db",
|
|
131
|
+
symbols=["EURUSD", "GBPUSD"],
|
|
132
|
+
datasets={Dataset.rates, Dataset.history_deals},
|
|
133
|
+
timeframes=["M1", "H1"], # default: all fixed MT5 timeframes
|
|
134
|
+
lookback_hours=24,
|
|
135
|
+
create_rate_views=True,
|
|
136
|
+
with_views=True,
|
|
137
|
+
include_account_events=True,
|
|
138
|
+
)
|
|
139
|
+
finally:
|
|
140
|
+
client.shutdown()
|
|
141
|
+
|
|
142
|
+
# Standalone wrapper that opens and closes MT5 for you
|
|
143
|
+
update_history_with_config(
|
|
144
|
+
output="history.db",
|
|
145
|
+
symbols=["EURUSD"],
|
|
146
|
+
config=Mt5Config(login=12345),
|
|
147
|
+
)
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
- **`collect-history`**: explicit date-range export into SQLite.
|
|
151
|
+
- **`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
|
+
- **`rates` table**: normalized storage with `symbol` and `timeframe` columns.
|
|
153
|
+
- **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.
|
|
115
154
|
|
|
116
155
|
## Requirements
|
|
117
156
|
|
|
@@ -87,7 +87,46 @@ mt5cli -o history.db collect-history \
|
|
|
87
87
|
--timeframe M1 --flags ALL --if-exists append --with-views
|
|
88
88
|
```
|
|
89
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
|
|
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-side entries, and uses volume-weighted open/close prices; reversal deals (`DEAL_ENTRY_INOUT`) are reported via `volume_reversal` / `reversal_count` columns.
|
|
91
|
+
|
|
92
|
+
### Incremental history SDK
|
|
93
|
+
|
|
94
|
+
For automated pipelines, use the importable incremental API instead of re-fetching fixed date ranges:
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from pdmt5 import Mt5Config, Mt5DataClient
|
|
98
|
+
from mt5cli import Dataset, update_history, update_history_with_config
|
|
99
|
+
|
|
100
|
+
# Reuse an already-connected pdmt5 client (does not open/close MT5)
|
|
101
|
+
client = Mt5DataClient(config=Mt5Config(login=12345))
|
|
102
|
+
client.initialize_and_login_mt5()
|
|
103
|
+
try:
|
|
104
|
+
update_history(
|
|
105
|
+
client=client,
|
|
106
|
+
output="history.db",
|
|
107
|
+
symbols=["EURUSD", "GBPUSD"],
|
|
108
|
+
datasets={Dataset.rates, Dataset.history_deals},
|
|
109
|
+
timeframes=["M1", "H1"], # default: all fixed MT5 timeframes
|
|
110
|
+
lookback_hours=24,
|
|
111
|
+
create_rate_views=True,
|
|
112
|
+
with_views=True,
|
|
113
|
+
include_account_events=True,
|
|
114
|
+
)
|
|
115
|
+
finally:
|
|
116
|
+
client.shutdown()
|
|
117
|
+
|
|
118
|
+
# Standalone wrapper that opens and closes MT5 for you
|
|
119
|
+
update_history_with_config(
|
|
120
|
+
output="history.db",
|
|
121
|
+
symbols=["EURUSD"],
|
|
122
|
+
config=Mt5Config(login=12345),
|
|
123
|
+
)
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
- **`collect-history`**: explicit date-range export into SQLite.
|
|
127
|
+
- **`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
|
+
- **`rates` table**: normalized storage with `symbol` and `timeframe` columns.
|
|
129
|
+
- **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.
|
|
91
130
|
|
|
92
131
|
## Requirements
|
|
93
132
|
|
|
@@ -10,12 +10,22 @@ The mt5cli package consists of the following modules:
|
|
|
10
10
|
|
|
11
11
|
Command-line interface module providing typer-based commands for exporting MetaTrader 5 data to CSV, JSON, Parquet, and SQLite3 formats.
|
|
12
12
|
|
|
13
|
+
### [Utils](utils.md)
|
|
14
|
+
|
|
15
|
+
Utility module providing constants, enums, Click parameter types, and helper functions for parsing and exporting data.
|
|
16
|
+
|
|
17
|
+
### [SDK](sdk.md)
|
|
18
|
+
|
|
19
|
+
Programmatic SDK for read-only MetaTrader 5 data collection. Returns pandas DataFrames and provides `collect_history` for SQLite bulk collection.
|
|
20
|
+
|
|
13
21
|
## Architecture Overview
|
|
14
22
|
|
|
15
23
|
The package follows a simple architecture built on top of pdmt5:
|
|
16
24
|
|
|
17
|
-
1. **CLI Layer** (`cli.py`): Typer application with subcommands
|
|
18
|
-
2. **
|
|
25
|
+
1. **CLI Layer** (`cli.py`): Typer application with subcommands that delegate to the SDK and export results.
|
|
26
|
+
2. **SDK Layer** (`sdk.py`): Read-only data access functions, `Mt5CliClient`, and `collect_history` orchestration.
|
|
27
|
+
3. **Utils Layer** (`utils.py`): Constants, enums, custom Click parameter types, parsing helpers, and format detection/export utilities.
|
|
28
|
+
4. **Data Layer** (via `pdmt5`): Uses `Mt5DataClient` and `Mt5Config` from the pdmt5 package for all MetaTrader 5 data access.
|
|
19
29
|
|
|
20
30
|
## Usage Guidelines
|
|
21
31
|
|
|
@@ -47,15 +57,38 @@ mt5cli -o data.db --table symbols symbols --group "*USD*"
|
|
|
47
57
|
## Python API
|
|
48
58
|
|
|
49
59
|
```python
|
|
50
|
-
from
|
|
51
|
-
|
|
60
|
+
from datetime import UTC, datetime
|
|
61
|
+
from pathlib import Path
|
|
62
|
+
|
|
63
|
+
from mt5cli import (
|
|
64
|
+
Mt5CliClient,
|
|
65
|
+
collect_history,
|
|
66
|
+
copy_rates_range,
|
|
67
|
+
detect_format,
|
|
68
|
+
export_dataframe,
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
# Fetch rates programmatically
|
|
72
|
+
rates = copy_rates_range(
|
|
73
|
+
"EURUSD",
|
|
74
|
+
timeframe="H1",
|
|
75
|
+
date_from="2024-01-01",
|
|
76
|
+
date_to="2024-02-01",
|
|
77
|
+
)
|
|
52
78
|
|
|
53
79
|
# Detect output format from file extension
|
|
54
80
|
fmt = detect_format(Path("output.parquet")) # Returns "parquet"
|
|
55
81
|
|
|
56
82
|
# Export a DataFrame
|
|
57
|
-
|
|
58
|
-
|
|
83
|
+
export_dataframe(rates, Path("output.csv"), "csv")
|
|
84
|
+
|
|
85
|
+
# Collect history into SQLite
|
|
86
|
+
collect_history(
|
|
87
|
+
Path("history.db"),
|
|
88
|
+
symbols=["EURUSD"],
|
|
89
|
+
date_from=datetime(2024, 1, 1, tzinfo=UTC),
|
|
90
|
+
date_to=datetime(2024, 2, 1, tzinfo=UTC),
|
|
91
|
+
)
|
|
59
92
|
```
|
|
60
93
|
|
|
61
94
|
## Examples
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# SQLite History Module
|
|
2
|
+
|
|
3
|
+
::: mt5cli.sqlite_history
|
|
4
|
+
|
|
5
|
+
## `collect-history` schema
|
|
6
|
+
|
|
7
|
+
The `collect-history` command (and the matching `collect_history` SDK function) writes
|
|
8
|
+
selected MT5 datasets into one SQLite database. Each dataset becomes a table; column
|
|
9
|
+
names and types mirror the pdmt5 DataFrame schema for that export, with two additions:
|
|
10
|
+
|
|
11
|
+
- `symbol` is prepended on every table.
|
|
12
|
+
- `timeframe` is prepended on `rates` so appended runs at different bar sizes stay
|
|
13
|
+
distinguishable.
|
|
14
|
+
|
|
15
|
+
SQLite does not declare foreign keys. Rows are linked logically by `symbol`, time
|
|
16
|
+
windows, and (for deals) `position_id` / `order`. Duplicate rows are removed on
|
|
17
|
+
append using dataset-specific keys (for example `ticket` on history tables, or
|
|
18
|
+
`(symbol, timeframe, time)` on rates).
|
|
19
|
+
|
|
20
|
+
Optional views are created when `--with-views` is set and the `history-deals` dataset
|
|
21
|
+
was written.
|
|
22
|
+
|
|
23
|
+
### Entity-relationship diagram
|
|
24
|
+
|
|
25
|
+
Sample layout for a full collection with `--with-views`:
|
|
26
|
+
|
|
27
|
+
```mermaid
|
|
28
|
+
erDiagram
|
|
29
|
+
rates {
|
|
30
|
+
TEXT symbol "dedup key"
|
|
31
|
+
INTEGER timeframe "dedup key"
|
|
32
|
+
TEXT time "dedup key"
|
|
33
|
+
REAL open
|
|
34
|
+
REAL high
|
|
35
|
+
REAL low
|
|
36
|
+
REAL close
|
|
37
|
+
INTEGER tick_volume
|
|
38
|
+
INTEGER spread
|
|
39
|
+
INTEGER real_volume
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
ticks {
|
|
43
|
+
TEXT symbol "dedup key"
|
|
44
|
+
TEXT time "dedup key"
|
|
45
|
+
INTEGER time_msc "dedup key (preferred)"
|
|
46
|
+
REAL bid
|
|
47
|
+
REAL ask
|
|
48
|
+
REAL last
|
|
49
|
+
INTEGER volume
|
|
50
|
+
INTEGER flags
|
|
51
|
+
REAL volume_real
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
history_orders {
|
|
55
|
+
INTEGER ticket "dedup key"
|
|
56
|
+
TEXT symbol
|
|
57
|
+
TEXT time
|
|
58
|
+
INTEGER type
|
|
59
|
+
INTEGER state
|
|
60
|
+
REAL volume_initial
|
|
61
|
+
REAL price_open
|
|
62
|
+
REAL price_current
|
|
63
|
+
INTEGER magic
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
history_deals {
|
|
67
|
+
INTEGER ticket "dedup key"
|
|
68
|
+
INTEGER order
|
|
69
|
+
INTEGER position_id "groups position view"
|
|
70
|
+
TEXT symbol
|
|
71
|
+
TEXT time
|
|
72
|
+
INTEGER type "0/1 trade, else cash event"
|
|
73
|
+
INTEGER entry "0 IN, 1 OUT, 2 INOUT, 3 OUT_BY"
|
|
74
|
+
REAL volume
|
|
75
|
+
REAL price
|
|
76
|
+
REAL profit
|
|
77
|
+
REAL commission
|
|
78
|
+
REAL swap
|
|
79
|
+
REAL fee
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
cash_events {
|
|
83
|
+
INTEGER ticket
|
|
84
|
+
TEXT symbol
|
|
85
|
+
TEXT time
|
|
86
|
+
INTEGER type
|
|
87
|
+
REAL profit
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
positions_reconstructed {
|
|
91
|
+
INTEGER position_id
|
|
92
|
+
TEXT symbol
|
|
93
|
+
TEXT open_time
|
|
94
|
+
TEXT close_time
|
|
95
|
+
INTEGER direction
|
|
96
|
+
REAL volume_open
|
|
97
|
+
REAL volume_close
|
|
98
|
+
REAL volume_reversal
|
|
99
|
+
REAL open_price
|
|
100
|
+
REAL close_price
|
|
101
|
+
REAL total_profit
|
|
102
|
+
INTEGER reversal_count
|
|
103
|
+
INTEGER deals_count
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
rates ||--o{ history_deals : "symbol (logical)"
|
|
107
|
+
ticks ||--o{ history_deals : "symbol (logical)"
|
|
108
|
+
history_orders ||--o{ history_deals : "order ~ ticket (logical)"
|
|
109
|
+
history_deals ||--|| cash_events : "VIEW: type NOT IN (0,1)"
|
|
110
|
+
history_deals ||--o{ positions_reconstructed : "VIEW: GROUP BY position_id"
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Tables and views
|
|
114
|
+
|
|
115
|
+
| Object | Kind | Source | Notes |
|
|
116
|
+
| ------------------------- | ----- | -------------------- | ------------------------------------------------------------------------------------------- |
|
|
117
|
+
| `rates` | table | `copy_rates_range` | Indexed on `(symbol, timeframe, time)` when columns exist. |
|
|
118
|
+
| `ticks` | table | `copy_ticks_range` | Indexed on `(symbol, time)` when columns exist. |
|
|
119
|
+
| `history_orders` | table | `history_orders_get` | Fetched per `--symbol`, then concatenated. |
|
|
120
|
+
| `history_deals` | table | `history_deals_get` | Fetched per `--symbol`, then concatenated. Indexed on `(position_id, symbol)` when present. |
|
|
121
|
+
| `cash_events` | view | `history_deals` | Non-trade deal types (deposits, balance ops, etc.). Requires `type` column. |
|
|
122
|
+
| `positions_reconstructed` | view | `history_deals` | One row per closed `position_id`; volume-weighted prices and reversal stats. |
|
|
123
|
+
|
|
124
|
+
Column sets can vary with terminal and pdmt5 version. Views are skipped with a warning
|
|
125
|
+
when required columns are missing.
|
|
126
|
+
|
|
127
|
+
### Incremental collection
|
|
128
|
+
|
|
129
|
+
The `update_history` SDK path uses the same base tables and optional
|
|
130
|
+
`cash_events` / `positions_reconstructed` views. It additionally maintains
|
|
131
|
+
`rate_<symbol>__<timeframe>` compatibility views when `create_rate_views=True`.
|
|
@@ -20,6 +20,44 @@ mt5cli is a CLI application that exports MetaTrader 5 trading data to multiple f
|
|
|
20
20
|
pip install mt5cli
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
+
## Programmatic usage / SDK usage
|
|
24
|
+
|
|
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
|
+
|
|
27
|
+
```python
|
|
28
|
+
from datetime import UTC, datetime
|
|
29
|
+
from pathlib import Path
|
|
30
|
+
|
|
31
|
+
from mt5cli import Mt5CliClient, collect_history, copy_rates_range, export_dataframe
|
|
32
|
+
|
|
33
|
+
# One-off fetch with module-level helpers
|
|
34
|
+
rates = copy_rates_range(
|
|
35
|
+
"EURUSD",
|
|
36
|
+
timeframe="H1",
|
|
37
|
+
date_from="2024-01-01",
|
|
38
|
+
date_to="2024-02-01",
|
|
39
|
+
)
|
|
40
|
+
export_dataframe(rates, Path("rates.csv"), "csv")
|
|
41
|
+
|
|
42
|
+
# Reuse one MT5 connection for multiple calls
|
|
43
|
+
with Mt5CliClient(login=12345, password="secret", server="Broker-Demo") as client:
|
|
44
|
+
account = client.account_info()
|
|
45
|
+
positions = client.positions()
|
|
46
|
+
|
|
47
|
+
# Bulk SQLite collection (same behavior as the collect-history CLI command)
|
|
48
|
+
collect_history(
|
|
49
|
+
Path("history.db"),
|
|
50
|
+
symbols=["EURUSD", "GBPUSD"],
|
|
51
|
+
date_from=datetime(2024, 1, 1, tzinfo=UTC),
|
|
52
|
+
date_to=datetime(2024, 2, 1, tzinfo=UTC),
|
|
53
|
+
timeframe="M1",
|
|
54
|
+
flags="ALL",
|
|
55
|
+
with_views=True,
|
|
56
|
+
)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Timeframes, tick flags, and ISO 8601 date strings are accepted wherever noted in the SDK API.
|
|
60
|
+
|
|
23
61
|
## Quick Start
|
|
24
62
|
|
|
25
63
|
```bash
|
|
@@ -114,6 +152,8 @@ mt5cli -o history.db collect-history \
|
|
|
114
152
|
|
|
115
153
|
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
154
|
|
|
155
|
+
See the [SQLite History schema diagram](api/sqlite_history.md#entity-relationship-diagram) for a sample ER layout of the resulting database.
|
|
156
|
+
|
|
117
157
|
## Global Options
|
|
118
158
|
|
|
119
159
|
| Option | Description |
|
|
@@ -138,7 +178,9 @@ History orders and deals are fetched per symbol and concatenated, so the symbol
|
|
|
138
178
|
|
|
139
179
|
Browse the API documentation for detailed module information:
|
|
140
180
|
|
|
141
|
-
- [CLI Module](api/cli.md) - CLI application with export commands
|
|
181
|
+
- [CLI Module](api/cli.md) - CLI application with export commands
|
|
182
|
+
- [SDK Module](api/sdk.md) - Programmatic read-only data collection API
|
|
183
|
+
- [Utils Module](api/utils.md) - Constants, parameter types, parsers, and export utilities
|
|
142
184
|
|
|
143
185
|
## Development
|
|
144
186
|
|
|
@@ -24,6 +24,7 @@ theme:
|
|
|
24
24
|
features:
|
|
25
25
|
- content.code.annotate
|
|
26
26
|
- content.code.copy
|
|
27
|
+
- content.code.mermaid
|
|
27
28
|
- navigation.indexes
|
|
28
29
|
- navigation.sections
|
|
29
30
|
- navigation.tabs
|
|
@@ -56,6 +57,9 @@ nav:
|
|
|
56
57
|
- API Reference:
|
|
57
58
|
- Overview: api/index.md
|
|
58
59
|
- CLI: api/cli.md
|
|
60
|
+
- SDK: api/sdk.md
|
|
61
|
+
- SQLite History: api/sqlite_history.md
|
|
62
|
+
- Utils: api/utils.md
|
|
59
63
|
|
|
60
64
|
markdown_extensions:
|
|
61
65
|
- admonition
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""mt5cli: Command-line tool and SDK for MetaTrader 5."""
|
|
2
|
+
|
|
3
|
+
from importlib.metadata import version
|
|
4
|
+
|
|
5
|
+
from .sdk import (
|
|
6
|
+
Mt5CliClient,
|
|
7
|
+
account_info,
|
|
8
|
+
build_config,
|
|
9
|
+
collect_history,
|
|
10
|
+
copy_rates_from,
|
|
11
|
+
copy_rates_from_pos,
|
|
12
|
+
copy_rates_range,
|
|
13
|
+
copy_ticks_from,
|
|
14
|
+
copy_ticks_range,
|
|
15
|
+
history_deals,
|
|
16
|
+
history_orders,
|
|
17
|
+
last_error,
|
|
18
|
+
market_book,
|
|
19
|
+
orders,
|
|
20
|
+
positions,
|
|
21
|
+
symbol_info,
|
|
22
|
+
symbol_info_tick,
|
|
23
|
+
symbols,
|
|
24
|
+
terminal_info,
|
|
25
|
+
update_history,
|
|
26
|
+
update_history_with_config,
|
|
27
|
+
)
|
|
28
|
+
from .sdk import (
|
|
29
|
+
version as mt5_version,
|
|
30
|
+
)
|
|
31
|
+
from .utils import Dataset, IfExists, detect_format, export_dataframe
|
|
32
|
+
|
|
33
|
+
__version__ = version(__package__) if __package__ else None
|
|
34
|
+
|
|
35
|
+
__all__ = [
|
|
36
|
+
"Dataset",
|
|
37
|
+
"IfExists",
|
|
38
|
+
"Mt5CliClient",
|
|
39
|
+
"account_info",
|
|
40
|
+
"build_config",
|
|
41
|
+
"collect_history",
|
|
42
|
+
"copy_rates_from",
|
|
43
|
+
"copy_rates_from_pos",
|
|
44
|
+
"copy_rates_range",
|
|
45
|
+
"copy_ticks_from",
|
|
46
|
+
"copy_ticks_range",
|
|
47
|
+
"detect_format",
|
|
48
|
+
"export_dataframe",
|
|
49
|
+
"history_deals",
|
|
50
|
+
"history_orders",
|
|
51
|
+
"last_error",
|
|
52
|
+
"market_book",
|
|
53
|
+
"mt5_version",
|
|
54
|
+
"orders",
|
|
55
|
+
"positions",
|
|
56
|
+
"symbol_info",
|
|
57
|
+
"symbol_info_tick",
|
|
58
|
+
"symbols",
|
|
59
|
+
"terminal_info",
|
|
60
|
+
"update_history",
|
|
61
|
+
"update_history_with_config",
|
|
62
|
+
]
|