mt5api 0.1.0__tar.gz → 0.3.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-0.1.0 → mt5api-0.3.0}/.agents/skills/local-qa/SKILL.md +1 -1
- {mt5api-0.1.0 → mt5api-0.3.0}/.agents/skills/local-qa/scripts/qa.sh +1 -1
- {mt5api-0.1.0 → mt5api-0.3.0}/.agents/skills/mt5api/SKILL.md +73 -2
- {mt5api-0.1.0 → mt5api-0.3.0}/.github/workflows/ci.yml +1 -22
- mt5api-0.1.0/.github/workflows/claude-code.yml → mt5api-0.3.0/.github/workflows/claude.yml +3 -3
- mt5api-0.3.0/.github/workflows/release.yml +44 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/PKG-INFO +44 -17
- {mt5api-0.1.0 → mt5api-0.3.0}/README.md +42 -12
- {mt5api-0.1.0 → mt5api-0.3.0}/docs/api/rest-api.md +25 -8
- {mt5api-0.1.0 → mt5api-0.3.0}/docs/index.md +12 -8
- mt5api-0.3.0/mt5api/dependencies.py +236 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/mt5api/main.py +13 -30
- {mt5api-0.1.0 → mt5api-0.3.0}/mt5api/models.py +97 -169
- mt5api-0.3.0/mt5api/routers/__init__.py +16 -0
- mt5api-0.3.0/mt5api/routers/connection.py +72 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/pyproject.toml +2 -5
- {mt5api-0.1.0 → mt5api-0.3.0}/tests/mt5_constants.py +1 -1
- mt5api-0.3.0/tests/openapi_mt5_constants.py +34 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/tests/test_calc.py +16 -0
- mt5api-0.3.0/tests/test_connection.py +467 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/tests/test_main.py +22 -27
- {mt5api-0.1.0 → mt5api-0.3.0}/tests/test_market.py +8 -6
- {mt5api-0.1.0 → mt5api-0.3.0}/tests/test_models.py +97 -45
- {mt5api-0.1.0 → mt5api-0.3.0}/tests/test_trading.py +12 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/uv.lock +68 -298
- mt5api-0.1.0/mt5api/dependencies.py +0 -132
- mt5api-0.1.0/mt5api/routers/__init__.py +0 -7
- {mt5api-0.1.0 → mt5api-0.3.0}/.agents/skills/speckit-analyze/SKILL.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/.agents/skills/speckit-checklist/SKILL.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/.agents/skills/speckit-clarify/SKILL.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/.agents/skills/speckit-constitution/SKILL.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/.agents/skills/speckit-implement/SKILL.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/.agents/skills/speckit-plan/SKILL.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/.agents/skills/speckit-specify/SKILL.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/.agents/skills/speckit-tasks/SKILL.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/.agents/skills/speckit-taskstoissues/SKILL.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/.claude/agents/codex.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/.claude/agents/copilot.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/.claude/commands/speckit.analyze.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/.claude/commands/speckit.checklist.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/.claude/commands/speckit.clarify.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/.claude/commands/speckit.constitution.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/.claude/commands/speckit.implement.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/.claude/commands/speckit.plan.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/.claude/commands/speckit.specify.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/.claude/commands/speckit.tasks.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/.claude/commands/speckit.taskstoissues.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/.claude/settings.json +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/.github/FUNDING.yml +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/.github/dependabot.yml +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/.github/renovate.json +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/.gitignore +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/.specify/memory/constitution.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/.specify/scripts/bash/check-prerequisites.sh +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/.specify/scripts/bash/common.sh +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/.specify/scripts/bash/create-new-feature.sh +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/.specify/scripts/bash/setup-plan.sh +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/.specify/scripts/bash/update-agent-context.sh +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/.specify/templates/agent-file-template.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/.specify/templates/checklist-template.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/.specify/templates/plan-template.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/.specify/templates/spec-template.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/.specify/templates/tasks-template.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/AGENTS.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/CLAUDE.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/LICENSE +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/docs/api/deployment.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/docs/api/index.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/mkdocs.yml +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/mt5api/__init__.py +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/mt5api/__main__.py +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/mt5api/auth.py +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/mt5api/config.py +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/mt5api/constants.py +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/mt5api/formatters.py +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/mt5api/middleware.py +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/mt5api/routers/account.py +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/mt5api/routers/calc.py +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/mt5api/routers/health.py +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/mt5api/routers/history.py +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/mt5api/routers/market.py +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/mt5api/routers/symbols.py +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/mt5api/routers/trading.py +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/specs/041-mt5-rest-api/contracts/openapi.yaml +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/specs/041-mt5-rest-api/data-model.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/specs/041-mt5-rest-api/plan.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/specs/041-mt5-rest-api/quickstart.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/specs/041-mt5-rest-api/research.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/specs/041-mt5-rest-api/spec.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/specs/041-mt5-rest-api/tasks.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/specs/042-mt5-core-client/spec.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/specs/043-mt5-dataframe-client/spec.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/specs/044-mt5-trading-client/spec.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/specs/045-mt5-utils/spec.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/specs/046-mt5-api-service/spec.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/specs/047-api-auth-rate-limit/spec.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/specs/048-api-response-format/spec.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/specs/049-api-routing-models/spec.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/specs/050-api-runtime-deploy/spec.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/specs/051-api-error-logging/spec.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/specs/052-api-dependencies/spec.md +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/tests/__init__.py +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/tests/conftest.py +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/tests/test_account.py +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/tests/test_auth.py +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/tests/test_cli.py +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/tests/test_config.py +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/tests/test_dependencies.py +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/tests/test_formatters.py +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/tests/test_health.py +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/tests/test_history.py +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/tests/test_integration.py +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/tests/test_lifespan.py +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/tests/test_middleware.py +0 -0
- {mt5api-0.1.0 → mt5api-0.3.0}/tests/test_symbols.py +0 -0
|
@@ -3,8 +3,8 @@ name: mt5api
|
|
|
3
3
|
description: >-
|
|
4
4
|
Query the MT5 API for account info, terminal status, health checks, symbol
|
|
5
5
|
data, market data (OHLCV rates, ticks, market depth), open positions, pending
|
|
6
|
-
orders,
|
|
7
|
-
endpoint.
|
|
6
|
+
orders, trade history, and reconnecting the MT5 terminal with new
|
|
7
|
+
credentials. Use when the user wants to interact with any mt5api endpoint.
|
|
8
8
|
allowed-tools: Bash
|
|
9
9
|
---
|
|
10
10
|
|
|
@@ -30,6 +30,16 @@ if [ -n "${MT5API_SECRET_KEY:-}" ]; then
|
|
|
30
30
|
fi
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
+
Login credentials for `/connection/login` are read from the environment so
|
|
34
|
+
the password is never hard-coded in a command:
|
|
35
|
+
|
|
36
|
+
| Variable | Description | Required for login |
|
|
37
|
+
| ----------------- | ------------------------------------------ | ------------------ |
|
|
38
|
+
| `MT5API_LOGIN` | Trading account login (integer) | yes |
|
|
39
|
+
| `MT5API_PASSWORD` | Trading account password | yes |
|
|
40
|
+
| `MT5API_SERVER` | Trading server name (e.g., `Broker-Demo`) | yes |
|
|
41
|
+
| `MT5API_TIMEOUT` | Connection timeout in milliseconds (`> 0`) | no |
|
|
42
|
+
|
|
33
43
|
## Response Formats
|
|
34
44
|
|
|
35
45
|
All endpoints (except `/health`) return JSON by default. Request Parquet with
|
|
@@ -44,6 +54,11 @@ All endpoints (except `/health`) return JSON by default. Request Parquet with
|
|
|
44
54
|
symbol or skipping DOM data.
|
|
45
55
|
- Empty arrays from `/positions`, `/orders`, `/history/orders`, or
|
|
46
56
|
`/history/deals` are valid results.
|
|
57
|
+
- `/connection/login` reconnects the shared MT5 client to a different account.
|
|
58
|
+
It shuts down the current connection and releases any active market-book
|
|
59
|
+
subscriptions before logging in. Never echo the password back to the user
|
|
60
|
+
and do not log it; the response only confirms `login`, `server`, `timeout`,
|
|
61
|
+
and `connected`.
|
|
47
62
|
|
|
48
63
|
---
|
|
49
64
|
|
|
@@ -77,6 +92,59 @@ curl -s "${AUTH_HEADER[@]}" \
|
|
|
77
92
|
|
|
78
93
|
---
|
|
79
94
|
|
|
95
|
+
## Connection
|
|
96
|
+
|
|
97
|
+
### Reconnect to MT5
|
|
98
|
+
|
|
99
|
+
Shut down the current MT5 client and reconnect with new credentials. Active
|
|
100
|
+
market-book subscriptions are released first. The call is serialized so
|
|
101
|
+
concurrent reconnect attempts do not race. The password is sent only in the
|
|
102
|
+
request body and is never echoed in the response.
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
# Build JSON body from env vars; include timeout only when set
|
|
106
|
+
LOGIN_BODY=$(python3 -c "
|
|
107
|
+
import json, os, sys
|
|
108
|
+
body = {
|
|
109
|
+
'login': int(os.environ['MT5API_LOGIN']),
|
|
110
|
+
'password': os.environ['MT5API_PASSWORD'],
|
|
111
|
+
'server': os.environ['MT5API_SERVER'],
|
|
112
|
+
}
|
|
113
|
+
t = os.environ.get('MT5API_TIMEOUT')
|
|
114
|
+
if t:
|
|
115
|
+
body['timeout'] = int(t)
|
|
116
|
+
print(json.dumps(body))
|
|
117
|
+
")
|
|
118
|
+
curl -s -X POST "${AUTH_HEADER[@]}" \
|
|
119
|
+
-H 'Content-Type: application/json' \
|
|
120
|
+
-d "${LOGIN_BODY}" \
|
|
121
|
+
"${MT5API_URL}/connection/login" | python -m json.tool
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Request body:
|
|
125
|
+
|
|
126
|
+
| Field | Type | Required | Description |
|
|
127
|
+
| -------- | ------ | -------- | ------------------------------------------ |
|
|
128
|
+
| login | int | yes | Trading account login (positive integer) |
|
|
129
|
+
| password | string | yes | Trading account password (never echoed) |
|
|
130
|
+
| server | string | yes | Trading server name (e.g., `Broker-Demo`) |
|
|
131
|
+
| timeout | int | no | Connection timeout in milliseconds (`> 0`) |
|
|
132
|
+
|
|
133
|
+
Successful response (`200`):
|
|
134
|
+
|
|
135
|
+
| Field | Type | Description |
|
|
136
|
+
| --------- | ------ | -------------------------------------------- |
|
|
137
|
+
| login | int | Login that was used to connect |
|
|
138
|
+
| server | string | Trading server that was connected to |
|
|
139
|
+
| timeout | int? | Timeout in milliseconds if one was specified |
|
|
140
|
+
| connected | bool | `true` when the new connection succeeded |
|
|
141
|
+
|
|
142
|
+
On failure, MT5 errors surface as `503 Service Unavailable` with an RFC 7807
|
|
143
|
+
problem-details body. Never include the supplied password in any summary or
|
|
144
|
+
diagnostic you return to the user.
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
80
148
|
## Account & Terminal
|
|
81
149
|
|
|
82
150
|
### Account Info
|
|
@@ -323,3 +391,6 @@ Either `(date_from AND date_to)` or `(ticket OR position)` must be provided.
|
|
|
323
391
|
running or reachable.
|
|
324
392
|
9. For historical queries, remind the user that either a date range or a
|
|
325
393
|
ticket/position filter is required.
|
|
394
|
+
10. For `/connection/login`, always send the password in the POST body and
|
|
395
|
+
never repeat it in any reply or log message. If the user asks you to
|
|
396
|
+
reconnect, confirm the target `login`/`server` before sending the request.
|
|
@@ -19,7 +19,6 @@ on:
|
|
|
19
19
|
options:
|
|
20
20
|
- lint-and-test
|
|
21
21
|
- docs-deploy
|
|
22
|
-
- release
|
|
23
22
|
description: Choose the workflow to run
|
|
24
23
|
default: lint-and-test
|
|
25
24
|
permissions:
|
|
@@ -54,10 +53,7 @@ jobs:
|
|
|
54
53
|
python-docs-deploy:
|
|
55
54
|
if: >
|
|
56
55
|
github.event_name == 'push'
|
|
57
|
-
|| (
|
|
58
|
-
github.event_name == 'workflow_dispatch'
|
|
59
|
-
&& (inputs.workflow == 'docs-deploy' || inputs.workflow == 'release')
|
|
60
|
-
)
|
|
56
|
+
|| (github.event_name == 'workflow_dispatch' && inputs.workflow == 'docs-deploy')
|
|
61
57
|
permissions:
|
|
62
58
|
contents: write
|
|
63
59
|
uses: dceoy/gh-actions-for-devops/.github/workflows/python-package-mkdocs-gh-deploy.yml@main # zizmor: ignore[unpinned-uses]
|
|
@@ -66,23 +62,6 @@ jobs:
|
|
|
66
62
|
runs-on: ubuntu-slim
|
|
67
63
|
secrets:
|
|
68
64
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
69
|
-
python-package-release:
|
|
70
|
-
if: >
|
|
71
|
-
github.event_name == 'push'
|
|
72
|
-
|| (
|
|
73
|
-
github.event_name == 'workflow_dispatch'
|
|
74
|
-
&& (inputs.workflow == 'release' || inputs.workflow == 'lint-and-test')
|
|
75
|
-
)
|
|
76
|
-
permissions:
|
|
77
|
-
contents: write
|
|
78
|
-
id-token: write
|
|
79
|
-
uses: dceoy/gh-actions-for-devops/.github/workflows/python-package-release-on-pypi-and-github.yml@main # zizmor: ignore[unpinned-uses]
|
|
80
|
-
with:
|
|
81
|
-
package-path: .
|
|
82
|
-
create-releases: ${{ github.event_name == 'workflow_dispatch' && inputs.workflow == 'release' }}
|
|
83
|
-
secrets:
|
|
84
|
-
PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
|
|
85
|
-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
86
65
|
dependabot-auto-merge:
|
|
87
66
|
if: >
|
|
88
67
|
github.event_name == 'pull_request' && github.actor == 'dependabot[bot]'
|
|
@@ -26,7 +26,7 @@ jobs:
|
|
|
26
26
|
claude-code-review:
|
|
27
27
|
if: >
|
|
28
28
|
github.event_name == 'pull_request'
|
|
29
|
-
&& github.event.pull_request.draft
|
|
29
|
+
&& (! github.event.pull_request.draft)
|
|
30
30
|
&& (! startsWith(github.head_ref, 'dependabot/'))
|
|
31
31
|
&& (! startsWith(github.head_ref, 'renovate/'))
|
|
32
32
|
permissions:
|
|
@@ -37,7 +37,7 @@ jobs:
|
|
|
37
37
|
actions: read
|
|
38
38
|
uses: dceoy/gh-actions-for-devops/.github/workflows/claude-code-review.yml@main # zizmor: ignore[unpinned-uses]
|
|
39
39
|
secrets:
|
|
40
|
-
CLAUDE_CODE_OAUTH_TOKEN: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
|
|
40
|
+
CLAUDE_CODE_OAUTH_TOKEN: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }} # zizmor: ignore[secrets-outside-env]
|
|
41
41
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
42
42
|
claude-code-bot:
|
|
43
43
|
if: >
|
|
@@ -53,5 +53,5 @@ jobs:
|
|
|
53
53
|
actions: read
|
|
54
54
|
uses: dceoy/gh-actions-for-devops/.github/workflows/claude-code-bot.yml@main # zizmor: ignore[unpinned-uses]
|
|
55
55
|
secrets:
|
|
56
|
-
CLAUDE_CODE_OAUTH_TOKEN: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
|
|
56
|
+
CLAUDE_CODE_OAUTH_TOKEN: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }} # zizmor: ignore[secrets-outside-env]
|
|
57
57
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Release
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
permissions:
|
|
6
|
+
contents: read
|
|
7
|
+
defaults:
|
|
8
|
+
run:
|
|
9
|
+
shell: bash -euo pipefail {0}
|
|
10
|
+
working-directory: .
|
|
11
|
+
jobs:
|
|
12
|
+
build-and-release:
|
|
13
|
+
permissions:
|
|
14
|
+
contents: write
|
|
15
|
+
id-token: write
|
|
16
|
+
uses: dceoy/gh-actions-for-devops/.github/workflows/python-package-release-on-pypi-and-github.yml@main # zizmor: ignore[unpinned-uses]
|
|
17
|
+
with:
|
|
18
|
+
package-path: .
|
|
19
|
+
create-github-release: true
|
|
20
|
+
publish-to-pypi: false
|
|
21
|
+
secrets:
|
|
22
|
+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
23
|
+
publish-to-pypi:
|
|
24
|
+
name: Publish the Python 🐍 distribution 📦 to PyPI
|
|
25
|
+
if: >
|
|
26
|
+
startsWith(github.ref, 'refs/tags/')
|
|
27
|
+
needs:
|
|
28
|
+
- build-and-release
|
|
29
|
+
runs-on: ubuntu-latest
|
|
30
|
+
environment:
|
|
31
|
+
name: pypi
|
|
32
|
+
url: https://pypi.org/p/${{ needs.build-and-release.outputs.project-name }}
|
|
33
|
+
permissions:
|
|
34
|
+
id-token: write # IMPORTANT: mandatory for trusted publishing
|
|
35
|
+
steps:
|
|
36
|
+
- name: Download all the dists
|
|
37
|
+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
|
38
|
+
with:
|
|
39
|
+
name: ${{ needs.build-and-release.outputs.distribution-artifact-name }}
|
|
40
|
+
path: dist/
|
|
41
|
+
- name: Publish distribution 📦 to PyPI
|
|
42
|
+
uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0
|
|
43
|
+
with:
|
|
44
|
+
verbose: true
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mt5api
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.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,11 +18,8 @@ Classifier: Topic :: Office/Business :: Financial :: Investment
|
|
|
18
18
|
Requires-Python: <3.14,>=3.11
|
|
19
19
|
Requires-Dist: fastapi>=0.115.0
|
|
20
20
|
Requires-Dist: httpx>=0.27.0
|
|
21
|
-
Requires-Dist:
|
|
22
|
-
Requires-Dist: passlib[bcrypt]>=1.7.4
|
|
23
|
-
Requires-Dist: pdmt5>=0.2.1
|
|
21
|
+
Requires-Dist: pdmt5>=0.3.0
|
|
24
22
|
Requires-Dist: pyarrow>=18.0.0
|
|
25
|
-
Requires-Dist: python-jose[cryptography]>=3.3.0
|
|
26
23
|
Requires-Dist: python-multipart>=0.0.9
|
|
27
24
|
Requires-Dist: uvicorn[standard]>=0.32.0
|
|
28
25
|
Description-Content-Type: text/markdown
|
|
@@ -34,14 +31,18 @@ MetaTrader 5 REST API
|
|
|
34
31
|
[](https://github.com/dceoy/mt5api/actions/workflows/ci.yml)
|
|
35
32
|
|
|
36
33
|
mt5api exposes MT5 market data, account info, trading history, and trading
|
|
37
|
-
operations over HTTP. It
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
operations over HTTP. It is a FastAPI/HTTP adapter over
|
|
35
|
+
[`pdmt5`](https://github.com/dceoy/pdmt5), which provides the core MT5 client,
|
|
36
|
+
dataframe/trading primitives, and canonical MT5 constant parsing. mt5api adds
|
|
37
|
+
optional API-key auth and JSON/Parquet response formatting.
|
|
40
38
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
[`mt5cli`](https://github.com/dceoy/mt5cli) is a sibling CLI/batch adapter for
|
|
40
|
+
the same pdmt5 stack; it is not a dependency of mt5api.
|
|
41
|
+
|
|
42
|
+
The API server must run on Windows. pdmt5 connects through the MetaTrader 5
|
|
43
|
+
Python API, which is supported only on Windows, so you must host `mt5api` on a
|
|
44
|
+
Windows machine with a logged-in MetaTrader 5 terminal. HTTP clients can connect
|
|
45
|
+
from any operating system.
|
|
45
46
|
|
|
46
47
|
## Architecture
|
|
47
48
|
|
|
@@ -61,7 +62,7 @@ graph TB
|
|
|
61
62
|
Formatters --> Middleware
|
|
62
63
|
end
|
|
63
64
|
|
|
64
|
-
Deps --> pdmt5["pdmt5<br/>MT5 Client
|
|
65
|
+
Deps --> pdmt5["pdmt5<br/>MT5 Client · Constants · Dataframes"]
|
|
65
66
|
pdmt5 --> MT5["MetaTrader 5<br/>Terminal"]
|
|
66
67
|
end
|
|
67
68
|
|
|
@@ -89,6 +90,20 @@ graph TB
|
|
|
89
90
|
|
|
90
91
|
Install and run the API on the Windows machine where MetaTrader 5 is installed.
|
|
91
92
|
|
|
93
|
+
Install the latest release from PyPI:
|
|
94
|
+
|
|
95
|
+
```console
|
|
96
|
+
pip install mt5api
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Or, when managing the project with `uv`, add it as a dependency:
|
|
100
|
+
|
|
101
|
+
```console
|
|
102
|
+
uv add mt5api
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Alternatively, install from source:
|
|
106
|
+
|
|
92
107
|
```powershell
|
|
93
108
|
git clone https://github.com/dceoy/mt5api.git
|
|
94
109
|
cd mt5api
|
|
@@ -97,12 +112,24 @@ uv sync
|
|
|
97
112
|
|
|
98
113
|
## Running the API on Windows
|
|
99
114
|
|
|
115
|
+
After installing from PyPI:
|
|
116
|
+
|
|
100
117
|
```powershell
|
|
101
118
|
$env:MT5API_SECRET_KEY = "your-secret-api-key" # Optional: omit to disable auth
|
|
102
119
|
$env:MT5API_ROUTER_PREFIX = "/api/v1" # Optional: omit for root-level routes
|
|
103
|
-
|
|
120
|
+
python -m mt5api
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
`python -m mt5api` reads `MT5API_HOST`, `MT5API_PORT`, and `MT5API_LOG_LEVEL`
|
|
124
|
+
from the environment. You can also invoke `uvicorn` directly:
|
|
125
|
+
|
|
126
|
+
```powershell
|
|
127
|
+
uvicorn mt5api.main:app --host 0.0.0.0 --port 8000
|
|
104
128
|
```
|
|
105
129
|
|
|
130
|
+
If you cloned the source tree, prepend `uv run` to either command (for example,
|
|
131
|
+
`uv run uvicorn mt5api.main:app --host 0.0.0.0 --port 8000`).
|
|
132
|
+
|
|
106
133
|
Docs:
|
|
107
134
|
|
|
108
135
|
- Swagger UI: `http://localhost:8000/docs`
|
|
@@ -136,9 +163,9 @@ curl -H "X-API-Key: your-secret-api-key" "http://windows-host:8000/symbols?group
|
|
|
136
163
|
curl -H "X-API-Key: your-secret-api-key" -H "Accept: application/parquet" "http://windows-host:8000/rates/from?symbol=EURUSD&timeframe=TIMEFRAME_M1&date_from=2024-01-01T00:00:00Z&count=100"
|
|
137
164
|
```
|
|
138
165
|
|
|
139
|
-
Market-data and calculation endpoints accept MetaTrader 5 constants
|
|
140
|
-
|
|
141
|
-
integer value.
|
|
166
|
+
Market-data and calculation endpoints accept MetaTrader 5 constants by official
|
|
167
|
+
name (`TIMEFRAME_M1`, `COPY_TICKS_ALL`, `ORDER_TYPE_BUY`), short alias (`M1`,
|
|
168
|
+
`ALL`, `BUY`), or integer value.
|
|
142
169
|
|
|
143
170
|
## Endpoints
|
|
144
171
|
|
|
@@ -5,14 +5,18 @@ MetaTrader 5 REST API
|
|
|
5
5
|
[](https://github.com/dceoy/mt5api/actions/workflows/ci.yml)
|
|
6
6
|
|
|
7
7
|
mt5api exposes MT5 market data, account info, trading history, and trading
|
|
8
|
-
operations over HTTP. It
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
operations over HTTP. It is a FastAPI/HTTP adapter over
|
|
9
|
+
[`pdmt5`](https://github.com/dceoy/pdmt5), which provides the core MT5 client,
|
|
10
|
+
dataframe/trading primitives, and canonical MT5 constant parsing. mt5api adds
|
|
11
|
+
optional API-key auth and JSON/Parquet response formatting.
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
[`mt5cli`](https://github.com/dceoy/mt5cli) is a sibling CLI/batch adapter for
|
|
14
|
+
the same pdmt5 stack; it is not a dependency of mt5api.
|
|
15
|
+
|
|
16
|
+
The API server must run on Windows. pdmt5 connects through the MetaTrader 5
|
|
17
|
+
Python API, which is supported only on Windows, so you must host `mt5api` on a
|
|
18
|
+
Windows machine with a logged-in MetaTrader 5 terminal. HTTP clients can connect
|
|
19
|
+
from any operating system.
|
|
16
20
|
|
|
17
21
|
## Architecture
|
|
18
22
|
|
|
@@ -32,7 +36,7 @@ graph TB
|
|
|
32
36
|
Formatters --> Middleware
|
|
33
37
|
end
|
|
34
38
|
|
|
35
|
-
Deps --> pdmt5["pdmt5<br/>MT5 Client
|
|
39
|
+
Deps --> pdmt5["pdmt5<br/>MT5 Client · Constants · Dataframes"]
|
|
36
40
|
pdmt5 --> MT5["MetaTrader 5<br/>Terminal"]
|
|
37
41
|
end
|
|
38
42
|
|
|
@@ -60,6 +64,20 @@ graph TB
|
|
|
60
64
|
|
|
61
65
|
Install and run the API on the Windows machine where MetaTrader 5 is installed.
|
|
62
66
|
|
|
67
|
+
Install the latest release from PyPI:
|
|
68
|
+
|
|
69
|
+
```console
|
|
70
|
+
pip install mt5api
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Or, when managing the project with `uv`, add it as a dependency:
|
|
74
|
+
|
|
75
|
+
```console
|
|
76
|
+
uv add mt5api
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Alternatively, install from source:
|
|
80
|
+
|
|
63
81
|
```powershell
|
|
64
82
|
git clone https://github.com/dceoy/mt5api.git
|
|
65
83
|
cd mt5api
|
|
@@ -68,12 +86,24 @@ uv sync
|
|
|
68
86
|
|
|
69
87
|
## Running the API on Windows
|
|
70
88
|
|
|
89
|
+
After installing from PyPI:
|
|
90
|
+
|
|
71
91
|
```powershell
|
|
72
92
|
$env:MT5API_SECRET_KEY = "your-secret-api-key" # Optional: omit to disable auth
|
|
73
93
|
$env:MT5API_ROUTER_PREFIX = "/api/v1" # Optional: omit for root-level routes
|
|
74
|
-
|
|
94
|
+
python -m mt5api
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
`python -m mt5api` reads `MT5API_HOST`, `MT5API_PORT`, and `MT5API_LOG_LEVEL`
|
|
98
|
+
from the environment. You can also invoke `uvicorn` directly:
|
|
99
|
+
|
|
100
|
+
```powershell
|
|
101
|
+
uvicorn mt5api.main:app --host 0.0.0.0 --port 8000
|
|
75
102
|
```
|
|
76
103
|
|
|
104
|
+
If you cloned the source tree, prepend `uv run` to either command (for example,
|
|
105
|
+
`uv run uvicorn mt5api.main:app --host 0.0.0.0 --port 8000`).
|
|
106
|
+
|
|
77
107
|
Docs:
|
|
78
108
|
|
|
79
109
|
- Swagger UI: `http://localhost:8000/docs`
|
|
@@ -107,9 +137,9 @@ curl -H "X-API-Key: your-secret-api-key" "http://windows-host:8000/symbols?group
|
|
|
107
137
|
curl -H "X-API-Key: your-secret-api-key" -H "Accept: application/parquet" "http://windows-host:8000/rates/from?symbol=EURUSD&timeframe=TIMEFRAME_M1&date_from=2024-01-01T00:00:00Z&count=100"
|
|
108
138
|
```
|
|
109
139
|
|
|
110
|
-
Market-data and calculation endpoints accept MetaTrader 5 constants
|
|
111
|
-
|
|
112
|
-
integer value.
|
|
140
|
+
Market-data and calculation endpoints accept MetaTrader 5 constants by official
|
|
141
|
+
name (`TIMEFRAME_M1`, `COPY_TICKS_ALL`, `ORDER_TYPE_BUY`), short alias (`M1`,
|
|
142
|
+
`ALL`, `BUY`), or integer value.
|
|
113
143
|
|
|
114
144
|
## Endpoints
|
|
115
145
|
|
|
@@ -108,22 +108,23 @@ If `MT5API_ROUTER_PREFIX` is configured, prepend it to each API route below.
|
|
|
108
108
|
|
|
109
109
|
### Market Data
|
|
110
110
|
|
|
111
|
-
- `timeframe` and `flags` accept
|
|
112
|
-
|
|
113
|
-
value.
|
|
111
|
+
- `timeframe` and `flags` accept the official MetaTrader 5 constant name (for
|
|
112
|
+
example `TIMEFRAME_M1`, `COPY_TICKS_ALL`), a short alias (for example `M1`,
|
|
113
|
+
`ALL`), or the equivalent integer value.
|
|
114
114
|
- `GET /rates/from` (`symbol`, `timeframe`, `date_from`, `count`, `format`)
|
|
115
115
|
- `GET /rates/from-pos` (`symbol`, `timeframe`, `start_pos`, `count`, `format`)
|
|
116
116
|
- `GET /rates/range` (`symbol`, `timeframe`, `date_from`, `date_to`, `format`)
|
|
117
117
|
- `GET /ticks/from` (`symbol`, `date_from`, `count`, `flags`, `format`)
|
|
118
118
|
- `GET /ticks/range` (`symbol`, `date_from`, `date_to`, `flags`, `format`)
|
|
119
|
-
- `GET /market-book/{symbol}` (`format`) — Market depth (DOM)
|
|
120
|
-
- `POST /market-book/{symbol}/subscribe` — Subscribe to DOM events
|
|
121
|
-
- `POST /market-book/{symbol}/unsubscribe` — Unsubscribe from DOM events
|
|
119
|
+
- `GET /market-book/{symbol}` (`format`) — Market depth (DOM) _(experimental)_
|
|
120
|
+
- `POST /market-book/{symbol}/subscribe` — Subscribe to DOM events _(experimental)_
|
|
121
|
+
- `POST /market-book/{symbol}/unsubscribe` — Unsubscribe from DOM events _(experimental)_
|
|
122
122
|
|
|
123
123
|
### Calculations
|
|
124
124
|
|
|
125
|
-
- `action` accepts
|
|
126
|
-
`ORDER_TYPE_BUY`) or the equivalent
|
|
125
|
+
- `action` accepts the official MetaTrader 5 constant name (for example
|
|
126
|
+
`ORDER_TYPE_BUY`), a short alias (for example `BUY`), or the equivalent
|
|
127
|
+
integer value.
|
|
127
128
|
- `GET /calc/margin` (`action`, `symbol`, `volume`, `price`, `format`) —
|
|
128
129
|
Calculate required margin in account currency
|
|
129
130
|
- `GET /calc/profit` (`action`, `symbol`, `volume`, `price_open`,
|
|
@@ -162,6 +163,14 @@ structure](https://www.mql5.com/en/docs/constants/structures/mqltraderequest),
|
|
|
162
163
|
with typed validation for core fields such as `action`, `symbol`, `volume`,
|
|
163
164
|
`type`, and `price`.
|
|
164
165
|
|
|
166
|
+
### Connection
|
|
167
|
+
|
|
168
|
+
- `POST /connection/login` (body: `{"login": ..., "password": "...",
|
|
169
|
+
"server": "...", "timeout": ...}`) — Reconnect the MT5 terminal with the
|
|
170
|
+
supplied credentials. Any active market-book subscriptions are released and
|
|
171
|
+
the previous MT5 client is shut down before the new connection is
|
|
172
|
+
established. The supplied password is never echoed in responses or logs.
|
|
173
|
+
|
|
165
174
|
## Response Formatter Utilities
|
|
166
175
|
|
|
167
176
|
If you are extending the API with custom endpoints, use the formatter helpers
|
|
@@ -291,6 +300,14 @@ curl -X POST -H "X-API-Key: your-secret-api-key" -H "Content-Type: application/j
|
|
|
291
300
|
"http://windows-host:8000/order/check"
|
|
292
301
|
```
|
|
293
302
|
|
|
303
|
+
### Reconnect to MT5
|
|
304
|
+
|
|
305
|
+
```console
|
|
306
|
+
curl -X POST -H "X-API-Key: your-secret-api-key" -H "Content-Type: application/json" \
|
|
307
|
+
-d '{"login": 12345678, "password": "s3cret", "server": "MetaQuotes-Demo", "timeout": 60000}' \
|
|
308
|
+
"http://windows-host:8000/connection/login"
|
|
309
|
+
```
|
|
310
|
+
|
|
294
311
|
## Error Responses
|
|
295
312
|
|
|
296
313
|
Errors follow RFC 7807 Problem Details:
|
|
@@ -5,14 +5,18 @@ trading operations.
|
|
|
5
5
|
|
|
6
6
|
## Overview
|
|
7
7
|
|
|
8
|
-
mt5api
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
mt5api is a FastAPI/HTTP adapter over
|
|
9
|
+
[`pdmt5`](https://github.com/dceoy/pdmt5). pdmt5 provides the core MT5 client,
|
|
10
|
+
dataframe/trading primitives, and canonical MT5 constant parsing. mt5api adds
|
|
11
|
+
optional authentication, response formatting, and OpenAPI documentation.
|
|
12
|
+
|
|
13
|
+
[`mt5cli`](https://github.com/dceoy/mt5cli) is a sibling CLI/batch adapter for
|
|
14
|
+
the same pdmt5 stack; it is not a dependency of mt5api.
|
|
15
|
+
|
|
16
|
+
The API server must run on Windows because pdmt5 connects through the MetaTrader
|
|
17
|
+
5 Python API, which is Windows-only. Run `mt5api` on a Windows host with
|
|
18
|
+
MetaTrader 5 installed and logged in. API clients can connect from any operating
|
|
19
|
+
system.
|
|
16
20
|
|
|
17
21
|
## Features
|
|
18
22
|
|