mt5api 1.0.5__tar.gz → 2.0.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.
- {mt5api-1.0.5 → mt5api-2.0.0}/PKG-INFO +17 -9
- {mt5api-1.0.5 → mt5api-2.0.0}/README.md +14 -6
- {mt5api-1.0.5 → mt5api-2.0.0}/mt5api/constants.py +6 -5
- {mt5api-1.0.5 → mt5api-2.0.0}/mt5api/dependencies.py +76 -27
- {mt5api-1.0.5 → mt5api-2.0.0}/mt5api/main.py +7 -5
- {mt5api-1.0.5 → mt5api-2.0.0}/mt5api/models.py +100 -11
- {mt5api-1.0.5 → mt5api-2.0.0}/mt5api/routers/account.py +1 -1
- {mt5api-1.0.5 → mt5api-2.0.0}/mt5api/routers/calc.py +1 -1
- {mt5api-1.0.5 → mt5api-2.0.0}/mt5api/routers/health.py +3 -3
- {mt5api-1.0.5 → mt5api-2.0.0}/mt5api/routers/history.py +1 -1
- {mt5api-1.0.5 → mt5api-2.0.0}/mt5api/routers/market.py +1 -1
- {mt5api-1.0.5 → mt5api-2.0.0}/mt5api/routers/symbols.py +1 -1
- {mt5api-1.0.5 → mt5api-2.0.0}/mt5api/routers/trading.py +115 -5
- mt5api-2.0.0/pyproject.toml +133 -0
- mt5api-1.0.5/pyproject.toml +0 -195
- {mt5api-1.0.5 → mt5api-2.0.0}/.gitignore +0 -0
- {mt5api-1.0.5 → mt5api-2.0.0}/LICENSE +0 -0
- {mt5api-1.0.5 → mt5api-2.0.0}/mt5api/__init__.py +0 -0
- {mt5api-1.0.5 → mt5api-2.0.0}/mt5api/__main__.py +0 -0
- {mt5api-1.0.5 → mt5api-2.0.0}/mt5api/auth.py +0 -0
- {mt5api-1.0.5 → mt5api-2.0.0}/mt5api/config.py +0 -0
- {mt5api-1.0.5 → mt5api-2.0.0}/mt5api/formatters.py +0 -0
- {mt5api-1.0.5 → mt5api-2.0.0}/mt5api/middleware.py +0 -0
- {mt5api-1.0.5 → mt5api-2.0.0}/mt5api/routers/__init__.py +0 -0
- {mt5api-1.0.5 → mt5api-2.0.0}/mt5api/routers/connection.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: mt5api
|
|
3
|
-
Version:
|
|
3
|
+
Version: 2.0.0
|
|
4
4
|
Summary: MetaTrader 5 REST API
|
|
5
5
|
Project-URL: Repository, https://github.com/dceoy/mt5api.git
|
|
6
6
|
Author-email: dceoy <dceoy@users.noreply.github.com>
|
|
@@ -18,7 +18,7 @@ Classifier: Topic :: Office/Business :: Financial :: Investment
|
|
|
18
18
|
Requires-Python: <3.15,>=3.11
|
|
19
19
|
Requires-Dist: fastapi>=0.115.0
|
|
20
20
|
Requires-Dist: pandas>=3.0.3
|
|
21
|
-
Requires-Dist: pdmt5>=1.2.
|
|
21
|
+
Requires-Dist: pdmt5>=1.2.4
|
|
22
22
|
Requires-Dist: pyarrow>=18.0.0
|
|
23
23
|
Requires-Dist: pydantic>=2.13.4
|
|
24
24
|
Requires-Dist: uvicorn[standard]>=0.32.0
|
|
@@ -37,11 +37,11 @@ provides the core MT5 client, dataframe/order primitives, and canonical MT5
|
|
|
37
37
|
constant parsing. mt5api adds optional API-key auth and JSON/Parquet response
|
|
38
38
|
formatting.
|
|
39
39
|
|
|
40
|
-
The
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
`
|
|
44
|
-
implement strategy orchestration.
|
|
40
|
+
The API supports all MetaTrader5 Python functions through REST operations or
|
|
41
|
+
application-managed connection lifecycle. Live order submission
|
|
42
|
+
(`POST /order/send`) is **disabled by default** and requires both
|
|
43
|
+
`MT5API_ENABLE_ORDER_SEND=true` and `MT5API_SECRET_KEY`. The server does
|
|
44
|
+
not implement strategy orchestration.
|
|
45
45
|
|
|
46
46
|
The API server must run on Windows. pdmt5 connects through the MetaTrader 5
|
|
47
47
|
Python API, which is supported only on Windows, so you must host `mt5api` on a
|
|
@@ -118,7 +118,7 @@ uv sync
|
|
|
118
118
|
After installing from PyPI:
|
|
119
119
|
|
|
120
120
|
```powershell
|
|
121
|
-
$env:MT5API_SECRET_KEY = "your-secret-api-key" #
|
|
121
|
+
$env:MT5API_SECRET_KEY = "your-secret-api-key" # Required for live order sends
|
|
122
122
|
$env:MT5API_ROUTER_PREFIX = "/api/v1" # Optional: omit for root-level routes
|
|
123
123
|
python -m mt5api
|
|
124
124
|
```
|
|
@@ -146,6 +146,14 @@ the same.
|
|
|
146
146
|
Set `MT5API_MAX_MARKET_BOOK_SUBSCRIPTIONS` to cap active market-book
|
|
147
147
|
subscriptions. The default limit is `100`.
|
|
148
148
|
|
|
149
|
+
To explicitly allow live order submission on a trusted Windows host, set
|
|
150
|
+
`MT5API_ENABLE_ORDER_SEND=true` **and** `MT5API_SECRET_KEY` before launching
|
|
151
|
+
the server. Never expose a trading-enabled instance directly to the public
|
|
152
|
+
Internet; use HTTPS, network access controls, and a dedicated least-privilege
|
|
153
|
+
trading account. With either setting missing, `POST /order/send` returns 403.
|
|
154
|
+
The endpoint does not automatically call `order_check` or retry requests;
|
|
155
|
+
clients must examine the MT5 `retcode` and avoid ambiguous duplicate orders.
|
|
156
|
+
|
|
149
157
|
## Example Requests with curl
|
|
150
158
|
|
|
151
159
|
Replace `windows-host` with the DNS name or IP address of the Windows machine
|
|
@@ -11,11 +11,11 @@ provides the core MT5 client, dataframe/order primitives, and canonical MT5
|
|
|
11
11
|
constant parsing. mt5api adds optional API-key auth and JSON/Parquet response
|
|
12
12
|
formatting.
|
|
13
13
|
|
|
14
|
-
The
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
`
|
|
18
|
-
implement strategy orchestration.
|
|
14
|
+
The API supports all MetaTrader5 Python functions through REST operations or
|
|
15
|
+
application-managed connection lifecycle. Live order submission
|
|
16
|
+
(`POST /order/send`) is **disabled by default** and requires both
|
|
17
|
+
`MT5API_ENABLE_ORDER_SEND=true` and `MT5API_SECRET_KEY`. The server does
|
|
18
|
+
not implement strategy orchestration.
|
|
19
19
|
|
|
20
20
|
The API server must run on Windows. pdmt5 connects through the MetaTrader 5
|
|
21
21
|
Python API, which is supported only on Windows, so you must host `mt5api` on a
|
|
@@ -92,7 +92,7 @@ uv sync
|
|
|
92
92
|
After installing from PyPI:
|
|
93
93
|
|
|
94
94
|
```powershell
|
|
95
|
-
$env:MT5API_SECRET_KEY = "your-secret-api-key" #
|
|
95
|
+
$env:MT5API_SECRET_KEY = "your-secret-api-key" # Required for live order sends
|
|
96
96
|
$env:MT5API_ROUTER_PREFIX = "/api/v1" # Optional: omit for root-level routes
|
|
97
97
|
python -m mt5api
|
|
98
98
|
```
|
|
@@ -120,6 +120,14 @@ the same.
|
|
|
120
120
|
Set `MT5API_MAX_MARKET_BOOK_SUBSCRIPTIONS` to cap active market-book
|
|
121
121
|
subscriptions. The default limit is `100`.
|
|
122
122
|
|
|
123
|
+
To explicitly allow live order submission on a trusted Windows host, set
|
|
124
|
+
`MT5API_ENABLE_ORDER_SEND=true` **and** `MT5API_SECRET_KEY` before launching
|
|
125
|
+
the server. Never expose a trading-enabled instance directly to the public
|
|
126
|
+
Internet; use HTTPS, network access controls, and a dedicated least-privilege
|
|
127
|
+
trading account. With either setting missing, `POST /order/send` returns 403.
|
|
128
|
+
The endpoint does not automatically call `order_check` or retry requests;
|
|
129
|
+
clients must examine the MT5 `retcode` and avoid ambiguous duplicate orders.
|
|
130
|
+
|
|
123
131
|
## Example Requests with curl
|
|
124
132
|
|
|
125
133
|
Replace `windows-host` with the DNS name or IP address of the Windows machine
|
|
@@ -4,9 +4,9 @@ from importlib.metadata import version
|
|
|
4
4
|
|
|
5
5
|
API_TITLE = "MT5 REST API"
|
|
6
6
|
API_DESCRIPTION = (
|
|
7
|
-
"REST API for MetaTrader 5 data
|
|
8
|
-
"
|
|
9
|
-
"and
|
|
7
|
+
"REST API for MetaTrader 5 market data, account information, trading history, "
|
|
8
|
+
"calculations, and terminal utilities. Live order submission is disabled "
|
|
9
|
+
"by default and requires explicit opt-in and API-key authentication."
|
|
10
10
|
)
|
|
11
11
|
API_VERSION = version("mt5api")
|
|
12
12
|
API_DOCS_URL = "/docs"
|
|
@@ -22,9 +22,10 @@ ENV_MT5API_PORT = "MT5API_PORT"
|
|
|
22
22
|
ENV_MT5API_LOG_LEVEL = "MT5API_LOG_LEVEL"
|
|
23
23
|
ENV_MT5API_ROUTER_PREFIX = "MT5API_ROUTER_PREFIX"
|
|
24
24
|
ENV_MT5API_MAX_MARKET_BOOK_SUBSCRIPTIONS = "MT5API_MAX_MARKET_BOOK_SUBSCRIPTIONS"
|
|
25
|
-
|
|
25
|
+
ENV_MT5API_ENABLE_ORDER_SEND = "MT5API_ENABLE_ORDER_SEND"
|
|
26
|
+
ENV_MT5API_SECRET_KEY = "MT5API_SECRET_KEY" # ruff: ignore[hardcoded-password-string]
|
|
26
27
|
|
|
27
|
-
DEFAULT_API_HOST = "0.0.0.0" #
|
|
28
|
+
DEFAULT_API_HOST = "0.0.0.0" # ruff: ignore[hardcoded-bind-all-interfaces]
|
|
28
29
|
DEFAULT_API_PORT = 8000
|
|
29
30
|
DEFAULT_API_LOG_LEVEL = "INFO"
|
|
30
31
|
DEFAULT_API_ROUTER_PREFIX = ""
|
|
@@ -80,37 +80,85 @@ def get_mt5_client_lock(request: Request) -> asyncio.Lock:
|
|
|
80
80
|
return get_mt5_runtime_state(request).client_lock
|
|
81
81
|
|
|
82
82
|
|
|
83
|
-
def
|
|
84
|
-
"""
|
|
83
|
+
def shutdown_mt5_client(state: Mt5RuntimeState) -> None:
|
|
84
|
+
"""Shutdown and clear the application-scoped MT5 client."""
|
|
85
|
+
client = state.client
|
|
86
|
+
if client is None:
|
|
87
|
+
return
|
|
88
|
+
state.client = None
|
|
89
|
+
client.shutdown()
|
|
85
90
|
|
|
86
|
-
|
|
87
|
-
|
|
91
|
+
|
|
92
|
+
async def _initialize_and_install_client(
|
|
93
|
+
state: Mt5RuntimeState,
|
|
94
|
+
client: Mt5DataClient,
|
|
95
|
+
) -> None:
|
|
96
|
+
"""Initialize ``client`` in a thread and install it as the active client.
|
|
97
|
+
|
|
98
|
+
The native initialization cannot be interrupted and changes MetaTrader5's
|
|
99
|
+
process-global connection. If the caller is cancelled, this waits for the
|
|
100
|
+
thread to finish and installs the client when it succeeded, so
|
|
101
|
+
``state.client`` always matches the terminal's connected account before the
|
|
102
|
+
caller releases ``state.client_lock``.
|
|
103
|
+
|
|
104
|
+
Raises:
|
|
105
|
+
asyncio.CancelledError: If cancelled, after the thread has finished.
|
|
106
|
+
"""
|
|
107
|
+
init_task = asyncio.ensure_future(
|
|
108
|
+
asyncio.to_thread(client.initialize_and_login_mt5)
|
|
109
|
+
)
|
|
110
|
+
try:
|
|
111
|
+
await asyncio.shield(init_task)
|
|
112
|
+
except asyncio.CancelledError:
|
|
113
|
+
while not init_task.done():
|
|
114
|
+
await asyncio.wait({init_task})
|
|
115
|
+
if init_task.exception() is None:
|
|
116
|
+
state.client = client
|
|
117
|
+
raise
|
|
118
|
+
state.client = client
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
async def ensure_mt5_client(state: Mt5RuntimeState) -> Mt5DataClient:
|
|
122
|
+
"""Return the active client, initializing the default one if needed.
|
|
123
|
+
|
|
124
|
+
Callers must hold ``state.client_lock`` so initialization cannot overlap an
|
|
125
|
+
account change.
|
|
88
126
|
|
|
89
127
|
Returns:
|
|
90
|
-
|
|
128
|
+
Active initialized MT5 data client.
|
|
91
129
|
|
|
92
130
|
Raises:
|
|
93
131
|
RuntimeError: If MT5 client initialization fails.
|
|
94
132
|
"""
|
|
95
|
-
state
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
return state.client
|
|
133
|
+
if state.client is not None:
|
|
134
|
+
return state.client
|
|
135
|
+
client = Mt5DataClient(config=Mt5Config())
|
|
136
|
+
try:
|
|
137
|
+
await _initialize_and_install_client(state, client)
|
|
138
|
+
except Exception as exc:
|
|
139
|
+
error_message = f"Failed to initialize MT5 client: {exc!s}"
|
|
140
|
+
raise RuntimeError(error_message) from exc
|
|
141
|
+
return client
|
|
105
142
|
|
|
106
143
|
|
|
107
|
-
def
|
|
108
|
-
"""
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
144
|
+
async def get_mt5_client(request: Request) -> Mt5DataClient:
|
|
145
|
+
"""Get or lazily create the application-scoped MT5 client instance.
|
|
146
|
+
|
|
147
|
+
Initialization is serialized with account changes and live order submission
|
|
148
|
+
by ``state.client_lock``. When a client already exists no native
|
|
149
|
+
initialization can occur, so the lock is not taken.
|
|
150
|
+
|
|
151
|
+
Args:
|
|
152
|
+
request: Request whose application owns the MT5 runtime state.
|
|
153
|
+
|
|
154
|
+
Returns:
|
|
155
|
+
Shared initialized MT5 data client.
|
|
156
|
+
"""
|
|
157
|
+
state = get_mt5_runtime_state(request)
|
|
158
|
+
if state.client is not None:
|
|
159
|
+
return state.client
|
|
160
|
+
async with state.client_lock:
|
|
161
|
+
return await ensure_mt5_client(state)
|
|
114
162
|
|
|
115
163
|
|
|
116
164
|
async def replace_mt5_client(
|
|
@@ -121,6 +169,8 @@ async def replace_mt5_client(
|
|
|
121
169
|
|
|
122
170
|
MetaTrader5 connection state is process-global, so the previous wrapper is
|
|
123
171
|
not shut down after success because doing so could close the new session.
|
|
172
|
+
If the caller is cancelled mid-initialization, the call waits for the native
|
|
173
|
+
thread and keeps ``state.client`` consistent with the connected account.
|
|
124
174
|
|
|
125
175
|
Returns:
|
|
126
176
|
Newly initialized and installed client.
|
|
@@ -128,14 +178,13 @@ async def replace_mt5_client(
|
|
|
128
178
|
Raises:
|
|
129
179
|
RuntimeError: If the replacement cannot be initialized.
|
|
130
180
|
"""
|
|
181
|
+
new_client = Mt5DataClient(config=config)
|
|
131
182
|
try:
|
|
132
|
-
|
|
133
|
-
await asyncio.to_thread(new_client.initialize_and_login_mt5)
|
|
183
|
+
await _initialize_and_install_client(state, new_client)
|
|
134
184
|
except Exception as exc:
|
|
135
185
|
logger.exception("Failed to initialize MT5 client")
|
|
136
186
|
error_message = "Failed to initialize MT5 client"
|
|
137
187
|
raise RuntimeError(error_message) from exc
|
|
138
|
-
state.client = new_client
|
|
139
188
|
return new_client
|
|
140
189
|
|
|
141
190
|
|
|
@@ -165,8 +214,8 @@ async def release_market_book_subscriptions(state: Mt5RuntimeState) -> None:
|
|
|
165
214
|
|
|
166
215
|
async def run_in_threadpool(
|
|
167
216
|
func: Callable[..., T],
|
|
168
|
-
*args: Any, #
|
|
169
|
-
**kwargs: Any, #
|
|
217
|
+
*args: Any, # ruff: ignore[any-type]
|
|
218
|
+
**kwargs: Any, # ruff: ignore[any-type]
|
|
170
219
|
) -> T:
|
|
171
220
|
"""Run a synchronous MT5 function without blocking the event loop.
|
|
172
221
|
|
|
@@ -226,13 +226,15 @@ async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
|
|
|
226
226
|
app,
|
|
227
227
|
max_market_book_subscriptions=get_configured_max_market_book_subscriptions(),
|
|
228
228
|
)
|
|
229
|
-
yield
|
|
230
|
-
logger.info("Shutting down MT5 REST API...")
|
|
231
229
|
try:
|
|
232
|
-
|
|
230
|
+
yield
|
|
233
231
|
finally:
|
|
234
|
-
|
|
235
|
-
|
|
232
|
+
logger.info("Shutting down MT5 REST API...")
|
|
233
|
+
try:
|
|
234
|
+
await release_market_book_subscriptions(state)
|
|
235
|
+
finally:
|
|
236
|
+
shutdown_mt5_client(state)
|
|
237
|
+
logger.info("MT5 connection closed")
|
|
236
238
|
|
|
237
239
|
|
|
238
240
|
app = FastAPI(
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
from datetime import datetime #
|
|
5
|
+
from datetime import datetime # ruff: ignore[typing-only-standard-library-import]
|
|
6
6
|
from enum import StrEnum
|
|
7
7
|
from typing import Annotated, Any, Self, TypeAlias
|
|
8
8
|
|
|
@@ -651,26 +651,26 @@ class TradeRequest(BaseModel):
|
|
|
651
651
|
ge=0,
|
|
652
652
|
examples=[1],
|
|
653
653
|
)
|
|
654
|
-
symbol: str = Field(
|
|
655
|
-
|
|
656
|
-
description="
|
|
654
|
+
symbol: str | None = Field(
|
|
655
|
+
default=None,
|
|
656
|
+
description="Trade symbol (not required for order removal/modification)",
|
|
657
657
|
min_length=1,
|
|
658
658
|
max_length=32,
|
|
659
659
|
examples=["EURUSD"],
|
|
660
660
|
)
|
|
661
|
-
volume: float = Field(
|
|
662
|
-
|
|
661
|
+
volume: float | None = Field(
|
|
662
|
+
default=None,
|
|
663
663
|
description="Trade volume in lots",
|
|
664
664
|
gt=0,
|
|
665
665
|
examples=[0.1, 1.0],
|
|
666
666
|
)
|
|
667
|
-
type: Mt5OrderType = Field(
|
|
668
|
-
|
|
667
|
+
type: Mt5OrderType | None = Field(
|
|
668
|
+
default=None,
|
|
669
669
|
description=_ORDER_TYPE_DESCRIPTION,
|
|
670
670
|
)
|
|
671
|
-
price: float = Field(
|
|
672
|
-
|
|
673
|
-
description="Requested price",
|
|
671
|
+
price: float | None = Field(
|
|
672
|
+
default=None,
|
|
673
|
+
description="Requested price (optional for market execution)",
|
|
674
674
|
ge=0,
|
|
675
675
|
examples=[1.08500],
|
|
676
676
|
)
|
|
@@ -746,6 +746,95 @@ class TradeRequest(BaseModel):
|
|
|
746
746
|
examples=[654321],
|
|
747
747
|
)
|
|
748
748
|
|
|
749
|
+
@model_validator(mode="after")
|
|
750
|
+
def validate_action_fields(self) -> Self:
|
|
751
|
+
"""Require only fields relevant to the selected MT5 trade action.
|
|
752
|
+
|
|
753
|
+
Returns:
|
|
754
|
+
The validated request for checking or sending to MT5.
|
|
755
|
+
|
|
756
|
+
SLTP and MODIFY replace the whole MT5 trade state, so omitted levels are
|
|
757
|
+
rejected instead of risking a reset to zero/GTC (use ``0`` to clear).
|
|
758
|
+
|
|
759
|
+
Raises:
|
|
760
|
+
ValueError: If the action is unknown or required fields are missing.
|
|
761
|
+
"""
|
|
762
|
+
required = {
|
|
763
|
+
1: ("symbol", "volume", "type"), # TRADE_ACTION_DEAL
|
|
764
|
+
5: ("symbol", "volume", "type", "price"), # PENDING
|
|
765
|
+
6: (), # SLTP: netting symbol or hedging position
|
|
766
|
+
7: ("order", "price", "sl", "tp", "type_time"), # MODIFY (full state)
|
|
767
|
+
8: ("order",), # REMOVE
|
|
768
|
+
10: ("position", "position_by"), # CLOSE_BY
|
|
769
|
+
}.get(self.action)
|
|
770
|
+
if required is None:
|
|
771
|
+
message = "Unsupported MetaTrader5 trade action"
|
|
772
|
+
raise ValueError(message)
|
|
773
|
+
missing = [
|
|
774
|
+
name
|
|
775
|
+
for name in required
|
|
776
|
+
if getattr(self, name) is None
|
|
777
|
+
or (
|
|
778
|
+
name in {"order", "position", "position_by"}
|
|
779
|
+
and getattr(self, name) == 0
|
|
780
|
+
)
|
|
781
|
+
]
|
|
782
|
+
if self.action == 6: # ruff: ignore[magic-value-comparison]
|
|
783
|
+
if not (self.position or self.symbol):
|
|
784
|
+
missing.append("position or symbol")
|
|
785
|
+
missing.extend(name for name in ("sl", "tp") if getattr(self, name) is None)
|
|
786
|
+
if (
|
|
787
|
+
self.action == 7 # ruff: ignore[magic-value-comparison]
|
|
788
|
+
and self.type_time in {2, 3} # ORDER_TIME_SPECIFIED(_DAY)
|
|
789
|
+
and self.expiration is None
|
|
790
|
+
):
|
|
791
|
+
missing.append("expiration")
|
|
792
|
+
if missing:
|
|
793
|
+
message = f"Missing required trade fields: {', '.join(missing)}"
|
|
794
|
+
raise ValueError(message)
|
|
795
|
+
if self.expiration is not None and self.expiration.utcoffset() is None:
|
|
796
|
+
message = "expiration must include a UTC offset"
|
|
797
|
+
raise ValueError(message)
|
|
798
|
+
return self
|
|
799
|
+
|
|
800
|
+
def to_mt5_dict(self) -> dict[str, Any]:
|
|
801
|
+
"""Serialize MT5 fields, converting aware expiration to Unix seconds.
|
|
802
|
+
|
|
803
|
+
Returns:
|
|
804
|
+
Trade request dictionary suitable for the MetaTrader5 Python module.
|
|
805
|
+
"""
|
|
806
|
+
payload: dict[str, Any] = self.model_dump(mode="python", exclude_none=True)
|
|
807
|
+
if self.expiration is not None:
|
|
808
|
+
payload["expiration"] = int(self.expiration.timestamp())
|
|
809
|
+
return payload
|
|
810
|
+
|
|
811
|
+
|
|
812
|
+
class OrderSendRequest(BaseModel):
|
|
813
|
+
"""Request body for an opt-in live trading operation."""
|
|
814
|
+
|
|
815
|
+
request: TradeRequest = Field(
|
|
816
|
+
...,
|
|
817
|
+
description=(
|
|
818
|
+
"MT5 MqlTradeRequest (order_send), including action-specific fields"
|
|
819
|
+
),
|
|
820
|
+
)
|
|
821
|
+
expected_login: int = Field(
|
|
822
|
+
...,
|
|
823
|
+
gt=0,
|
|
824
|
+
description=(
|
|
825
|
+
"MT5 account login the order is intended for. The order is rejected "
|
|
826
|
+
"(HTTP 409) unless the connected account matches."
|
|
827
|
+
),
|
|
828
|
+
)
|
|
829
|
+
expected_server: str | None = Field(
|
|
830
|
+
default=None,
|
|
831
|
+
min_length=1,
|
|
832
|
+
description=(
|
|
833
|
+
"Optional MT5 trade server the order is intended for. When set, the "
|
|
834
|
+
"connected account's server must match exactly."
|
|
835
|
+
),
|
|
836
|
+
)
|
|
837
|
+
|
|
749
838
|
|
|
750
839
|
class OrderCheckRequest(BaseModel):
|
|
751
840
|
"""Request parameters for order check endpoint."""
|
|
@@ -5,7 +5,7 @@ from __future__ import annotations
|
|
|
5
5
|
from typing import TYPE_CHECKING, Annotated
|
|
6
6
|
|
|
7
7
|
from fastapi import APIRouter, Depends
|
|
8
|
-
from pdmt5.dataframe import Mt5DataClient #
|
|
8
|
+
from pdmt5.dataframe import Mt5DataClient # ruff: ignore[typing-only-third-party-import]
|
|
9
9
|
|
|
10
10
|
from mt5api.auth import verify_api_key
|
|
11
11
|
from mt5api.dependencies import (
|
|
@@ -5,7 +5,7 @@ from __future__ import annotations
|
|
|
5
5
|
from typing import TYPE_CHECKING, Annotated
|
|
6
6
|
|
|
7
7
|
from fastapi import APIRouter, Depends
|
|
8
|
-
from pdmt5.dataframe import Mt5DataClient #
|
|
8
|
+
from pdmt5.dataframe import Mt5DataClient # ruff: ignore[typing-only-third-party-import]
|
|
9
9
|
|
|
10
10
|
from mt5api.auth import verify_api_key
|
|
11
11
|
from mt5api.dependencies import (
|
|
@@ -6,7 +6,7 @@ import logging
|
|
|
6
6
|
from typing import TYPE_CHECKING, Annotated
|
|
7
7
|
|
|
8
8
|
from fastapi import APIRouter, Depends, Request
|
|
9
|
-
from pdmt5.dataframe import Mt5DataClient #
|
|
9
|
+
from pdmt5.dataframe import Mt5DataClient # ruff: ignore[typing-only-third-party-import]
|
|
10
10
|
|
|
11
11
|
from mt5api.auth import verify_api_key
|
|
12
12
|
from mt5api.constants import API_VERSION
|
|
@@ -49,12 +49,12 @@ async def get_health(request: Request) -> HealthResponse:
|
|
|
49
49
|
mt5_version = None
|
|
50
50
|
|
|
51
51
|
try:
|
|
52
|
-
client = await
|
|
52
|
+
client = await get_mt5_client(request)
|
|
53
53
|
version_dict = await run_in_threadpool(client.version_as_dict)
|
|
54
54
|
if version_dict:
|
|
55
55
|
mt5_version = f"{version_dict.get('mt5_terminal_version', 'unknown')}"
|
|
56
56
|
mt5_connected = True
|
|
57
|
-
except Exception as e: #
|
|
57
|
+
except Exception as e: # ruff: ignore[blind-except]
|
|
58
58
|
logger.debug("MT5 not available for health check: %s", e)
|
|
59
59
|
|
|
60
60
|
return HealthResponse(
|
|
@@ -5,7 +5,7 @@ from __future__ import annotations
|
|
|
5
5
|
from typing import TYPE_CHECKING, Annotated
|
|
6
6
|
|
|
7
7
|
from fastapi import APIRouter, Depends
|
|
8
|
-
from pdmt5.dataframe import Mt5DataClient #
|
|
8
|
+
from pdmt5.dataframe import Mt5DataClient # ruff: ignore[typing-only-third-party-import]
|
|
9
9
|
|
|
10
10
|
from mt5api.auth import verify_api_key
|
|
11
11
|
from mt5api.dependencies import (
|
|
@@ -5,7 +5,7 @@ from __future__ import annotations
|
|
|
5
5
|
from typing import TYPE_CHECKING, Annotated
|
|
6
6
|
|
|
7
7
|
from fastapi import APIRouter, Depends
|
|
8
|
-
from pdmt5.dataframe import Mt5DataClient #
|
|
8
|
+
from pdmt5.dataframe import Mt5DataClient # ruff: ignore[typing-only-third-party-import]
|
|
9
9
|
|
|
10
10
|
from mt5api.auth import verify_api_key
|
|
11
11
|
from mt5api.dependencies import (
|
|
@@ -5,7 +5,7 @@ from __future__ import annotations
|
|
|
5
5
|
from typing import TYPE_CHECKING, Annotated
|
|
6
6
|
|
|
7
7
|
from fastapi import APIRouter, Depends
|
|
8
|
-
from pdmt5.dataframe import Mt5DataClient #
|
|
8
|
+
from pdmt5.dataframe import Mt5DataClient # ruff: ignore[typing-only-third-party-import]
|
|
9
9
|
|
|
10
10
|
from mt5api.auth import verify_api_key
|
|
11
11
|
from mt5api.dependencies import (
|
|
@@ -2,16 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
import asyncio
|
|
5
6
|
import logging
|
|
7
|
+
import os
|
|
6
8
|
from typing import TYPE_CHECKING, Annotated, Any
|
|
7
9
|
|
|
8
|
-
from fastapi import APIRouter, Depends, Request, status
|
|
10
|
+
from fastapi import APIRouter, Depends, HTTPException, Request, status
|
|
9
11
|
from fastapi.responses import JSONResponse
|
|
10
|
-
from pdmt5.dataframe import Mt5DataClient #
|
|
12
|
+
from pdmt5.dataframe import Mt5DataClient # ruff: ignore[typing-only-third-party-import]
|
|
11
13
|
|
|
12
|
-
from mt5api.auth import verify_api_key
|
|
13
|
-
from mt5api.constants import
|
|
14
|
+
from mt5api.auth import is_auth_enabled, verify_api_key
|
|
15
|
+
from mt5api.constants import (
|
|
16
|
+
ENV_MT5API_ENABLE_ORDER_SEND,
|
|
17
|
+
ENV_MT5API_MAX_MARKET_BOOK_SUBSCRIPTIONS,
|
|
18
|
+
)
|
|
14
19
|
from mt5api.dependencies import (
|
|
20
|
+
ensure_mt5_client,
|
|
15
21
|
get_mt5_client,
|
|
16
22
|
get_mt5_runtime_state,
|
|
17
23
|
get_response_format,
|
|
@@ -23,6 +29,7 @@ from mt5api.models import (
|
|
|
23
29
|
ErrorResponse,
|
|
24
30
|
MarketBookSubscriptionRequest,
|
|
25
31
|
OrderCheckRequest,
|
|
32
|
+
OrderSendRequest,
|
|
26
33
|
ResponseFormat,
|
|
27
34
|
SymbolSelectRequest,
|
|
28
35
|
)
|
|
@@ -61,6 +68,109 @@ def _build_market_book_subscription_limit_response(
|
|
|
61
68
|
)
|
|
62
69
|
|
|
63
70
|
|
|
71
|
+
def require_order_send_access() -> None:
|
|
72
|
+
"""Reject live trading unless explicitly enabled with API-key authentication.
|
|
73
|
+
|
|
74
|
+
Raises:
|
|
75
|
+
HTTPException: If the endpoint is disabled or authentication is unconfigured.
|
|
76
|
+
"""
|
|
77
|
+
enabled = os.getenv(ENV_MT5API_ENABLE_ORDER_SEND, "").strip().lower()
|
|
78
|
+
if enabled not in {"1", "true"} or not is_auth_enabled():
|
|
79
|
+
raise HTTPException(
|
|
80
|
+
status_code=status.HTTP_403_FORBIDDEN,
|
|
81
|
+
detail=(
|
|
82
|
+
"Live trading is disabled. Set MT5API_ENABLE_ORDER_SEND=true "
|
|
83
|
+
"and configure MT5API_SECRET_KEY to allow order submission."
|
|
84
|
+
),
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _send_for_expected_account(
|
|
89
|
+
client: Mt5DataClient,
|
|
90
|
+
payload: dict[str, Any],
|
|
91
|
+
*,
|
|
92
|
+
expected_login: int,
|
|
93
|
+
expected_server: str | None,
|
|
94
|
+
) -> dict[str, Any]:
|
|
95
|
+
"""Send an order only if the connected account is the intended one.
|
|
96
|
+
|
|
97
|
+
The account check and the send run back to back in one worker thread, while
|
|
98
|
+
the caller holds ``client_lock``, so the account cannot change in between.
|
|
99
|
+
|
|
100
|
+
Returns:
|
|
101
|
+
MT5 order-send result.
|
|
102
|
+
|
|
103
|
+
Raises:
|
|
104
|
+
HTTPException: If the connected account differs from the expected one.
|
|
105
|
+
"""
|
|
106
|
+
account = client.account_info_as_dict()
|
|
107
|
+
if account.get("login") != expected_login or (
|
|
108
|
+
expected_server is not None and account.get("server") != expected_server
|
|
109
|
+
):
|
|
110
|
+
raise HTTPException(
|
|
111
|
+
status_code=status.HTTP_409_CONFLICT,
|
|
112
|
+
detail=(
|
|
113
|
+
"Connected MT5 account does not match expected_login/"
|
|
114
|
+
"expected_server; the order was not sent."
|
|
115
|
+
),
|
|
116
|
+
)
|
|
117
|
+
return client.order_send_as_dict(request=payload)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
@router.post(
|
|
121
|
+
"/order/send",
|
|
122
|
+
response_model=DataResponse,
|
|
123
|
+
summary="Send live trading order (opt-in)",
|
|
124
|
+
description=(
|
|
125
|
+
"Submit a live MetaTrader5 order. Disabled unless MT5API_ENABLE_ORDER_SEND "
|
|
126
|
+
"is true and API-key authentication is configured. Check the returned "
|
|
127
|
+
"MT5 retcode: HTTP 200 does not imply the order was filled."
|
|
128
|
+
),
|
|
129
|
+
dependencies=[Depends(require_order_send_access)],
|
|
130
|
+
)
|
|
131
|
+
async def post_order_send(
|
|
132
|
+
app_request: Request,
|
|
133
|
+
response_format: Annotated[ResponseFormat, Depends(get_response_format)],
|
|
134
|
+
request: OrderSendRequest,
|
|
135
|
+
) -> DataResponse | Response:
|
|
136
|
+
"""Send a validated order and preserve the MT5 execution result.
|
|
137
|
+
|
|
138
|
+
The send holds the application's client lock so it cannot interleave with
|
|
139
|
+
``/connection/login``. The active client is resolved (and lazily
|
|
140
|
+
initialized) under the lock, and the lock is retained until the native call
|
|
141
|
+
finishes, even if the request is cancelled. The connected account must match
|
|
142
|
+
``expected_login`` (and ``expected_server`` when given); otherwise the order
|
|
143
|
+
is rejected with HTTP 409 before ``order_send`` is invoked.
|
|
144
|
+
|
|
145
|
+
Returns:
|
|
146
|
+
MT5 order-send result, including retcode, in JSON or Parquet format.
|
|
147
|
+
|
|
148
|
+
Raises:
|
|
149
|
+
asyncio.CancelledError: If the request is cancelled after the send ends.
|
|
150
|
+
"""
|
|
151
|
+
payload = request.request.to_mt5_dict()
|
|
152
|
+
state = get_mt5_runtime_state(app_request)
|
|
153
|
+
async with state.client_lock:
|
|
154
|
+
active_client = await ensure_mt5_client(state)
|
|
155
|
+
send_task = asyncio.ensure_future(
|
|
156
|
+
run_in_threadpool(
|
|
157
|
+
_send_for_expected_account,
|
|
158
|
+
active_client,
|
|
159
|
+
payload,
|
|
160
|
+
expected_login=request.expected_login,
|
|
161
|
+
expected_server=request.expected_server,
|
|
162
|
+
)
|
|
163
|
+
)
|
|
164
|
+
try:
|
|
165
|
+
result: dict[str, Any] = await asyncio.shield(send_task)
|
|
166
|
+
except asyncio.CancelledError:
|
|
167
|
+
while not send_task.done():
|
|
168
|
+
await asyncio.wait({send_task})
|
|
169
|
+
send_task.exception()
|
|
170
|
+
raise
|
|
171
|
+
return format_response(result, response_format)
|
|
172
|
+
|
|
173
|
+
|
|
64
174
|
@router.post(
|
|
65
175
|
"/order/check",
|
|
66
176
|
response_model=DataResponse,
|
|
@@ -79,7 +189,7 @@ async def post_order_check(
|
|
|
79
189
|
"""
|
|
80
190
|
result: dict[str, Any] = await run_in_threadpool(
|
|
81
191
|
mt5_client.order_check_as_dict,
|
|
82
|
-
request=request.request.
|
|
192
|
+
request=request.request.to_mt5_dict(),
|
|
83
193
|
)
|
|
84
194
|
return format_response(result, response_format)
|
|
85
195
|
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "mt5api"
|
|
3
|
+
version = "2.0.0"
|
|
4
|
+
description = "MetaTrader 5 REST API"
|
|
5
|
+
authors = [{name = "dceoy", email = "dceoy@users.noreply.github.com"}]
|
|
6
|
+
maintainers = [{name = "dceoy", email = "dceoy@users.noreply.github.com"}]
|
|
7
|
+
license = "MIT"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">= 3.11, < 3.15"
|
|
11
|
+
dependencies = [
|
|
12
|
+
"pdmt5 >= 1.2.4",
|
|
13
|
+
"fastapi >= 0.115.0",
|
|
14
|
+
"uvicorn[standard] >= 0.32.0",
|
|
15
|
+
"pandas >= 3.0.3",
|
|
16
|
+
"pydantic >= 2.13.4",
|
|
17
|
+
"pyarrow >= 18.0.0",
|
|
18
|
+
]
|
|
19
|
+
classifiers = [
|
|
20
|
+
"Development Status :: 4 - Beta",
|
|
21
|
+
"Environment :: Console",
|
|
22
|
+
"License :: OSI Approved :: MIT License",
|
|
23
|
+
"Operating System :: Microsoft :: Windows",
|
|
24
|
+
"Programming Language :: Python",
|
|
25
|
+
"Programming Language :: Python :: 3",
|
|
26
|
+
"Intended Audience :: Financial and Insurance Industry",
|
|
27
|
+
"Topic :: Office/Business :: Financial :: Investment",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[project.urls]
|
|
31
|
+
Repository = "https://github.com/dceoy/mt5api.git"
|
|
32
|
+
|
|
33
|
+
[tool.uv]
|
|
34
|
+
required-environments = ["platform_system == 'Windows'"]
|
|
35
|
+
exclude-newer = "1 day"
|
|
36
|
+
exclude-newer-package = { pdmt5 = false }
|
|
37
|
+
|
|
38
|
+
[dependency-groups]
|
|
39
|
+
dev = [
|
|
40
|
+
"httpx >= 0.27.0",
|
|
41
|
+
"httpx2 >= 2.0.0",
|
|
42
|
+
"ruff >= 0.17.1",
|
|
43
|
+
"pyright >= 1.1.407",
|
|
44
|
+
"pytest >= 8.0.0",
|
|
45
|
+
"pytest-asyncio >= 0.25.2",
|
|
46
|
+
"pytest-mock >= 3.12.0",
|
|
47
|
+
"pytest-cov >= 5.0.0",
|
|
48
|
+
"pandas-stubs >= 3.0.3.260530",
|
|
49
|
+
"types-pygments >= 2.19.0.20250516",
|
|
50
|
+
"types-colorama >= 0.4.15.20240311",
|
|
51
|
+
"types-pexpect >= 4.9.0.20250516",
|
|
52
|
+
"mkdocs >= 1.6.1",
|
|
53
|
+
"mkdocs-material >= 9.6.15",
|
|
54
|
+
"mkdocstrings[python] >= 0.29.1",
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
[tool.hatch.build.targets.sdist]
|
|
58
|
+
only-include = ["mt5api"]
|
|
59
|
+
|
|
60
|
+
[tool.hatch.build.targets.wheel]
|
|
61
|
+
packages = ["mt5api"]
|
|
62
|
+
|
|
63
|
+
[tool.ruff]
|
|
64
|
+
line-length = 88
|
|
65
|
+
exclude = ["build", ".venv"]
|
|
66
|
+
preview = true
|
|
67
|
+
|
|
68
|
+
[tool.ruff.lint]
|
|
69
|
+
select = ["ALL"]
|
|
70
|
+
ignore = [
|
|
71
|
+
"CPY", # flake8-copyright (CPY)
|
|
72
|
+
"RET", # flake8-return (RET)
|
|
73
|
+
"missing-trailing-comma", # missing-trailing-comma
|
|
74
|
+
"boolean-type-hint-positional-argument", # boolean-type-hint-positional-argument
|
|
75
|
+
"boolean-default-value-positional-argument", # boolean-default-value-positional-argument
|
|
76
|
+
]
|
|
77
|
+
|
|
78
|
+
[tool.ruff.lint.per-file-ignores]
|
|
79
|
+
"tests/**/*.py" = [
|
|
80
|
+
"docstring-missing-returns", # Missing return documentation
|
|
81
|
+
"docstring-missing-exception", # Raised exception missing from docstring
|
|
82
|
+
"import-private-name", # Private name import
|
|
83
|
+
"too-many-public-methods", # Too many public methods
|
|
84
|
+
"magic-value-comparison", # Magic value used in comparison
|
|
85
|
+
"no-self-use", # Method could be function/static/classmethod
|
|
86
|
+
"assert", # Use of assert (acceptable in tests)
|
|
87
|
+
"hardcoded-password-func-arg", # Possible hardcoded password
|
|
88
|
+
"private-member-access", # Private member accessed
|
|
89
|
+
]
|
|
90
|
+
|
|
91
|
+
[tool.ruff.lint.pydocstyle]
|
|
92
|
+
convention = "google"
|
|
93
|
+
|
|
94
|
+
[tool.ruff.lint.pylint]
|
|
95
|
+
max-args = 10
|
|
96
|
+
max-public-methods = 40
|
|
97
|
+
|
|
98
|
+
[tool.pyright]
|
|
99
|
+
exclude = ["build", ".venv"]
|
|
100
|
+
venvPath = "."
|
|
101
|
+
venv = ".venv"
|
|
102
|
+
typeCheckingMode = "strict"
|
|
103
|
+
reportMissingTypeStubs = "none"
|
|
104
|
+
|
|
105
|
+
[tool.pytest.ini_options]
|
|
106
|
+
addopts = [
|
|
107
|
+
"--cov=mt5api",
|
|
108
|
+
"--cov-branch",
|
|
109
|
+
"--doctest-modules",
|
|
110
|
+
"--capture=no",
|
|
111
|
+
]
|
|
112
|
+
pythonpath = ["."]
|
|
113
|
+
testpaths = ["tests"]
|
|
114
|
+
python_files = ["test_*.py", "*_test.py"]
|
|
115
|
+
python_classes = ["Test*"]
|
|
116
|
+
python_functions = ["test_*"]
|
|
117
|
+
minversion = "6.0"
|
|
118
|
+
|
|
119
|
+
[tool.coverage.run]
|
|
120
|
+
source = ["mt5api"]
|
|
121
|
+
omit = [
|
|
122
|
+
"**/__init__.py",
|
|
123
|
+
"tests/**",
|
|
124
|
+
]
|
|
125
|
+
|
|
126
|
+
[tool.coverage.report]
|
|
127
|
+
show_missing = true
|
|
128
|
+
fail_under = 100
|
|
129
|
+
exclude_lines = ["if TYPE_CHECKING:"]
|
|
130
|
+
|
|
131
|
+
[build-system]
|
|
132
|
+
requires = ["hatchling"]
|
|
133
|
+
build-backend = "hatchling.build"
|
mt5api-1.0.5/pyproject.toml
DELETED
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
[project]
|
|
2
|
-
name = "mt5api"
|
|
3
|
-
version = "1.0.5"
|
|
4
|
-
description = "MetaTrader 5 REST API"
|
|
5
|
-
authors = [{name = "dceoy", email = "dceoy@users.noreply.github.com"}]
|
|
6
|
-
maintainers = [{name = "dceoy", email = "dceoy@users.noreply.github.com"}]
|
|
7
|
-
license = "MIT"
|
|
8
|
-
license-files = ["LICENSE"]
|
|
9
|
-
readme = "README.md"
|
|
10
|
-
requires-python = ">= 3.11, < 3.15"
|
|
11
|
-
dependencies = [
|
|
12
|
-
"pdmt5 >= 1.2.0",
|
|
13
|
-
"fastapi >= 0.115.0",
|
|
14
|
-
"uvicorn[standard] >= 0.32.0",
|
|
15
|
-
"pandas >= 3.0.3",
|
|
16
|
-
"pydantic >= 2.13.4",
|
|
17
|
-
"pyarrow >= 18.0.0",
|
|
18
|
-
]
|
|
19
|
-
classifiers = [
|
|
20
|
-
"Development Status :: 4 - Beta",
|
|
21
|
-
"Environment :: Console",
|
|
22
|
-
"License :: OSI Approved :: MIT License",
|
|
23
|
-
"Operating System :: Microsoft :: Windows",
|
|
24
|
-
"Programming Language :: Python",
|
|
25
|
-
"Programming Language :: Python :: 3",
|
|
26
|
-
"Intended Audience :: Financial and Insurance Industry",
|
|
27
|
-
"Topic :: Office/Business :: Financial :: Investment",
|
|
28
|
-
]
|
|
29
|
-
|
|
30
|
-
[project.urls]
|
|
31
|
-
Repository = "https://github.com/dceoy/mt5api.git"
|
|
32
|
-
|
|
33
|
-
[tool.uv]
|
|
34
|
-
required-environments = ["platform_system == 'Windows'"]
|
|
35
|
-
exclude-newer = "1 week"
|
|
36
|
-
exclude-newer-package = { pdmt5 = false }
|
|
37
|
-
|
|
38
|
-
[dependency-groups]
|
|
39
|
-
dev = [
|
|
40
|
-
"httpx >= 0.27.0",
|
|
41
|
-
"httpx2 >= 2.0.0",
|
|
42
|
-
"ruff >= 0.11.0",
|
|
43
|
-
"pyright >= 1.1.407",
|
|
44
|
-
"pytest >= 8.0.0",
|
|
45
|
-
"pytest-asyncio >= 0.25.2",
|
|
46
|
-
"pytest-mock >= 3.12.0",
|
|
47
|
-
"pytest-cov >= 5.0.0",
|
|
48
|
-
"pandas-stubs >= 3.0.3.260530",
|
|
49
|
-
"types-pygments >= 2.19.0.20250516",
|
|
50
|
-
"types-colorama >= 0.4.15.20240311",
|
|
51
|
-
"types-pexpect >= 4.9.0.20250516",
|
|
52
|
-
"mkdocs >= 1.6.1",
|
|
53
|
-
"mkdocs-material >= 9.6.15",
|
|
54
|
-
"mkdocstrings[python] >= 0.29.1",
|
|
55
|
-
]
|
|
56
|
-
|
|
57
|
-
[tool.hatch.build.targets.sdist]
|
|
58
|
-
only-include = ["mt5api"]
|
|
59
|
-
|
|
60
|
-
[tool.hatch.build.targets.wheel]
|
|
61
|
-
packages = ["mt5api"]
|
|
62
|
-
|
|
63
|
-
[tool.ruff]
|
|
64
|
-
line-length = 88
|
|
65
|
-
exclude = ["build", ".venv"]
|
|
66
|
-
preview = true
|
|
67
|
-
|
|
68
|
-
[tool.ruff.lint]
|
|
69
|
-
select = [
|
|
70
|
-
"F", # Pyflakes (F)
|
|
71
|
-
"E", # pycodestyle error (E)
|
|
72
|
-
"W", # pycodestyle warning (W)
|
|
73
|
-
"C90", # mccabe (C90)
|
|
74
|
-
"I", # isort (I)
|
|
75
|
-
"N", # pep8-naming (N)
|
|
76
|
-
"D", # pydocstyle (D)
|
|
77
|
-
"UP", # pyupgrade (UP)
|
|
78
|
-
"S", # flake8-bandit (S)
|
|
79
|
-
"B", # flake8-bugbear (B)
|
|
80
|
-
"C4", # flake8-comprehensions (C4)
|
|
81
|
-
"SIM", # flake8-simplify (SIM)
|
|
82
|
-
"ARG", # flake8-unused-arguments (ARG)
|
|
83
|
-
"PD", # pandas-vet (PD)
|
|
84
|
-
"PLC", # Pylint convention (PLC)
|
|
85
|
-
"PLE", # Pylint error (PLE)
|
|
86
|
-
"PLR", # Pylint refactor (PLR)
|
|
87
|
-
"PLW", # Pylint warning (PLW)
|
|
88
|
-
"FLY", # flynt (FLY)
|
|
89
|
-
"NPY", # NumPy-specific rules (NPY)
|
|
90
|
-
"PERF", # Perflint (PERF)
|
|
91
|
-
"FURB", # refurb (FURB)
|
|
92
|
-
"RUF", # Ruff-specific rules (RUF)
|
|
93
|
-
"YTT", # flake8-2020 (YTT)
|
|
94
|
-
"ANN", # flake8-annotations (ANN)
|
|
95
|
-
"ASYNC", # flake8-async (ASYNC)
|
|
96
|
-
"BLE", # flake8-blind-except (BLE)
|
|
97
|
-
"FBT", # flake8-boolean-trap (FBT)
|
|
98
|
-
"A", # flake8-builtins (A)
|
|
99
|
-
"COM", # flake8-commas (COM)
|
|
100
|
-
# "CPY", # flake8-copyright (CPY)
|
|
101
|
-
"DTZ", # flake8-datetimez (DTZ)
|
|
102
|
-
"T10", # flake8-debugger (T10)
|
|
103
|
-
"DJ", # flake8-django (DJ)
|
|
104
|
-
"EM", # flake8-errmsg (EM)
|
|
105
|
-
"EXE", # flake8-executable (EXE)
|
|
106
|
-
"FA", # flake8-future-annotations (FA)
|
|
107
|
-
"ISC", # flake8-implicit-str-concat (ISC)
|
|
108
|
-
"ICN", # flake8-import-conventions (ICN)
|
|
109
|
-
"LOG", # flake8-logging (LOG)
|
|
110
|
-
"G", # flake8-logging-format (G)
|
|
111
|
-
"INP", # flake8-no-pep420 (INP)
|
|
112
|
-
"PIE", # flake8-pie (PIE)
|
|
113
|
-
"T20", # flake8-print (T20)
|
|
114
|
-
"PYI", # flake8-pyi (PYI)
|
|
115
|
-
"PT", # flake8-pytest-style (PT)
|
|
116
|
-
"Q", # flake8-quotes (Q)
|
|
117
|
-
"RSE", # flake8-raise (RSE)
|
|
118
|
-
# "RET", # flake8-return (RET)
|
|
119
|
-
"SLF", # flake8-self (SLF)
|
|
120
|
-
"SLOT", # flake8-slots (SLOT)
|
|
121
|
-
"TID", # flake8-tidy-imports (TID)
|
|
122
|
-
"TCH", # flake8-type-checking (TCH)
|
|
123
|
-
"INT", # flake8-gettext (INT)
|
|
124
|
-
"PTH", # flake8-use-pathlib (PTH)
|
|
125
|
-
"TD", # flake8-todos (TD)
|
|
126
|
-
"FIX", # flake8-fixme (FIX)
|
|
127
|
-
"ERA", # eradicate (ERA)
|
|
128
|
-
"PGH", # pygrep-hooks (PGH)
|
|
129
|
-
"TRY", # tryceratops (TRY)
|
|
130
|
-
"FAST", # FastAPI (FAST)
|
|
131
|
-
"AIR", # Airflow (AIR)
|
|
132
|
-
"DOC", # pydoclint (DOC)
|
|
133
|
-
]
|
|
134
|
-
ignore = [
|
|
135
|
-
"COM812", # missing-trailing-comma
|
|
136
|
-
"FBT001", # boolean-type-hint-positional-argument
|
|
137
|
-
"FBT002", # boolean-default-value-positional-argument
|
|
138
|
-
]
|
|
139
|
-
|
|
140
|
-
[tool.ruff.lint.per-file-ignores]
|
|
141
|
-
"tests/**/*.py" = [
|
|
142
|
-
"DOC201", # Missing return documentation
|
|
143
|
-
"DOC501", # Raised exception missing from docstring
|
|
144
|
-
"PLC2701", # Private name import
|
|
145
|
-
"PLR0904", # Too many public methods
|
|
146
|
-
"PLR2004", # Magic value used in comparison
|
|
147
|
-
"PLR6301", # Method could be function/static/classmethod
|
|
148
|
-
"S101", # Use of assert (acceptable in tests)
|
|
149
|
-
"S106", # Possible hardcoded password
|
|
150
|
-
"SLF001", # Private member accessed
|
|
151
|
-
]
|
|
152
|
-
|
|
153
|
-
[tool.ruff.lint.pydocstyle]
|
|
154
|
-
convention = "google"
|
|
155
|
-
|
|
156
|
-
[tool.ruff.lint.pylint]
|
|
157
|
-
max-args = 10
|
|
158
|
-
max-public-methods = 40
|
|
159
|
-
|
|
160
|
-
[tool.pyright]
|
|
161
|
-
exclude = ["build", ".venv"]
|
|
162
|
-
venvPath = "."
|
|
163
|
-
venv = ".venv"
|
|
164
|
-
typeCheckingMode = "strict"
|
|
165
|
-
reportMissingTypeStubs = "none"
|
|
166
|
-
|
|
167
|
-
[tool.pytest.ini_options]
|
|
168
|
-
addopts = [
|
|
169
|
-
"--cov=mt5api",
|
|
170
|
-
"--cov-branch",
|
|
171
|
-
"--doctest-modules",
|
|
172
|
-
"--capture=no",
|
|
173
|
-
]
|
|
174
|
-
pythonpath = ["."]
|
|
175
|
-
testpaths = ["tests"]
|
|
176
|
-
python_files = ["test_*.py", "*_test.py"]
|
|
177
|
-
python_classes = ["Test*"]
|
|
178
|
-
python_functions = ["test_*"]
|
|
179
|
-
minversion = "6.0"
|
|
180
|
-
|
|
181
|
-
[tool.coverage.run]
|
|
182
|
-
source = ["mt5api"]
|
|
183
|
-
omit = [
|
|
184
|
-
"**/__init__.py",
|
|
185
|
-
"tests/**",
|
|
186
|
-
]
|
|
187
|
-
|
|
188
|
-
[tool.coverage.report]
|
|
189
|
-
show_missing = true
|
|
190
|
-
fail_under = 100
|
|
191
|
-
exclude_lines = ["if TYPE_CHECKING:"]
|
|
192
|
-
|
|
193
|
-
[build-system]
|
|
194
|
-
requires = ["hatchling"]
|
|
195
|
-
build-backend = "hatchling.build"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|