mt5cli 0.9.1__tar.gz → 0.9.3__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 (56) hide show
  1. {mt5cli-0.9.1 → mt5cli-0.9.3}/PKG-INFO +4 -4
  2. {mt5cli-0.9.1 → mt5cli-0.9.3}/README.md +3 -3
  3. {mt5cli-0.9.1 → mt5cli-0.9.3}/docs/api/public-contract.md +72 -45
  4. {mt5cli-0.9.1 → mt5cli-0.9.3}/docs/api/sdk.md +3 -3
  5. {mt5cli-0.9.1 → mt5cli-0.9.3}/docs/api/trading.md +2 -2
  6. {mt5cli-0.9.1 → mt5cli-0.9.3}/docs/index.md +1 -1
  7. {mt5cli-0.9.1 → mt5cli-0.9.3}/mt5cli/__init__.py +21 -3
  8. {mt5cli-0.9.1 → mt5cli-0.9.3}/mt5cli/client.py +1 -3
  9. {mt5cli-0.9.1 → mt5cli-0.9.3}/mt5cli/contract.py +71 -29
  10. {mt5cli-0.9.1 → mt5cli-0.9.3}/mt5cli/trading.py +349 -63
  11. {mt5cli-0.9.1 → mt5cli-0.9.3}/pyproject.toml +1 -1
  12. {mt5cli-0.9.1 → mt5cli-0.9.3}/tests/test_contracts.py +76 -4
  13. {mt5cli-0.9.1 → mt5cli-0.9.3}/tests/test_trading.py +831 -76
  14. {mt5cli-0.9.1 → mt5cli-0.9.3}/uv.lock +1 -1
  15. {mt5cli-0.9.1 → mt5cli-0.9.3}/.agents/skills/local-qa/SKILL.md +0 -0
  16. {mt5cli-0.9.1 → mt5cli-0.9.3}/.agents/skills/local-qa/scripts/qa.sh +0 -0
  17. {mt5cli-0.9.1 → mt5cli-0.9.3}/.agents/skills/mt5cli/SKILL.md +0 -0
  18. {mt5cli-0.9.1 → mt5cli-0.9.3}/.agents/skills/pr-feedback-triage/SKILL.md +0 -0
  19. {mt5cli-0.9.1 → mt5cli-0.9.3}/.claude/agents/codex.md +0 -0
  20. {mt5cli-0.9.1 → mt5cli-0.9.3}/.claude/settings.json +0 -0
  21. {mt5cli-0.9.1 → mt5cli-0.9.3}/.github/FUNDING.yml +0 -0
  22. {mt5cli-0.9.1 → mt5cli-0.9.3}/.github/dependabot.yml +0 -0
  23. {mt5cli-0.9.1 → mt5cli-0.9.3}/.github/renovate.json +0 -0
  24. {mt5cli-0.9.1 → mt5cli-0.9.3}/.github/workflows/ci.yml +0 -0
  25. {mt5cli-0.9.1 → mt5cli-0.9.3}/.github/workflows/claude.yml +0 -0
  26. {mt5cli-0.9.1 → mt5cli-0.9.3}/.github/workflows/release.yml +0 -0
  27. {mt5cli-0.9.1 → mt5cli-0.9.3}/.gitignore +0 -0
  28. {mt5cli-0.9.1 → mt5cli-0.9.3}/AGENTS.md +0 -0
  29. {mt5cli-0.9.1 → mt5cli-0.9.3}/CLAUDE.md +0 -0
  30. {mt5cli-0.9.1 → mt5cli-0.9.3}/LICENSE +0 -0
  31. {mt5cli-0.9.1 → mt5cli-0.9.3}/docs/api/cli.md +0 -0
  32. {mt5cli-0.9.1 → mt5cli-0.9.3}/docs/api/client.md +0 -0
  33. {mt5cli-0.9.1 → mt5cli-0.9.3}/docs/api/converters.md +0 -0
  34. {mt5cli-0.9.1 → mt5cli-0.9.3}/docs/api/exceptions.md +0 -0
  35. {mt5cli-0.9.1 → mt5cli-0.9.3}/docs/api/history.md +0 -0
  36. {mt5cli-0.9.1 → mt5cli-0.9.3}/docs/api/index.md +0 -0
  37. {mt5cli-0.9.1 → mt5cli-0.9.3}/docs/api/schemas.md +0 -0
  38. {mt5cli-0.9.1 → mt5cli-0.9.3}/docs/api/storage.md +0 -0
  39. {mt5cli-0.9.1 → mt5cli-0.9.3}/docs/api/utils.md +0 -0
  40. {mt5cli-0.9.1 → mt5cli-0.9.3}/mkdocs.yml +0 -0
  41. {mt5cli-0.9.1 → mt5cli-0.9.3}/mt5cli/__main__.py +0 -0
  42. {mt5cli-0.9.1 → mt5cli-0.9.3}/mt5cli/cli.py +0 -0
  43. {mt5cli-0.9.1 → mt5cli-0.9.3}/mt5cli/converters.py +0 -0
  44. {mt5cli-0.9.1 → mt5cli-0.9.3}/mt5cli/exceptions.py +0 -0
  45. {mt5cli-0.9.1 → mt5cli-0.9.3}/mt5cli/history.py +0 -0
  46. {mt5cli-0.9.1 → mt5cli-0.9.3}/mt5cli/retry.py +0 -0
  47. {mt5cli-0.9.1 → mt5cli-0.9.3}/mt5cli/schemas.py +0 -0
  48. {mt5cli-0.9.1 → mt5cli-0.9.3}/mt5cli/sdk.py +0 -0
  49. {mt5cli-0.9.1 → mt5cli-0.9.3}/mt5cli/storage.py +0 -0
  50. {mt5cli-0.9.1 → mt5cli-0.9.3}/mt5cli/utils.py +0 -0
  51. {mt5cli-0.9.1 → mt5cli-0.9.3}/tests/__init__.py +0 -0
  52. {mt5cli-0.9.1 → mt5cli-0.9.3}/tests/conftest.py +0 -0
  53. {mt5cli-0.9.1 → mt5cli-0.9.3}/tests/test_cli.py +0 -0
  54. {mt5cli-0.9.1 → mt5cli-0.9.3}/tests/test_history.py +0 -0
  55. {mt5cli-0.9.1 → mt5cli-0.9.3}/tests/test_sdk.py +0 -0
  56. {mt5cli-0.9.1 → mt5cli-0.9.3}/tests/test_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mt5cli
3
- Version: 0.9.1
3
+ Version: 0.9.3
4
4
  Summary: Generic MT5 data and execution infrastructure for Python applications
5
5
  Project-URL: Repository, https://github.com/dceoy/mt5cli.git
6
6
  Author-email: dceoy <dceoy@users.noreply.github.com>
@@ -55,7 +55,7 @@ pip install -U mt5cli MetaTrader5
55
55
 
56
56
  ## Python API (downstream packages)
57
57
 
58
- Import `MT5Client` for generic MT5 data access, schema normalization, and optional order primitives. `Mt5CliClient` remains available as a backward-compatible alias.
58
+ Import `MT5Client` for generic MT5 data access, schema normalization, and optional order primitives.
59
59
 
60
60
  ```python
61
61
  from datetime import UTC, datetime
@@ -274,7 +274,7 @@ eurusd_m1 = rates["EURUSD", "M1"] # closed bars only
274
274
 
275
275
  - **Credential resolution**: use `resolve_account_spec()` / `resolve_account_specs()` to merge explicit override values over `AccountSpec` fields and expand `${ENV_VAR}` placeholders (via `substitute_env_placeholders()`), raising `ValueError` for missing variables. This keeps secrets out of plan/config files without coupling to any strategy code.
276
276
  - **Throttled history updates**: use `ThrottledHistoryUpdater` to wrap `update_history()` with a minimum `interval_seconds` between successful runs (monotonic clock). Call `should_update()` / `update(client, symbols)` from an application loop; errors propagate by default, or pass `suppress_errors=True` to swallow recoverable `Mt5*Error`, `sqlite3.Error`, `ValueError`, `OSError`, and MT5 client capability errors for history API methods without advancing the throttle (other `AttributeError` / `TypeError` values always propagate). Pass `update_backend` to inject a custom history update callable (same keyword arguments as `update_history`) instead of monkey-patching `mt5cli.sdk.update_history`.
277
- - **Trading session helpers**: use `mt5_trading_session()` for a trading-capable `pdmt5.Mt5TradingClient` that initializes/logs in via `Mt5Config.path` and always shuts down safely. Pair with `detect_position_side()`, `calculate_margin_and_volume()`, and `determine_order_limits()` for generic position and sizing utilities. The read-only `mt5_session()` / `Mt5CliClient` SDK is unchanged.
277
+ - **Trading session helpers**: use `mt5_trading_session()` for a trading-capable `pdmt5.Mt5TradingClient` that initializes/logs in via `Mt5Config.path` and always shuts down safely. Pair with `detect_position_side()`, `calculate_margin_and_volume()`, and `determine_order_limits()` for generic position and sizing utilities. Keep read-only collection on `mt5_session()` / `MT5Client`.
278
278
  - **Granularity-keyed rate loading**: `load_rate_series_by_granularity()` builds targets with `build_rate_targets()`, loads them with `load_rate_series_from_sqlite()`, and returns a mapping keyed by `(symbol | None, granularity_name)` such as `("EURUSD", "M1")` to reduce downstream boilerplate.
279
279
  - **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 `MT5Client` that shuts down on exit.
280
280
  - **SQLite export helpers**: use `export_dataframe_to_sqlite()` for append mode, optional index export, and post-write deduplication by key columns.
@@ -341,7 +341,7 @@ finally:
341
341
  client.shutdown()
342
342
  ```
343
343
 
344
- Read-only collectors can keep using `mt5_session()` and `MT5Client` (or the `Mt5CliClient` alias) without changes.
344
+ Read-only collectors can keep using `mt5_session()` and `MT5Client`.
345
345
 
346
346
  ## Development
347
347
 
@@ -31,7 +31,7 @@ pip install -U mt5cli MetaTrader5
31
31
 
32
32
  ## Python API (downstream packages)
33
33
 
34
- Import `MT5Client` for generic MT5 data access, schema normalization, and optional order primitives. `Mt5CliClient` remains available as a backward-compatible alias.
34
+ Import `MT5Client` for generic MT5 data access, schema normalization, and optional order primitives.
35
35
 
36
36
  ```python
37
37
  from datetime import UTC, datetime
@@ -250,7 +250,7 @@ eurusd_m1 = rates["EURUSD", "M1"] # closed bars only
250
250
 
251
251
  - **Credential resolution**: use `resolve_account_spec()` / `resolve_account_specs()` to merge explicit override values over `AccountSpec` fields and expand `${ENV_VAR}` placeholders (via `substitute_env_placeholders()`), raising `ValueError` for missing variables. This keeps secrets out of plan/config files without coupling to any strategy code.
252
252
  - **Throttled history updates**: use `ThrottledHistoryUpdater` to wrap `update_history()` with a minimum `interval_seconds` between successful runs (monotonic clock). Call `should_update()` / `update(client, symbols)` from an application loop; errors propagate by default, or pass `suppress_errors=True` to swallow recoverable `Mt5*Error`, `sqlite3.Error`, `ValueError`, `OSError`, and MT5 client capability errors for history API methods without advancing the throttle (other `AttributeError` / `TypeError` values always propagate). Pass `update_backend` to inject a custom history update callable (same keyword arguments as `update_history`) instead of monkey-patching `mt5cli.sdk.update_history`.
253
- - **Trading session helpers**: use `mt5_trading_session()` for a trading-capable `pdmt5.Mt5TradingClient` that initializes/logs in via `Mt5Config.path` and always shuts down safely. Pair with `detect_position_side()`, `calculate_margin_and_volume()`, and `determine_order_limits()` for generic position and sizing utilities. The read-only `mt5_session()` / `Mt5CliClient` SDK is unchanged.
253
+ - **Trading session helpers**: use `mt5_trading_session()` for a trading-capable `pdmt5.Mt5TradingClient` that initializes/logs in via `Mt5Config.path` and always shuts down safely. Pair with `detect_position_side()`, `calculate_margin_and_volume()`, and `determine_order_limits()` for generic position and sizing utilities. Keep read-only collection on `mt5_session()` / `MT5Client`.
254
254
  - **Granularity-keyed rate loading**: `load_rate_series_by_granularity()` builds targets with `build_rate_targets()`, loads them with `load_rate_series_from_sqlite()`, and returns a mapping keyed by `(symbol | None, granularity_name)` such as `("EURUSD", "M1")` to reduce downstream boilerplate.
255
255
  - **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 `MT5Client` that shuts down on exit.
256
256
  - **SQLite export helpers**: use `export_dataframe_to_sqlite()` for append mode, optional index export, and post-write deduplication by key columns.
@@ -317,7 +317,7 @@ finally:
317
317
  client.shutdown()
318
318
  ```
319
319
 
320
- Read-only collectors can keep using `mt5_session()` and `MT5Client` (or the `Mt5CliClient` alias) without changes.
320
+ Read-only collectors can keep using `mt5_session()` and `MT5Client`.
321
321
 
322
322
  ## Development
323
323
 
@@ -8,20 +8,29 @@ downstream app -> mt5cli -> pdmt5 -> MetaTrader 5
8
8
  ```
9
9
 
10
10
  Downstream packages should import from the package root (`from mt5cli import
11
- ...`) and treat the symbols listed below as the stable SDK contract. CLI
12
- commands mirror the same behavior but are not importable Python APIs.
11
+ ...`) and use the public tier sets in `mt5cli.contract` to distinguish API
12
+ stability. CLI commands mirror the same behavior but are not importable Python
13
+ APIs.
14
+
15
+ ## Public API tiers
16
+
17
+ mt5cli classifies package-root imports by intended downstream use:
18
+
19
+ | Tier | Contract set | Meaning |
20
+ | ---------------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
21
+ | Stable core | `STABLE_SDK_EXPORTS` | Preferred SDK surface for downstream MT5 infrastructure adapters. Changes require a deliberate compatibility path. |
22
+ | Secondary public | `SECONDARY_PUBLIC_EXPORTS` | Public helpers for CLI/export/schema integrations and lower-level MT5 wrappers. Importable, but less central to the downstream trading SDK. |
13
23
 
14
24
  ## Stable downstream SDK API
15
25
 
16
26
  These names are exported from `mt5cli` and covered by the contract in
17
- `mt5cli.STABLE_SDK_EXPORTS` (defined in `mt5cli.contract`). Prefer `MT5Client` over the legacy `Mt5CliClient`
18
- alias for new code.
27
+ `mt5cli.STABLE_SDK_EXPORTS` (defined in `mt5cli.contract`).
19
28
 
20
29
  ### Session lifecycle and configuration
21
30
 
22
31
  | Symbol | Role |
23
32
  | ----------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
24
- | `MT5Client`, `Mt5CliClient` | Read-only data client with optional `order_check` / `order_send` |
33
+ | `MT5Client` | Read-only data client with optional `order_check` / `order_send` |
25
34
  | `build_config` | Build `pdmt5.Mt5Config` from connection fields |
26
35
  | `mt5_session` | Context manager: initialize, login, yield client, shutdown |
27
36
  | `create_trading_client`, `mt5_trading_session` | Trading-capable `pdmt5.Mt5TradingClient` lifecycle |
@@ -40,23 +49,6 @@ Partial strings such as `"plan$pass"`, `"abc$ENV"`, or `"$ENV-suffix"` are
40
49
  **never** expanded — only an exact `$IDENTIFIER` whole-string match qualifies.
41
50
  Default is `False` to preserve backward compatibility.
42
51
 
43
- ### Read-only MT5 data access
44
-
45
- Module-level helpers open a transient connection per call. Prefer `mt5_session`
46
- or `MT5Client` when making many requests in one process.
47
-
48
- | Area | Symbols |
49
- | -------------------- | ---------------------------------------------------------------------------------------------------- |
50
- | Rates | `copy_rates_from`, `copy_rates_from_pos`, `copy_rates_range`, `latest_rates`, `collect_latest_rates` |
51
- | Ticks | `copy_ticks_from`, `copy_ticks_range`, `recent_ticks` |
52
- | Account / terminal | `account_info`, `terminal_info`, `mt5_version`, `last_error`, `mt5_summary`, `mt5_summary_as_df` |
53
- | Symbols / market | `symbols`, `symbol_info`, `symbol_info_tick`, `market_book`, `minimum_margins` |
54
- | Trading state (read) | `orders`, `positions`, `history_orders`, `history_deals`, `recent_history_deals` |
55
-
56
- Use `mt5_version` for MetaTrader 5 terminal version data. The name `version` at
57
- the package root refers to `importlib.metadata.version` (package metadata), not
58
- the MT5 SDK helper.
59
-
60
52
  ### Closed-bar rate helpers
61
53
 
62
54
  MetaTrader 5 returns the still-forming bar as the last row when
@@ -71,7 +63,6 @@ timestamp normalization in downstream apps.
71
63
  | `fetch_latest_closed_rates_indexed` | Same as above but returns a UTC `DatetimeIndex` named `"time"` (no time column) |
72
64
  | `collect_latest_closed_rates_for_accounts` | Multi-account closed bars with optional retry wrapper |
73
65
  | `collect_latest_closed_rates_by_granularity` | Same data keyed by `(symbol, granularity_name)` |
74
- | `collect_latest_rates_for_accounts` | Latest bars including the forming bar when `start_pos=0` |
75
66
  | `collect_latest_rates_for_accounts_with_retries` | Bounded exponential backoff for transient MT5 errors |
76
67
 
77
68
  ### SQLite history collection and rate loading
@@ -99,18 +90,24 @@ diagrams.
99
90
  These helpers implement broker-facing calculations only. They do not encode
100
91
  strategy entries, exits, Kelly sizing, or signal logic.
101
92
 
102
- | Symbol | Role |
103
- | -------------------------------------------------------------------------------------------------- | --------------------------------------------- |
104
- | `get_account_snapshot`, `get_symbol_snapshot`, `get_tick_snapshot`, `get_positions_frame` | Normalized account/symbol/tick/position views |
105
- | `detect_position_side` | Net long / short / flat from open positions |
106
- | `calculate_spread_ratio` | Relative bid-ask spread |
107
- | `calculate_margin_and_volume`, `calculate_volume_by_margin`, `calculate_new_position_margin_ratio` | Margin budget and volume sizing |
108
- | `normalize_order_volume`, `estimate_order_margin`, `calculate_positions_margin` | Broker volume normalization and margin totals |
109
- | `determine_order_limits` | SL/TP price levels from ratios |
110
- | `ensure_symbol_selected` | Select/verify Market Watch visibility |
111
- | `place_market_order`, `close_open_positions`, `update_sltp_for_open_positions` | Order execution helpers (`dry_run` supported) |
112
- | `MarginVolume`, `OrderLimits`, `OrderExecutionResult` | Typed return contracts for order helpers |
113
- | `OrderSide`, `OrderFillingMode`, `OrderTimeMode`, `PositionSide`, `ExecutionStatus` | Typed enums for order helpers |
93
+ | Symbol | Role |
94
+ | ------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------- |
95
+ | `get_account_snapshot`, `get_symbol_snapshot`, `get_tick_snapshot`, `get_positions_frame` | Normalized account/symbol/tick/position views |
96
+ | `extract_tick_price` | Positive finite bid/ask extraction from tick mappings |
97
+ | `detect_position_side` | Net long / short / flat from open positions |
98
+ | `calculate_spread_ratio` | Relative bid-ask spread |
99
+ | `calculate_margin_and_volume`, `calculate_volume_by_margin`, `calculate_new_position_margin_ratio` | Margin budget and volume sizing |
100
+ | `normalize_order_volume`, `estimate_order_margin`, `calculate_positions_margin` | Broker volume normalization and margin totals |
101
+ | `calculate_positions_margin_by_symbol` | Per-symbol margin map (resilient, first-seen order) |
102
+ | `calculate_positions_margin_safe` | Summed total margin across symbols (failed symbols skipped) |
103
+ | `calculate_projected_margin_ratio` | Estimated symbol margin/equity after optional new exposure |
104
+ | `calculate_symbol_group_margin_ratio` | Estimated symbol-group margin/equity with optional exposure |
105
+ | `determine_order_limits` | SL/TP price levels from ratios |
106
+ | `calculate_trailing_stop_updates` | Per-ticket generic trailing stop-loss update plan |
107
+ | `ensure_symbol_selected` | Select/verify Market Watch visibility |
108
+ | `place_market_order`, `close_open_positions`, `update_sltp_for_open_positions`, `update_trailing_stop_loss_for_open_positions` | Order execution helpers (`dry_run` supported) |
109
+ | `MarginVolume`, `OrderLimits`, `OrderExecutionResult` | Typed return contracts for order helpers |
110
+ | `OrderSide`, `OrderFillingMode`, `OrderTimeMode`, `PositionSide`, `ExecutionStatus` | Typed enums for order helpers |
114
111
 
115
112
  `MT5Client.order_send()` and CLI `order-send --yes` are live execution paths.
116
113
 
@@ -133,13 +130,43 @@ and returned as `status="failed"` with normalized `request` / `response` details
133
130
  | `normalize_mt5_exception`, `call_with_normalized_errors`, `is_recoverable_mt5_error` | Error normalization and retry classification |
134
131
  | `Mt5Config`, `Mt5RuntimeError`, `Mt5TradingClient`, `Mt5TradingError` | Re-exported pdmt5 types for adapter convenience |
135
132
 
136
- ### Additional public exports (secondary)
133
+ ## Secondary public exports
134
+
135
+ These names remain importable from `mt5cli` and are covered by
136
+ `SECONDARY_PUBLIC_EXPORTS`, but they are oriented toward CLI/export/schema
137
+ integrations, parsing, and lower-level MT5 access rather than the stable core
138
+ SDK surface. Prefer the stable symbols above for downstream infrastructure
139
+ adapters.
140
+
141
+ ### Read-only MT5 data wrappers
142
+
143
+ Module-level helpers open a transient connection per call. Prefer `mt5_session`
144
+ or `MT5Client` when making many requests in one process.
145
+
146
+ | Area | Symbols |
147
+ | -------------------- | ---------------------------------------------------------------------------------------------------- |
148
+ | Rates | `copy_rates_from`, `copy_rates_from_pos`, `copy_rates_range`, `latest_rates`, `collect_latest_rates` |
149
+ | Ticks | `copy_ticks_from`, `copy_ticks_range`, `recent_ticks` |
150
+ | Account / terminal | `account_info`, `terminal_info`, `mt5_version`, `last_error`, `mt5_summary`, `mt5_summary_as_df` |
151
+ | Symbols / market | `symbols`, `symbol_info`, `symbol_info_tick`, `market_book`, `minimum_margins` |
152
+ | Trading state (read) | `orders`, `positions`, `history_orders`, `history_deals`, `recent_history_deals` |
153
+ | Multi-account rates | `collect_latest_rates_for_accounts` |
154
+
155
+ Use `mt5_version` for MetaTrader 5 terminal version data. The name `version` at
156
+ the package root refers to `importlib.metadata.version` (package metadata), not
157
+ the MT5 SDK helper.
158
+
159
+ ### Schema, export, and parser helpers
137
160
 
138
- The package root also exports schema, storage, and parsing helpers (for example
139
- `DataKind`, `Dataset`, `normalize_dataframe`, `export_dataframe`,
140
- `parse_timeframe`, `TIMEFRAME_MAP`). These are public but oriented toward export
141
- pipelines and advanced integration. Prefer the stable symbols above for core
142
- infrastructure.
161
+ | Area | Symbols |
162
+ | -------------------- | ------------------------------------------------------------------------------------------------------------- |
163
+ | Dataset contracts | `DataKind`, `Dataset`, `IfExists`, `DEDUP_KEYS`, `REQUIRED_COLUMNS`, `TIME_COLUMNS`, `KNOWN_MT5_TIME_COLUMNS` |
164
+ | Schema normalization | `normalize_dataframe`, `normalize_time_columns`, `schema_columns`, `validate_schema` |
165
+ | Export helpers | `detect_format`, `export_dataframe`, `export_dataframe_to_sqlite` |
166
+ | Symbol parsing | `normalize_symbol`, `normalize_symbols` |
167
+ | Time parsing | `ensure_utc`, `parse_date_range`, `parse_datetime`, `recent_window` |
168
+ | MT5 parsing maps | `granularity_name`, `parse_tick_flags`, `parse_timeframe`, `TICK_FLAG_MAP`, `TIMEFRAME_MAP` |
169
+ | Trading data shapes | `POSITION_COLUMNS` |
143
170
 
144
171
  ## CLI commands
145
172
 
@@ -188,7 +215,7 @@ their own adapter layer.
188
215
 
189
216
  ## Contract verification
190
217
 
191
- `tests/test_contracts.py` asserts that every name in `STABLE_SDK_EXPORTS` is
192
- importable from `mt5cli`, documents key closed-bar, rate-view, SQLite loading,
193
- account-resolution, and trading-session behaviors, and keeps the contract set
194
- aligned with `__all__`.
218
+ `tests/test_contracts.py` asserts that every name in the stable and secondary
219
+ tier sets is importable from `mt5cli`, documents key closed-bar, rate-view,
220
+ SQLite loading, account-resolution, and trading-session behaviors, and keeps the
221
+ tier sets aligned with `__all__`.
@@ -31,7 +31,7 @@ rates = collect_latest_rates_for_accounts_with_retries(
31
31
  ### Latest closed rate bars
32
32
 
33
33
  MetaTrader 5 `start_pos=0` includes the still-forming current bar as the last
34
- row. `fetch_latest_closed_rates()` handles one connected `Mt5CliClient`; use
34
+ row. `fetch_latest_closed_rates()` handles one connected `MT5Client`; use
35
35
  `fetch_latest_closed_rates_for_trading_client()` from an active
36
36
  `Mt5TradingClient` session. Multi-account helpers fetch `count + 1` bars, drop
37
37
  that row with `drop_forming_rate_bar()`, and validate each series is non-empty. Returned frames are ordered
@@ -170,5 +170,5 @@ resulting `ValueError` is suppressed along with other recoverable errors.
170
170
  ## Trading-capable sessions
171
171
 
172
172
  For order placement and trading calculations, use the dedicated
173
- [Trading module](trading.md). The read-only `Mt5CliClient` and `mt5_session()`
174
- helpers in this module are unchanged.
173
+ [Trading module](trading.md). Use `mt5_session()` / `MT5Client` for read-only
174
+ collection.
@@ -31,7 +31,7 @@ finally:
31
31
  `login` accepts `int`, numeric `str`, or an empty string; empty strings are
32
32
  treated as unset. `path`, `password`, `server`, and `timeout` are forwarded to
33
33
  `pdmt5.Mt5Config`, and omitted `timeout` values keep the lower-level default.
34
- The read-only `Mt5CliClient` / `mt5_session()` API is unchanged.
34
+ Use `mt5_session()` / `MT5Client` for read-only data collection.
35
35
 
36
36
  ## State and order helpers
37
37
 
@@ -194,6 +194,6 @@ through the stable package root without embedding entry/exit policy.
194
194
  | Local SL/TP price derivation | `determine_order_limits()` |
195
195
  | Throttled SQLite history loop with ad-hoc error handling | `ThrottledHistoryUpdater(suppress_errors=True)` |
196
196
 
197
- Keep read-only data collection on `mt5_session()` / `Mt5CliClient`; use
197
+ Keep read-only data collection on `mt5_session()` / `MT5Client`; use
198
198
  `mt5_trading_session()` only where order placement or trading calculations are
199
199
  required.
@@ -29,7 +29,7 @@ pip install mt5cli
29
29
 
30
30
  ## Python API for downstream packages
31
31
 
32
- Import `MT5Client` for generic MT5 data access, schema normalization, and optional order primitives. `Mt5CliClient` remains available as a backward-compatible alias.
32
+ Import `MT5Client` for generic MT5 data access, schema normalization, and optional order primitives.
33
33
 
34
34
  ```python
35
35
  from datetime import UTC, datetime
@@ -11,7 +11,11 @@ from importlib.metadata import version
11
11
  from pdmt5 import Mt5Config, Mt5RuntimeError, Mt5TradingClient, Mt5TradingError
12
12
 
13
13
  from .client import MT5Client, build_config, mt5_session
14
- from .contract import STABLE_SDK_EXPORTS
14
+ from .contract import (
15
+ PUBLIC_EXPORT_TIERS,
16
+ SECONDARY_PUBLIC_EXPORTS,
17
+ STABLE_SDK_EXPORTS,
18
+ )
15
19
  from .converters import (
16
20
  ensure_utc,
17
21
  granularity_name,
@@ -59,7 +63,6 @@ from .schemas import (
59
63
  )
60
64
  from .sdk import (
61
65
  AccountSpec,
62
- Mt5CliClient,
63
66
  ThrottledHistoryUpdater,
64
67
  account_info,
65
68
  collect_history,
@@ -119,7 +122,12 @@ from .trading import (
119
122
  calculate_margin_and_volume,
120
123
  calculate_new_position_margin_ratio,
121
124
  calculate_positions_margin,
125
+ calculate_positions_margin_by_symbol,
126
+ calculate_positions_margin_safe,
127
+ calculate_projected_margin_ratio,
122
128
  calculate_spread_ratio,
129
+ calculate_symbol_group_margin_ratio,
130
+ calculate_trailing_stop_updates,
123
131
  calculate_volume_by_margin,
124
132
  close_open_positions,
125
133
  create_trading_client,
@@ -127,6 +135,7 @@ from .trading import (
127
135
  determine_order_limits,
128
136
  ensure_symbol_selected,
129
137
  estimate_order_margin,
138
+ extract_tick_price,
130
139
  fetch_latest_closed_rates_for_trading_client,
131
140
  fetch_latest_closed_rates_indexed,
132
141
  get_account_snapshot,
@@ -137,6 +146,7 @@ from .trading import (
137
146
  normalize_order_volume,
138
147
  place_market_order,
139
148
  update_sltp_for_open_positions,
149
+ update_trailing_stop_loss_for_open_positions,
140
150
  )
141
151
  from .utils import (
142
152
  TICK_FLAG_MAP,
@@ -152,7 +162,9 @@ __all__ = [
152
162
  "DEDUP_KEYS",
153
163
  "KNOWN_MT5_TIME_COLUMNS",
154
164
  "POSITION_COLUMNS",
165
+ "PUBLIC_EXPORT_TIERS",
155
166
  "REQUIRED_COLUMNS",
167
+ "SECONDARY_PUBLIC_EXPORTS",
156
168
  "STABLE_SDK_EXPORTS",
157
169
  "TICK_FLAG_MAP",
158
170
  "TIMEFRAME_MAP",
@@ -164,7 +176,6 @@ __all__ = [
164
176
  "IfExists",
165
177
  "MT5Client",
166
178
  "MarginVolume",
167
- "Mt5CliClient",
168
179
  "Mt5CliError",
169
180
  "Mt5Config",
170
181
  "Mt5ConnectionError",
@@ -188,7 +199,12 @@ __all__ = [
188
199
  "calculate_margin_and_volume",
189
200
  "calculate_new_position_margin_ratio",
190
201
  "calculate_positions_margin",
202
+ "calculate_positions_margin_by_symbol",
203
+ "calculate_positions_margin_safe",
204
+ "calculate_projected_margin_ratio",
191
205
  "calculate_spread_ratio",
206
+ "calculate_symbol_group_margin_ratio",
207
+ "calculate_trailing_stop_updates",
192
208
  "calculate_volume_by_margin",
193
209
  "call_with_normalized_errors",
194
210
  "close_open_positions",
@@ -213,6 +229,7 @@ __all__ = [
213
229
  "estimate_order_margin",
214
230
  "export_dataframe",
215
231
  "export_dataframe_to_sqlite",
232
+ "extract_tick_price",
216
233
  "fetch_latest_closed_rates",
217
234
  "fetch_latest_closed_rates_for_trading_client",
218
235
  "fetch_latest_closed_rates_indexed",
@@ -271,5 +288,6 @@ __all__ = [
271
288
  "update_history",
272
289
  "update_history_with_config",
273
290
  "update_sltp_for_open_positions",
291
+ "update_trailing_stop_loss_for_open_positions",
274
292
  "validate_schema",
275
293
  ]
@@ -24,9 +24,7 @@ class MT5Client(Mt5CliClient):
24
24
  """Public client for generic MT5 data access and order primitives.
25
25
 
26
26
  Extends the read-only SDK client with optional order check/send helpers and
27
- exposes the same connection lifecycle as :class:`~mt5cli.sdk.Mt5CliClient`.
28
- Downstream applications such as private trading packages should prefer this
29
- type over the legacy ``Mt5CliClient`` name.
27
+ exposes the same connection lifecycle as :func:`mt5_session`.
30
28
 
31
29
  mt5cli intentionally exposes minimal execution primitives only. Trading
32
30
  decisions, signals, strategies, backtests, and optimization remain the
@@ -1,11 +1,10 @@
1
- """Stable downstream SDK export names for mt5cli."""
1
+ """Downstream SDK export tiers for mt5cli."""
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
5
  STABLE_SDK_EXPORTS: frozenset[str] = frozenset({
6
6
  "AccountSpec",
7
7
  "MT5Client",
8
- "Mt5CliClient",
9
8
  "Mt5CliError",
10
9
  "Mt5Config",
11
10
  "Mt5ConnectionError",
@@ -24,36 +23,32 @@ STABLE_SDK_EXPORTS: frozenset[str] = frozenset({
24
23
  "OrderLimits",
25
24
  "RateTarget",
26
25
  "ThrottledHistoryUpdater",
27
- "account_info",
28
26
  "build_config",
29
27
  "build_rate_targets",
30
28
  "build_rate_view_name",
31
29
  "calculate_margin_and_volume",
32
30
  "calculate_new_position_margin_ratio",
31
+ "calculate_projected_margin_ratio",
33
32
  "calculate_positions_margin",
33
+ "calculate_positions_margin_by_symbol",
34
+ "calculate_positions_margin_safe",
34
35
  "calculate_spread_ratio",
36
+ "calculate_symbol_group_margin_ratio",
37
+ "calculate_trailing_stop_updates",
35
38
  "calculate_volume_by_margin",
36
39
  "call_with_normalized_errors",
37
40
  "close_open_positions",
38
41
  "collect_history",
39
42
  "collect_latest_closed_rates_by_granularity",
40
43
  "collect_latest_closed_rates_for_accounts",
41
- "collect_latest_rates",
42
- "collect_latest_rates_for_accounts",
43
44
  "collect_latest_rates_for_accounts_with_retries",
44
- "copy_rates_from",
45
- "copy_rates_from_pos",
46
- "copy_rates_range",
47
- "copy_ticks_from",
48
- "copy_ticks_range",
49
45
  "create_trading_client",
50
46
  "detect_position_side",
51
47
  "determine_order_limits",
52
48
  "drop_forming_rate_bar",
53
49
  "ensure_symbol_selected",
54
50
  "estimate_order_margin",
55
- "export_dataframe",
56
- "export_dataframe_to_sqlite",
51
+ "extract_tick_price",
57
52
  "fetch_latest_closed_rates",
58
53
  "fetch_latest_closed_rates_for_trading_client",
59
54
  "fetch_latest_closed_rates_indexed",
@@ -61,29 +56,16 @@ STABLE_SDK_EXPORTS: frozenset[str] = frozenset({
61
56
  "get_positions_frame",
62
57
  "get_symbol_snapshot",
63
58
  "get_tick_snapshot",
64
- "history_deals",
65
- "history_orders",
66
59
  "is_recoverable_mt5_error",
67
- "last_error",
68
- "latest_rates",
69
60
  "load_rate_data",
70
61
  "load_rate_data_from_connection",
71
62
  "load_rate_series_by_granularity",
72
63
  "load_rate_series_from_sqlite",
73
- "market_book",
74
- "minimum_margins",
75
64
  "mt5_session",
76
- "mt5_summary",
77
- "mt5_summary_as_df",
78
65
  "mt5_trading_session",
79
- "mt5_version",
80
66
  "normalize_mt5_exception",
81
67
  "normalize_order_volume",
82
- "orders",
83
68
  "place_market_order",
84
- "positions",
85
- "recent_history_deals",
86
- "recent_ticks",
87
69
  "resolve_account_spec",
88
70
  "resolve_account_specs",
89
71
  "resolve_history_datasets",
@@ -94,13 +76,73 @@ STABLE_SDK_EXPORTS: frozenset[str] = frozenset({
94
76
  "resolve_rate_view_name",
95
77
  "resolve_rate_view_names",
96
78
  "substitute_env_placeholders",
79
+ "update_history",
80
+ "update_history_with_config",
81
+ "update_sltp_for_open_positions",
82
+ "update_trailing_stop_loss_for_open_positions",
83
+ })
84
+
85
+ SECONDARY_PUBLIC_EXPORTS: frozenset[str] = frozenset({
86
+ "DEDUP_KEYS",
87
+ "DataKind",
88
+ "Dataset",
89
+ "IfExists",
90
+ "KNOWN_MT5_TIME_COLUMNS",
91
+ "POSITION_COLUMNS",
92
+ "REQUIRED_COLUMNS",
93
+ "TICK_FLAG_MAP",
94
+ "TIMEFRAME_MAP",
95
+ "TIME_COLUMNS",
96
+ "account_info",
97
+ "collect_latest_rates",
98
+ "collect_latest_rates_for_accounts",
99
+ "copy_rates_from",
100
+ "copy_rates_from_pos",
101
+ "copy_rates_range",
102
+ "copy_ticks_from",
103
+ "copy_ticks_range",
104
+ "detect_format",
105
+ "ensure_utc",
106
+ "export_dataframe",
107
+ "export_dataframe_to_sqlite",
108
+ "granularity_name",
109
+ "history_deals",
110
+ "history_orders",
111
+ "last_error",
112
+ "latest_rates",
113
+ "market_book",
114
+ "minimum_margins",
115
+ "mt5_summary",
116
+ "mt5_summary_as_df",
117
+ "mt5_version",
118
+ "normalize_dataframe",
119
+ "normalize_symbol",
120
+ "normalize_symbols",
121
+ "normalize_time_columns",
122
+ "orders",
123
+ "parse_date_range",
124
+ "parse_datetime",
125
+ "parse_tick_flags",
126
+ "parse_timeframe",
127
+ "positions",
128
+ "recent_history_deals",
129
+ "recent_ticks",
130
+ "recent_window",
131
+ "schema_columns",
97
132
  "symbol_info",
98
133
  "symbol_info_tick",
99
134
  "symbols",
100
135
  "terminal_info",
101
- "update_history",
102
- "update_history_with_config",
103
- "update_sltp_for_open_positions",
136
+ "validate_schema",
104
137
  })
105
138
 
106
- __all__ = ["STABLE_SDK_EXPORTS"]
139
+ PUBLIC_EXPORT_TIERS: dict[str, frozenset[str]] = {
140
+ "stable": STABLE_SDK_EXPORTS,
141
+ "secondary": SECONDARY_PUBLIC_EXPORTS,
142
+ }
143
+
144
+ __all__ = [
145
+ "PUBLIC_EXPORT_TIERS",
146
+ "SECONDARY_PUBLIC_EXPORTS",
147
+ "STABLE_SDK_EXPORTS",
148
+ ]