mt5api 0.0.2__tar.gz → 0.0.4__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 (130) hide show
  1. mt5api-0.0.4/.agents/skills/local-qa/SKILL.md +22 -0
  2. mt5api-0.0.4/.agents/skills/mt5api/SKILL.md +325 -0
  3. mt5api-0.0.4/AGENTS.md +90 -0
  4. mt5api-0.0.4/PKG-INFO +171 -0
  5. mt5api-0.0.4/README.md +141 -0
  6. {mt5api-0.0.2 → mt5api-0.0.4}/docs/api/deployment.md +8 -6
  7. mt5api-0.0.4/docs/api/index.md +69 -0
  8. mt5api-0.0.4/docs/api/rest-api.md +323 -0
  9. {mt5api-0.0.2 → mt5api-0.0.4}/docs/index.md +17 -14
  10. {mt5api-0.0.2 → mt5api-0.0.4}/mkdocs.yml +0 -4
  11. {mt5api-0.0.2 → mt5api-0.0.4}/mt5api/__main__.py +18 -13
  12. {mt5api-0.0.2 → mt5api-0.0.4}/mt5api/auth.py +10 -7
  13. mt5api-0.0.4/mt5api/config.py +144 -0
  14. mt5api-0.0.4/mt5api/constants.py +36 -0
  15. {mt5api-0.0.2 → mt5api-0.0.4}/mt5api/main.py +79 -25
  16. {mt5api-0.0.2 → mt5api-0.0.4}/mt5api/middleware.py +4 -3
  17. mt5api-0.0.4/mt5api/models.py +884 -0
  18. mt5api-0.0.4/mt5api/routers/__init__.py +7 -0
  19. {mt5api-0.0.2 → mt5api-0.0.4}/mt5api/routers/account.py +0 -1
  20. mt5api-0.0.4/mt5api/routers/calc.py +87 -0
  21. {mt5api-0.0.2 → mt5api-0.0.4}/mt5api/routers/health.py +26 -3
  22. {mt5api-0.0.2 → mt5api-0.0.4}/mt5api/routers/history.py +87 -1
  23. {mt5api-0.0.2 → mt5api-0.0.4}/mt5api/routers/market.py +0 -1
  24. {mt5api-0.0.2 → mt5api-0.0.4}/mt5api/routers/symbols.py +19 -1
  25. mt5api-0.0.4/mt5api/routers/trading.py +218 -0
  26. {mt5api-0.0.2 → mt5api-0.0.4}/pyproject.toml +1 -1
  27. {mt5api-0.0.2 → mt5api-0.0.4}/specs/041-mt5-rest-api/contracts/openapi.yaml +20 -20
  28. {mt5api-0.0.2 → mt5api-0.0.4}/specs/041-mt5-rest-api/data-model.md +5 -5
  29. {mt5api-0.0.2 → mt5api-0.0.4}/specs/041-mt5-rest-api/plan.md +13 -13
  30. {mt5api-0.0.2 → mt5api-0.0.4}/specs/041-mt5-rest-api/quickstart.md +42 -42
  31. {mt5api-0.0.2 → mt5api-0.0.4}/specs/041-mt5-rest-api/research.md +13 -13
  32. {mt5api-0.0.2 → mt5api-0.0.4}/specs/041-mt5-rest-api/tasks.md +16 -16
  33. {mt5api-0.0.2 → mt5api-0.0.4}/tests/conftest.py +70 -37
  34. mt5api-0.0.4/tests/mt5_constants.py +75 -0
  35. {mt5api-0.0.2 → mt5api-0.0.4}/tests/test_account.py +8 -8
  36. {mt5api-0.0.2 → mt5api-0.0.4}/tests/test_auth.py +58 -12
  37. mt5api-0.0.4/tests/test_calc.py +296 -0
  38. {mt5api-0.0.2 → mt5api-0.0.4}/tests/test_cli.py +19 -13
  39. mt5api-0.0.4/tests/test_config.py +163 -0
  40. {mt5api-0.0.2 → mt5api-0.0.4}/tests/test_dependencies.py +2 -2
  41. {mt5api-0.0.2 → mt5api-0.0.4}/tests/test_health.py +41 -5
  42. mt5api-0.0.4/tests/test_history.py +394 -0
  43. {mt5api-0.0.2 → mt5api-0.0.4}/tests/test_integration.py +9 -9
  44. {mt5api-0.0.2 → mt5api-0.0.4}/tests/test_lifespan.py +1 -1
  45. mt5api-0.0.4/tests/test_main.py +158 -0
  46. {mt5api-0.0.2 → mt5api-0.0.4}/tests/test_market.py +151 -52
  47. {mt5api-0.0.2 → mt5api-0.0.4}/tests/test_middleware.py +4 -3
  48. mt5api-0.0.4/tests/test_models.py +243 -0
  49. {mt5api-0.0.2 → mt5api-0.0.4}/tests/test_symbols.py +45 -14
  50. mt5api-0.0.4/tests/test_trading.py +523 -0
  51. {mt5api-0.0.2 → mt5api-0.0.4}/uv.lock +1 -1
  52. mt5api-0.0.2/.agents/skills/local-qa/SKILL.md +0 -19
  53. mt5api-0.0.2/.agents/skills/mt5-account/SKILL.md +0 -55
  54. mt5api-0.0.2/.agents/skills/mt5-health/SKILL.md +0 -47
  55. mt5api-0.0.2/.agents/skills/mt5-history/SKILL.md +0 -111
  56. mt5api-0.0.2/.agents/skills/mt5-market/SKILL.md +0 -122
  57. mt5api-0.0.2/.agents/skills/mt5-symbols/SKILL.md +0 -69
  58. mt5api-0.0.2/AGENTS.md +0 -65
  59. mt5api-0.0.2/PKG-INFO +0 -115
  60. mt5api-0.0.2/README.md +0 -85
  61. mt5api-0.0.2/docs/api/dataframe.md +0 -165
  62. mt5api-0.0.2/docs/api/index.md +0 -78
  63. mt5api-0.0.2/docs/api/mt5.md +0 -324
  64. mt5api-0.0.2/docs/api/rest-api.md +0 -201
  65. mt5api-0.0.2/docs/api/trading.md +0 -399
  66. mt5api-0.0.2/docs/api/utils.md +0 -117
  67. mt5api-0.0.2/mt5api/models.py +0 -408
  68. mt5api-0.0.2/mt5api/routers/__init__.py +0 -7
  69. mt5api-0.0.2/tests/test_config.py +0 -34
  70. mt5api-0.0.2/tests/test_history.py +0 -195
  71. mt5api-0.0.2/tests/test_main.py +0 -55
  72. mt5api-0.0.2/tests/test_models.py +0 -24
  73. {mt5api-0.0.2 → mt5api-0.0.4}/.agents/skills/local-qa/scripts/qa.sh +0 -0
  74. {mt5api-0.0.2 → mt5api-0.0.4}/.agents/skills/speckit-analyze/SKILL.md +0 -0
  75. {mt5api-0.0.2 → mt5api-0.0.4}/.agents/skills/speckit-checklist/SKILL.md +0 -0
  76. {mt5api-0.0.2 → mt5api-0.0.4}/.agents/skills/speckit-clarify/SKILL.md +0 -0
  77. {mt5api-0.0.2 → mt5api-0.0.4}/.agents/skills/speckit-constitution/SKILL.md +0 -0
  78. {mt5api-0.0.2 → mt5api-0.0.4}/.agents/skills/speckit-implement/SKILL.md +0 -0
  79. {mt5api-0.0.2 → mt5api-0.0.4}/.agents/skills/speckit-plan/SKILL.md +0 -0
  80. {mt5api-0.0.2 → mt5api-0.0.4}/.agents/skills/speckit-specify/SKILL.md +0 -0
  81. {mt5api-0.0.2 → mt5api-0.0.4}/.agents/skills/speckit-tasks/SKILL.md +0 -0
  82. {mt5api-0.0.2 → mt5api-0.0.4}/.agents/skills/speckit-taskstoissues/SKILL.md +0 -0
  83. {mt5api-0.0.2 → mt5api-0.0.4}/.claude/agents/codex.md +0 -0
  84. {mt5api-0.0.2 → mt5api-0.0.4}/.claude/agents/copilot.md +0 -0
  85. {mt5api-0.0.2 → mt5api-0.0.4}/.claude/commands/speckit.analyze.md +0 -0
  86. {mt5api-0.0.2 → mt5api-0.0.4}/.claude/commands/speckit.checklist.md +0 -0
  87. {mt5api-0.0.2 → mt5api-0.0.4}/.claude/commands/speckit.clarify.md +0 -0
  88. {mt5api-0.0.2 → mt5api-0.0.4}/.claude/commands/speckit.constitution.md +0 -0
  89. {mt5api-0.0.2 → mt5api-0.0.4}/.claude/commands/speckit.implement.md +0 -0
  90. {mt5api-0.0.2 → mt5api-0.0.4}/.claude/commands/speckit.plan.md +0 -0
  91. {mt5api-0.0.2 → mt5api-0.0.4}/.claude/commands/speckit.specify.md +0 -0
  92. {mt5api-0.0.2 → mt5api-0.0.4}/.claude/commands/speckit.tasks.md +0 -0
  93. {mt5api-0.0.2 → mt5api-0.0.4}/.claude/commands/speckit.taskstoissues.md +0 -0
  94. {mt5api-0.0.2 → mt5api-0.0.4}/.claude/settings.json +0 -0
  95. {mt5api-0.0.2 → mt5api-0.0.4}/.github/FUNDING.yml +0 -0
  96. {mt5api-0.0.2 → mt5api-0.0.4}/.github/dependabot.yml +0 -0
  97. {mt5api-0.0.2 → mt5api-0.0.4}/.github/renovate.json +0 -0
  98. {mt5api-0.0.2 → mt5api-0.0.4}/.github/workflows/ci.yml +0 -0
  99. {mt5api-0.0.2 → mt5api-0.0.4}/.github/workflows/claude-code.yml +0 -0
  100. {mt5api-0.0.2 → mt5api-0.0.4}/.gitignore +0 -0
  101. {mt5api-0.0.2 → mt5api-0.0.4}/.specify/memory/constitution.md +0 -0
  102. {mt5api-0.0.2 → mt5api-0.0.4}/.specify/scripts/bash/check-prerequisites.sh +0 -0
  103. {mt5api-0.0.2 → mt5api-0.0.4}/.specify/scripts/bash/common.sh +0 -0
  104. {mt5api-0.0.2 → mt5api-0.0.4}/.specify/scripts/bash/create-new-feature.sh +0 -0
  105. {mt5api-0.0.2 → mt5api-0.0.4}/.specify/scripts/bash/setup-plan.sh +0 -0
  106. {mt5api-0.0.2 → mt5api-0.0.4}/.specify/scripts/bash/update-agent-context.sh +0 -0
  107. {mt5api-0.0.2 → mt5api-0.0.4}/.specify/templates/agent-file-template.md +0 -0
  108. {mt5api-0.0.2 → mt5api-0.0.4}/.specify/templates/checklist-template.md +0 -0
  109. {mt5api-0.0.2 → mt5api-0.0.4}/.specify/templates/plan-template.md +0 -0
  110. {mt5api-0.0.2 → mt5api-0.0.4}/.specify/templates/spec-template.md +0 -0
  111. {mt5api-0.0.2 → mt5api-0.0.4}/.specify/templates/tasks-template.md +0 -0
  112. {mt5api-0.0.2 → mt5api-0.0.4}/CLAUDE.md +0 -0
  113. {mt5api-0.0.2 → mt5api-0.0.4}/LICENSE +0 -0
  114. {mt5api-0.0.2 → mt5api-0.0.4}/mt5api/__init__.py +0 -0
  115. {mt5api-0.0.2 → mt5api-0.0.4}/mt5api/dependencies.py +0 -0
  116. {mt5api-0.0.2 → mt5api-0.0.4}/mt5api/formatters.py +0 -0
  117. {mt5api-0.0.2 → mt5api-0.0.4}/specs/041-mt5-rest-api/spec.md +0 -0
  118. {mt5api-0.0.2 → mt5api-0.0.4}/specs/042-mt5-core-client/spec.md +0 -0
  119. {mt5api-0.0.2 → mt5api-0.0.4}/specs/043-mt5-dataframe-client/spec.md +0 -0
  120. {mt5api-0.0.2 → mt5api-0.0.4}/specs/044-mt5-trading-client/spec.md +0 -0
  121. {mt5api-0.0.2 → mt5api-0.0.4}/specs/045-mt5-utils/spec.md +0 -0
  122. {mt5api-0.0.2 → mt5api-0.0.4}/specs/046-mt5-api-service/spec.md +0 -0
  123. {mt5api-0.0.2 → mt5api-0.0.4}/specs/047-api-auth-rate-limit/spec.md +0 -0
  124. {mt5api-0.0.2 → mt5api-0.0.4}/specs/048-api-response-format/spec.md +0 -0
  125. {mt5api-0.0.2 → mt5api-0.0.4}/specs/049-api-routing-models/spec.md +0 -0
  126. {mt5api-0.0.2 → mt5api-0.0.4}/specs/050-api-runtime-deploy/spec.md +0 -0
  127. {mt5api-0.0.2 → mt5api-0.0.4}/specs/051-api-error-logging/spec.md +0 -0
  128. {mt5api-0.0.2 → mt5api-0.0.4}/specs/052-api-dependencies/spec.md +0 -0
  129. {mt5api-0.0.2 → mt5api-0.0.4}/tests/__init__.py +0 -0
  130. {mt5api-0.0.2 → mt5api-0.0.4}/tests/test_formatters.py +0 -0
@@ -0,0 +1,22 @@
1
+ ---
2
+ name: local-qa
3
+ description: Run local QA including formatting, linting, and testing for the repository. Use whenever any file has been updated.
4
+ disable-model-invocation: true
5
+ ---
6
+
7
+ # Local QA (format, lint, and test)
8
+
9
+ Run the local QA script `scripts/qa.sh` in this skill.
10
+
11
+ ## Procedure
12
+
13
+ - Execute the script exactly as shown above when this skill is triggered.
14
+ - Capture and summarize key output (success/failure, major warnings, and any files modified).
15
+ - If the script fails due to missing tooling (`command not found`, missing executable, or equivalent), install the missing tool(s) and rerun `./scripts/qa.sh`.
16
+ - Install tools using this order of preference:
17
+ 1. Use the project's package manager when applicable (`uv`/`poetry` for Python, package manager scripts/dependencies for Node.js).
18
+ 2. Use a system package manager (`brew` on macOS, `apt` on Debian/Ubuntu) when project-local install is not applicable.
19
+ 3. Use language-specific installers as fallback (`pipx`/`pip`, `npm`, `go install`, etc.).
20
+ - If multiple tools are missing, repeat install -> rerun until QA completes or you hit a blocker.
21
+ - If installation fails or requires unavailable privileges, report what was attempted, the exact failure, and stop.
22
+ - Do not run unrelated commands; only run commands needed for QA and missing-tool installation.
@@ -0,0 +1,325 @@
1
+ ---
2
+ name: mt5api
3
+ description: >-
4
+ Query the MT5 API for account info, terminal status, health checks, symbol
5
+ data, market data (OHLCV rates, ticks, market depth), open positions, pending
6
+ orders, and trade history. Use when the user wants to interact with any mt5api
7
+ endpoint.
8
+ allowed-tools: Bash
9
+ ---
10
+
11
+ # MT5 API
12
+
13
+ Query all mt5api endpoints: health, version, account, terminal, symbols, market
14
+ data, positions, orders, and trade history.
15
+
16
+ ## Configuration
17
+
18
+ The API base URL defaults to `http://localhost:8000`. Set `MT5API_URL` to
19
+ override. When the server is configured with `MT5API_SECRET_KEY`, send the same value
20
+ in the `X-API-Key` header. When server-side auth is disabled, omit the header
21
+ instead of sending an empty `X-API-Key`.
22
+
23
+ Use these shell helpers in examples:
24
+
25
+ ```bash
26
+ MT5API_URL="${MT5API_URL:-http://localhost:8000}"
27
+ AUTH_HEADER=()
28
+ if [ -n "${MT5API_SECRET_KEY:-}" ]; then
29
+ AUTH_HEADER=(-H "X-API-Key: ${MT5API_SECRET_KEY}")
30
+ fi
31
+ ```
32
+
33
+ ## Response Formats
34
+
35
+ All endpoints (except `/health`) return JSON by default. Request Parquet with
36
+ `format=parquet` or `Accept: application/parquet`.
37
+
38
+ ## Operational Notes
39
+
40
+ - Start `ticks/range` with a narrow window. Large ranges can be slow; use
41
+ `ticks/from` when the user only needs the latest `N` ticks.
42
+ - `/market-book/{symbol}` may return `503` when MT5 depth-of-market data is not
43
+ available for the symbol. Report the exact MT5 error and suggest another
44
+ symbol or skipping DOM data.
45
+ - Empty arrays from `/positions`, `/orders`, `/history/orders`, or
46
+ `/history/deals` are valid results.
47
+
48
+ ---
49
+
50
+ ## Health & Version
51
+
52
+ ### Health Check (public, no auth required)
53
+
54
+ ```bash
55
+ curl -s "${MT5API_URL}/health" | python -m json.tool
56
+ ```
57
+
58
+ Returns:
59
+
60
+ | Field | Type | Description |
61
+ | ------------- | ------- | ------------------------------ |
62
+ | status | string | `healthy` or `unhealthy` |
63
+ | mt5_connected | bool | MT5 terminal connection status |
64
+ | mt5_version | string? | MT5 terminal version string |
65
+ | api_version | string | API version (e.g., `1.0.0`) |
66
+
67
+ ### MT5 Version
68
+
69
+ ```bash
70
+ curl -s "${AUTH_HEADER[@]}" \
71
+ "${MT5API_URL}/version" | python -m json.tool
72
+ ```
73
+
74
+ | Parameter | Type | Required | Description |
75
+ | --------- | ------ | -------- | ------------------------ |
76
+ | format | string | no | Response format override |
77
+
78
+ ---
79
+
80
+ ## Account & Terminal
81
+
82
+ ### Account Info
83
+
84
+ Get current trading account details (balance, equity, margin, leverage, etc.).
85
+
86
+ ```bash
87
+ curl -s "${AUTH_HEADER[@]}" \
88
+ "${MT5API_URL}/account" | python -m json.tool
89
+ ```
90
+
91
+ Key fields: `login`, `balance`, `equity`, `margin`, `margin_free`,
92
+ `margin_level`, `leverage`, `currency`, `server`, `name`.
93
+
94
+ | Parameter | Type | Required | Description |
95
+ | --------- | ------ | -------- | ------------------------ |
96
+ | format | string | no | Response format override |
97
+
98
+ ### Terminal Info
99
+
100
+ ```bash
101
+ curl -s "${AUTH_HEADER[@]}" \
102
+ "${MT5API_URL}/terminal" | python -m json.tool
103
+ ```
104
+
105
+ | Parameter | Type | Required | Description |
106
+ | --------- | ------ | -------- | ------------------------ |
107
+ | format | string | no | Response format override |
108
+
109
+ ---
110
+
111
+ ## Symbols
112
+
113
+ ### List Symbols
114
+
115
+ ```bash
116
+ curl -s "${AUTH_HEADER[@]}" \
117
+ "${MT5API_URL}/symbols" | python -m json.tool
118
+ ```
119
+
120
+ | Parameter | Type | Required | Description |
121
+ | --------- | ------ | -------- | --------------------------------------------- |
122
+ | group | string | no | Symbol group filter (e.g., `*USD*`, `Forex*`) |
123
+ | format | string | no | Response format override |
124
+
125
+ ### Get Symbol Info
126
+
127
+ ```bash
128
+ curl -s "${AUTH_HEADER[@]}" \
129
+ "${MT5API_URL}/symbols/EURUSD" | python -m json.tool
130
+ ```
131
+
132
+ ### Get Latest Tick
133
+
134
+ ```bash
135
+ curl -s "${AUTH_HEADER[@]}" \
136
+ "${MT5API_URL}/symbols/EURUSD/tick" | python -m json.tool
137
+ ```
138
+
139
+ ---
140
+
141
+ ## Market Data
142
+
143
+ `timeframe` and `flags` accept either the official MetaTrader 5 constant name
144
+ (e.g., `TIMEFRAME_H1`, `COPY_TICKS_ALL`) or the equivalent integer value.
145
+
146
+ ### Rates from Date
147
+
148
+ ```bash
149
+ curl -s "${AUTH_HEADER[@]}" \
150
+ "${MT5API_URL}/rates/from?symbol=EURUSD&timeframe=TIMEFRAME_H1&date_from=2024-01-01T00:00:00Z&count=100" \
151
+ | python -m json.tool
152
+ ```
153
+
154
+ | Parameter | Type | Required | Description |
155
+ | --------- | -------- | -------- | -------------------------------------------- |
156
+ | symbol | string | yes | Symbol name |
157
+ | timeframe | int/str | yes | MT5 timeframe constant or equivalent integer |
158
+ | date_from | datetime | yes | Start date (ISO 8601) |
159
+ | count | int | yes | Number of candles (1–100000) |
160
+ | format | string | no | Response format override |
161
+
162
+ ### Rates from Position
163
+
164
+ ```bash
165
+ curl -s "${AUTH_HEADER[@]}" \
166
+ "${MT5API_URL}/rates/from-pos?symbol=EURUSD&timeframe=TIMEFRAME_H1&start_pos=0&count=100" \
167
+ | python -m json.tool
168
+ ```
169
+
170
+ | Parameter | Type | Required | Description |
171
+ | --------- | ------- | -------- | --------------------------------- |
172
+ | symbol | str | yes | Symbol name |
173
+ | timeframe | str/int | yes | MT5 timeframe constant or integer |
174
+ | start_pos | int | yes | Start position (0 = current bar) |
175
+ | count | int | yes | Number of candles (1–100000) |
176
+ | format | string | no | Response format override |
177
+
178
+ ### Rates in Range
179
+
180
+ ```bash
181
+ curl -s "${AUTH_HEADER[@]}" \
182
+ "${MT5API_URL}/rates/range?symbol=EURUSD&timeframe=TIMEFRAME_H1&date_from=2024-01-01T00:00:00Z&date_to=2024-01-31T23:59:59Z" \
183
+ | python -m json.tool
184
+ ```
185
+
186
+ | Parameter | Type | Required | Description |
187
+ | --------- | -------- | -------- | --------------------------------- |
188
+ | symbol | string | yes | Symbol name |
189
+ | timeframe | int/str | yes | MT5 timeframe constant or integer |
190
+ | date_from | datetime | yes | Start date (ISO 8601) |
191
+ | date_to | datetime | yes | End date (ISO 8601) |
192
+ | format | string | no | Response format override |
193
+
194
+ ### Ticks from Date
195
+
196
+ ```bash
197
+ curl -s "${AUTH_HEADER[@]}" \
198
+ "${MT5API_URL}/ticks/from?symbol=EURUSD&date_from=2024-01-02T10:00:00Z&count=500" \
199
+ | python -m json.tool
200
+ ```
201
+
202
+ | Parameter | Type | Required | Default | Description |
203
+ | --------- | -------- | -------- | -------------- | --------------------------------- |
204
+ | symbol | string | yes | | Symbol name |
205
+ | date_from | datetime | yes | | Start date (ISO 8601) |
206
+ | count | int | yes | | Number of ticks (1–100000) |
207
+ | flags | int/str | no | COPY_TICKS_ALL | MT5 tick flag constant or integer |
208
+ | format | string | no | | Response format override |
209
+
210
+ ### Ticks in Range
211
+
212
+ ```bash
213
+ curl -s "${AUTH_HEADER[@]}" \
214
+ "${MT5API_URL}/ticks/range?symbol=EURUSD&date_from=2024-01-02T10:00:00Z&date_to=2024-01-02T11:00:00Z" \
215
+ | python -m json.tool
216
+ ```
217
+
218
+ | Parameter | Type | Required | Default | Description |
219
+ | --------- | -------- | -------- | -------------- | --------------------------------- |
220
+ | symbol | string | yes | | Symbol name |
221
+ | date_from | datetime | yes | | Start date (ISO 8601) |
222
+ | date_to | datetime | yes | | End date (ISO 8601) |
223
+ | flags | int/str | no | COPY_TICKS_ALL | MT5 tick flag constant or integer |
224
+ | format | string | no | | Response format override |
225
+
226
+ ### Market Book (DOM)
227
+
228
+ ```bash
229
+ curl -s "${AUTH_HEADER[@]}" \
230
+ "${MT5API_URL}/market-book/EURUSD" | python -m json.tool
231
+ ```
232
+
233
+ If this returns `503`, explain that MT5 did not provide DOM data for the
234
+ requested symbol and include the server's error text.
235
+
236
+ ---
237
+
238
+ ## Positions, Orders & History
239
+
240
+ ### Open Positions
241
+
242
+ ```bash
243
+ curl -s "${AUTH_HEADER[@]}" \
244
+ "${MT5API_URL}/positions" | python -m json.tool
245
+ ```
246
+
247
+ | Parameter | Type | Required | Description |
248
+ | --------- | ------ | -------- | ------------------------- |
249
+ | symbol | string | no | Filter by symbol |
250
+ | group | string | no | Filter by group pattern |
251
+ | ticket | int | no | Filter by position ticket |
252
+ | format | string | no | Response format override |
253
+
254
+ ### Pending Orders
255
+
256
+ ```bash
257
+ curl -s "${AUTH_HEADER[@]}" \
258
+ "${MT5API_URL}/orders" | python -m json.tool
259
+ ```
260
+
261
+ | Parameter | Type | Required | Description |
262
+ | --------- | ------ | -------- | ------------------------ |
263
+ | symbol | string | no | Filter by symbol |
264
+ | group | string | no | Filter by group pattern |
265
+ | ticket | int | no | Filter by order ticket |
266
+ | format | string | no | Response format override |
267
+
268
+ ### Historical Orders
269
+
270
+ ```bash
271
+ curl -s "${AUTH_HEADER[@]}" \
272
+ "${MT5API_URL}/history/orders?date_from=2024-01-01T00:00:00Z&date_to=2024-01-31T23:59:59Z" \
273
+ | python -m json.tool
274
+ ```
275
+
276
+ | Parameter | Type | Required | Description |
277
+ | --------- | -------- | -------- | ------------------------------------------------- |
278
+ | date_from | datetime | cond. | Start date (required if no ticket/position) |
279
+ | date_to | datetime | cond. | End date (required if no ticket/position) |
280
+ | ticket | int | cond. | Filter by ticket (alternative to date range) |
281
+ | position | int | cond. | Filter by position ID (alternative to date range) |
282
+ | symbol | string | no | Filter by symbol |
283
+ | group | string | no | Filter by group pattern |
284
+ | format | string | no | Response format override |
285
+
286
+ Either `(date_from AND date_to)` or `(ticket OR position)` must be provided.
287
+
288
+ ### Historical Deals
289
+
290
+ ```bash
291
+ curl -s "${AUTH_HEADER[@]}" \
292
+ "${MT5API_URL}/history/deals?date_from=2024-01-01T00:00:00Z&date_to=2024-01-31T23:59:59Z" \
293
+ | python -m json.tool
294
+ ```
295
+
296
+ | Parameter | Type | Required | Description |
297
+ | --------- | -------- | -------- | ------------------------------------------------- |
298
+ | date_from | datetime | cond. | Start date (required if no ticket/position) |
299
+ | date_to | datetime | cond. | End date (required if no ticket/position) |
300
+ | ticket | int | cond. | Filter by ticket (alternative to date range) |
301
+ | position | int | cond. | Filter by position ID (alternative to date range) |
302
+ | symbol | string | no | Filter by symbol |
303
+ | group | string | no | Filter by group pattern |
304
+ | format | string | no | Response format override |
305
+
306
+ Either `(date_from AND date_to)` or `(ticket OR position)` must be provided.
307
+
308
+ ---
309
+
310
+ ## Procedure
311
+
312
+ 1. Identify which endpoint(s) the user needs from the sections above.
313
+ 2. Gather required parameters (symbol, timeframe, dates, count, filters).
314
+ 3. Decide whether the caller needs JSON or Parquet output.
315
+ 4. Build `AUTH_HEADER` only when `MT5API_SECRET_KEY` is set, then construct and run
316
+ the appropriate `curl` command(s).
317
+ 5. For `ticks/range`, start with a narrow interval and widen only if needed.
318
+ 6. Parse the JSON response and summarize the results, or note when the API
319
+ returned Parquet data.
320
+ 7. If `/market-book/{symbol}` returns `503`, explain that MT5 did not provide
321
+ DOM data for that symbol and include the error text.
322
+ 8. If the health status is `unhealthy`, note that the MT5 terminal may not be
323
+ running or reachable.
324
+ 9. For historical queries, remind the user that either a date range or a
325
+ ticket/position filter is required.
mt5api-0.0.4/AGENTS.md ADDED
@@ -0,0 +1,90 @@
1
+ # Repository Guidelines
2
+
3
+ ## Commands
4
+
5
+ ### Development Setup
6
+
7
+ - `uv sync --dev` installs runtime and development dependencies.
8
+ - `uv run uvicorn mt5api.main:app --host 0.0.0.0 --port 8000` starts the API locally.
9
+ - `uv run python -m mt5api` starts the app using `MT5API_HOST`, `MT5API_PORT`, and `MT5API_LOG_LEVEL`.
10
+ - `uv run mkdocs serve` previews the documentation site.
11
+
12
+ ### Code Quality and Documentation
13
+
14
+ **Important**: Run these before committing or creating a PR.
15
+
16
+ 1. **Format, lint, and test**: Use `local-qa` skill.
17
+ 2. **Documentation build**: Run `uv run mkdocs build` when documentation, configuration, or OpenAPI-visible behavior changes.
18
+
19
+ ## Architecture
20
+
21
+ ### Runtime Constraints
22
+
23
+ - The API server must run on Windows with a logged-in MetaTrader 5 terminal.
24
+ - Linux and macOS are for HTTP clients, documentation work, and local non-runtime development only.
25
+
26
+ ### Key Dependencies
27
+
28
+ - `pdmt5`: Underlying MetaTrader 5 client integration used by the API layer.
29
+ - `fastapi`: HTTP application framework and OpenAPI generation.
30
+
31
+ ### Package Structure
32
+
33
+ - `mt5api/`: Main FastAPI package.
34
+ - `main.py`: App wiring, lifespan handling, middleware, CORS, and router registration.
35
+ - `__main__.py`: CLI entry point for launching the API from environment-backed configuration.
36
+ - `config.py`: Environment-backed configuration normalization and validation.
37
+ - `auth.py`: Optional API key authentication helpers.
38
+ - `dependencies.py`: Shared endpoint dependencies and MT5 accessors.
39
+ - `formatters.py`: JSON and Parquet response formatting helpers.
40
+ - `models.py`: Pydantic API models.
41
+ - `middleware.py`: Request logging and error handling.
42
+ - `constants.py`: Shared constants and environment variable names.
43
+ - `routers/`: Endpoint groups for operations: `health.py`, `symbols.py`, `market.py`, `account.py`, `history.py`, `calc.py`, and `trading.py`.
44
+ - `tests/`: Pytest suite covering API behavior, configuration, middleware, and CLI entry points.
45
+ - `docs/`: MkDocs documentation, including REST API and deployment guidance.
46
+
47
+ ## Quality Standards
48
+
49
+ - Type hints required (pyright strict mode)
50
+ - Comprehensive linting with 35+ rule categories (ruff)
51
+ - Test coverage tracking with 100% (pytest-cov)
52
+ - Parametrized tests for input/result matrices using `pytest.mark.parametrize` (pytest)
53
+
54
+ ## Documentation Workflow
55
+
56
+ 1. Update docstrings and docs when behavior, configuration, or OpenAPI-visible output changes.
57
+ 2. Local preview: `uv run mkdocs serve`
58
+ 3. Build validation: `uv run mkdocs build`
59
+
60
+ ## Commit & Pull Request Guidelines
61
+
62
+ - Run QA using `local-qa` skill before committing or creating a PR.
63
+ - Branch names use appropriate prefixes on creation (e.g., `feature/...`, `bugfix/...`, `refactor/...`, `docs/...`, `chore/...`).
64
+ - When instructed to create a PR, create it as a draft with appropriate labels by default.
65
+
66
+ ## Security & Configuration Tips
67
+
68
+ - Do not commit real MT5 credentials or API keys.
69
+ - Configure `MT5API_SECRET_KEY`, `MT5API_RATE_LIMIT`, `MT5API_CORS_ORIGINS`, `MT5API_ROUTER_PREFIX`, and `MT5API_LOG_LEVEL` through environment variables.
70
+ - Keep runtime configuration in the environment instead of hardcoding deployment values.
71
+ - Authentication mode is fixed at process startup; cover both authenticated and unauthenticated behavior when changing auth-related code.
72
+
73
+ ## Code Design Principles
74
+
75
+ Always prefer the simplest design that works.
76
+
77
+ - **KISS**: Choose straightforward solutions and avoid unnecessary abstraction.
78
+ - **DRY**: Remove duplication when it improves clarity and maintainability.
79
+ - **YAGNI**: Do not add features, hooks, or flexibility until they are needed.
80
+ - **SOLID/Clean Code**: Apply these as tools only when they keep the design simpler and easier to change.
81
+
82
+ ## Development Methodology
83
+
84
+ Keep delivery incremental, test-backed, and easy to review.
85
+
86
+ - Make small, safe, reversible changes.
87
+ - Prefer `Red -> Green -> Refactor`.
88
+ - Do not mix feature work and refactoring in the same commit.
89
+ - Refactor when it improves clarity or removes real duplication (Rule of Three).
90
+ - Keep tests fast, focused, and self-validating.
mt5api-0.0.4/PKG-INFO ADDED
@@ -0,0 +1,171 @@
1
+ Metadata-Version: 2.4
2
+ Name: mt5api
3
+ Version: 0.0.4
4
+ Summary: MetaTrader 5 REST API
5
+ Project-URL: Repository, https://github.com/dceoy/mt5api.git
6
+ Author-email: dceoy <dceoy@users.noreply.github.com>
7
+ Maintainer-email: dceoy <dceoy@users.noreply.github.com>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Financial and Insurance Industry
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Operating System :: Microsoft :: Windows
15
+ Classifier: Programming Language :: Python
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Topic :: Office/Business :: Financial :: Investment
18
+ Requires-Python: <3.14,>=3.11
19
+ Requires-Dist: fastapi>=0.115.0
20
+ Requires-Dist: httpx>=0.27.0
21
+ Requires-Dist: metatrader5>=5.0.4424; sys_platform == 'win32'
22
+ Requires-Dist: passlib[bcrypt]>=1.7.4
23
+ Requires-Dist: pdmt5>=0.2.1
24
+ Requires-Dist: pyarrow>=18.0.0
25
+ Requires-Dist: python-jose[cryptography]>=3.3.0
26
+ Requires-Dist: python-multipart>=0.0.9
27
+ Requires-Dist: slowapi>=0.1.9
28
+ Requires-Dist: uvicorn[standard]>=0.32.0
29
+ Description-Content-Type: text/markdown
30
+
31
+ # mt5api
32
+
33
+ MetaTrader 5 REST API
34
+
35
+ [![CI/CD](https://github.com/dceoy/mt5api/actions/workflows/ci.yml/badge.svg)](https://github.com/dceoy/mt5api/actions/workflows/ci.yml)
36
+
37
+ mt5api exposes MT5 market data, account info, trading history, and trading
38
+ operations over HTTP. It uses the [`pdmt5`](https://github.com/dceoy/pdmt5)
39
+ client internally and adds optional API-key auth, rate limiting, and
40
+ JSON/Parquet response formatting.
41
+
42
+ The API server must run on Windows. The `MetaTrader5` Python package used by
43
+ `pdmt5` is supported only on Windows, so you must host `mt5api` on a Windows
44
+ machine with a logged-in MetaTrader 5 terminal. HTTP clients can connect from
45
+ any operating system.
46
+
47
+ ## Architecture
48
+
49
+ ```mermaid
50
+ graph TB
51
+ Client["HTTP Client<br/>(Any OS)"]
52
+
53
+ subgraph "Windows Host"
54
+ subgraph "FastAPI Application"
55
+ Middleware["Middleware Stack<br/>CORS · Logging · Error Handler · Rate Limiter"]
56
+ Routers["Routers<br/>health · symbols · market · account · history · calc · trading"]
57
+ Auth["API Key Security Dependency<br/>Security(api_key_header) · verify_api_key"]
58
+ Deps["FastAPI Dependencies<br/>MT5 Client Singleton · Format Negotiation"]
59
+ Formatters["Response Formatters<br/>JSON · Parquet"]
60
+ Middleware --> Routers --> Deps --> Formatters
61
+ Auth -.-> Routers
62
+ Formatters --> Middleware
63
+ end
64
+
65
+ Deps --> pdmt5["pdmt5<br/>MT5 Client Library"]
66
+ pdmt5 --> MT5["MetaTrader 5<br/>Terminal"]
67
+ end
68
+
69
+ Client -- "HTTP/REST" --> Middleware
70
+ Middleware -- "JSON / Parquet" --> Client
71
+ ```
72
+
73
+ ## Features
74
+
75
+ - REST endpoints for symbols, market data, account info, orders, history,
76
+ calculations, and trading operations
77
+ - JSON and Apache Parquet responses (content negotiation)
78
+ - Optional API key authentication with per-minute rate limiting
79
+ - Structured JSON logging and configurable CORS
80
+ - OpenAPI/Swagger docs built into the API
81
+
82
+ ## Requirements
83
+
84
+ - Python 3.11+
85
+ - Windows host with MetaTrader 5 terminal installed and logged in
86
+ - Linux and macOS are not supported for the API server runtime, but they work
87
+ for HTTP clients
88
+
89
+ ## Installation
90
+
91
+ Install and run the API on the Windows machine where MetaTrader 5 is installed.
92
+
93
+ ```powershell
94
+ git clone https://github.com/dceoy/mt5api.git
95
+ cd mt5api
96
+ uv sync
97
+ ```
98
+
99
+ ## Running the API on Windows
100
+
101
+ ```powershell
102
+ $env:MT5API_SECRET_KEY = "your-secret-api-key" # Optional: omit to disable auth
103
+ $env:MT5API_ROUTER_PREFIX = "/api/v1" # Optional: omit for root-level routes
104
+ uv run uvicorn mt5api.main:app --host 0.0.0.0 --port 8000
105
+ ```
106
+
107
+ Docs:
108
+
109
+ - Swagger UI: `http://localhost:8000/docs`
110
+ - OpenAPI JSON: `http://localhost:8000/openapi.json`
111
+
112
+ Set `MT5API_ROUTER_PREFIX` to mount the API endpoints under a shared path such
113
+ as `/api/v1`. The default is `""`, which keeps routes like `/health` and
114
+ `/symbols` at the root. `"/api/v1"`, `"api/v1"`, and `"/api/v1/"` are treated
115
+ the same.
116
+
117
+ Set `MT5API_MAX_MARKET_BOOK_SUBSCRIPTIONS` to cap active market-book
118
+ subscriptions. The default limit is `100`.
119
+
120
+ ## Example Requests with curl
121
+
122
+ Replace `windows-host` with the DNS name or IP address of the Windows machine
123
+ running `mt5api`. If you run the request on that Windows host, `localhost` also
124
+ works. In PowerShell, use `curl.exe` if `curl` resolves to
125
+ `Invoke-WebRequest`.
126
+
127
+ ```console
128
+ curl "http://windows-host:8000/health"
129
+ ```
130
+
131
+ ```console
132
+ # Include X-API-Key only when MT5API_SECRET_KEY is configured on the server.
133
+ curl -H "X-API-Key: your-secret-api-key" "http://windows-host:8000/symbols?group=*USD*"
134
+ ```
135
+
136
+ ```console
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"
138
+ ```
139
+
140
+ Market-data and calculation endpoints accept MetaTrader 5 constants either by
141
+ official name (`TIMEFRAME_M1`, `COPY_TICKS_ALL`, `ORDER_TYPE_BUY`) or by their
142
+ integer value.
143
+
144
+ ## Endpoints
145
+
146
+ If `MT5API_ROUTER_PREFIX` is set, prepend that value to every API route below.
147
+
148
+ ### Read-Only Endpoints
149
+
150
+ - Health: `GET /health`, `GET /version`, `GET /last-error`
151
+ - Symbols: `GET /symbols`, `GET /symbols/total`, `GET /symbols/{symbol}`,
152
+ `GET /symbols/{symbol}/tick`
153
+ - Market data: `GET /rates/from`, `GET /rates/from-pos`, `GET /rates/range`,
154
+ `GET /ticks/from`, `GET /ticks/range`, `GET /market-book/{symbol}`
155
+ - Calculations: `GET /calc/margin`, `GET /calc/profit`
156
+ - Account: `GET /account`, `GET /terminal`
157
+ - Trading state: `GET /positions`, `GET /positions/total`,
158
+ `GET /orders`, `GET /orders/total`
159
+ - History: `GET /history/orders`, `GET /history/orders/total`,
160
+ `GET /history/deals`, `GET /history/deals/total`
161
+
162
+ ### Operational Endpoints
163
+
164
+ - `POST /symbols/{symbol}/select` — Show or hide symbol in MarketWatch
165
+ - `POST /market-book/{symbol}/subscribe` — Subscribe to DOM events
166
+ - `POST /market-book/{symbol}/unsubscribe` — Unsubscribe from DOM events
167
+ - `POST /order/check` — Validate a trade request without execution
168
+
169
+ ## License
170
+
171
+ MIT License - see [LICENSE](https://github.com/dceoy/mt5api/blob/main/LICENSE).