mt5api 0.0.1__tar.gz → 0.0.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. mt5api-0.0.3/.agents/skills/local-qa/SKILL.md +22 -0
  2. mt5api-0.0.3/.agents/skills/mt5api/SKILL.md +325 -0
  3. {mt5api-0.0.1 → mt5api-0.0.3}/AGENTS.md +1 -1
  4. {mt5api-0.0.1 → mt5api-0.0.3}/PKG-INFO +38 -21
  5. mt5api-0.0.3/README.md +96 -0
  6. {mt5api-0.0.1 → mt5api-0.0.3}/docs/api/deployment.md +7 -4
  7. mt5api-0.0.3/docs/api/index.md +57 -0
  8. mt5api-0.0.3/docs/api/rest-api.md +212 -0
  9. {mt5api-0.0.1 → mt5api-0.0.3}/docs/index.md +17 -13
  10. {mt5api-0.0.1 → mt5api-0.0.3}/mkdocs.yml +0 -4
  11. {mt5api-0.0.1 → mt5api-0.0.3}/mt5api/__main__.py +18 -13
  12. {mt5api-0.0.1 → mt5api-0.0.3}/mt5api/auth.py +10 -7
  13. mt5api-0.0.3/mt5api/config.py +114 -0
  14. mt5api-0.0.3/mt5api/constants.py +31 -0
  15. {mt5api-0.0.1 → mt5api-0.0.3}/mt5api/main.py +32 -21
  16. {mt5api-0.0.1 → mt5api-0.0.3}/mt5api/middleware.py +4 -3
  17. {mt5api-0.0.1 → mt5api-0.0.3}/mt5api/models.py +223 -51
  18. {mt5api-0.0.1 → mt5api-0.0.3}/mt5api/routers/account.py +0 -1
  19. {mt5api-0.0.1 → mt5api-0.0.3}/mt5api/routers/health.py +2 -3
  20. {mt5api-0.0.1 → mt5api-0.0.3}/mt5api/routers/history.py +0 -1
  21. {mt5api-0.0.1 → mt5api-0.0.3}/mt5api/routers/market.py +0 -1
  22. {mt5api-0.0.1 → mt5api-0.0.3}/mt5api/routers/symbols.py +0 -1
  23. {mt5api-0.0.1 → mt5api-0.0.3}/pyproject.toml +2 -2
  24. {mt5api-0.0.1 → mt5api-0.0.3}/specs/041-mt5-rest-api/contracts/openapi.yaml +20 -20
  25. {mt5api-0.0.1 → mt5api-0.0.3}/specs/041-mt5-rest-api/data-model.md +5 -5
  26. {mt5api-0.0.1 → mt5api-0.0.3}/specs/041-mt5-rest-api/plan.md +13 -13
  27. {mt5api-0.0.1 → mt5api-0.0.3}/specs/041-mt5-rest-api/quickstart.md +37 -37
  28. {mt5api-0.0.1 → mt5api-0.0.3}/specs/041-mt5-rest-api/research.md +13 -13
  29. {mt5api-0.0.1 → mt5api-0.0.3}/specs/041-mt5-rest-api/tasks.md +16 -16
  30. {mt5api-0.0.1 → mt5api-0.0.3}/tests/conftest.py +22 -32
  31. mt5api-0.0.3/tests/mt5_constants.py +67 -0
  32. {mt5api-0.0.1 → mt5api-0.0.3}/tests/test_account.py +8 -8
  33. {mt5api-0.0.1 → mt5api-0.0.3}/tests/test_auth.py +60 -6
  34. {mt5api-0.0.1 → mt5api-0.0.3}/tests/test_cli.py +19 -13
  35. mt5api-0.0.3/tests/test_config.py +120 -0
  36. {mt5api-0.0.1 → mt5api-0.0.3}/tests/test_dependencies.py +2 -2
  37. {mt5api-0.0.1 → mt5api-0.0.3}/tests/test_health.py +7 -5
  38. {mt5api-0.0.1 → mt5api-0.0.3}/tests/test_history.py +16 -16
  39. {mt5api-0.0.1 → mt5api-0.0.3}/tests/test_integration.py +9 -9
  40. {mt5api-0.0.1 → mt5api-0.0.3}/tests/test_lifespan.py +1 -1
  41. {mt5api-0.0.1 → mt5api-0.0.3}/tests/test_main.py +9 -5
  42. {mt5api-0.0.1 → mt5api-0.0.3}/tests/test_market.py +151 -52
  43. {mt5api-0.0.1 → mt5api-0.0.3}/tests/test_middleware.py +4 -3
  44. mt5api-0.0.3/tests/test_models.py +113 -0
  45. {mt5api-0.0.1 → mt5api-0.0.3}/tests/test_symbols.py +14 -14
  46. {mt5api-0.0.1 → mt5api-0.0.3}/uv.lock +1 -1
  47. mt5api-0.0.1/.agents/skills/local-qa/SKILL.md +0 -19
  48. mt5api-0.0.1/.agents/skills/mt5-account/SKILL.md +0 -55
  49. mt5api-0.0.1/.agents/skills/mt5-health/SKILL.md +0 -47
  50. mt5api-0.0.1/.agents/skills/mt5-history/SKILL.md +0 -111
  51. mt5api-0.0.1/.agents/skills/mt5-market/SKILL.md +0 -122
  52. mt5api-0.0.1/.agents/skills/mt5-symbols/SKILL.md +0 -69
  53. mt5api-0.0.1/README.md +0 -79
  54. mt5api-0.0.1/docs/api/dataframe.md +0 -165
  55. mt5api-0.0.1/docs/api/index.md +0 -74
  56. mt5api-0.0.1/docs/api/mt5.md +0 -324
  57. mt5api-0.0.1/docs/api/rest-api.md +0 -206
  58. mt5api-0.0.1/docs/api/trading.md +0 -399
  59. mt5api-0.0.1/docs/api/utils.md +0 -117
  60. mt5api-0.0.1/tests/test_config.py +0 -34
  61. mt5api-0.0.1/tests/test_models.py +0 -24
  62. {mt5api-0.0.1 → mt5api-0.0.3}/.agents/skills/local-qa/scripts/qa.sh +0 -0
  63. {mt5api-0.0.1 → mt5api-0.0.3}/.agents/skills/speckit-analyze/SKILL.md +0 -0
  64. {mt5api-0.0.1 → mt5api-0.0.3}/.agents/skills/speckit-checklist/SKILL.md +0 -0
  65. {mt5api-0.0.1 → mt5api-0.0.3}/.agents/skills/speckit-clarify/SKILL.md +0 -0
  66. {mt5api-0.0.1 → mt5api-0.0.3}/.agents/skills/speckit-constitution/SKILL.md +0 -0
  67. {mt5api-0.0.1 → mt5api-0.0.3}/.agents/skills/speckit-implement/SKILL.md +0 -0
  68. {mt5api-0.0.1 → mt5api-0.0.3}/.agents/skills/speckit-plan/SKILL.md +0 -0
  69. {mt5api-0.0.1 → mt5api-0.0.3}/.agents/skills/speckit-specify/SKILL.md +0 -0
  70. {mt5api-0.0.1 → mt5api-0.0.3}/.agents/skills/speckit-tasks/SKILL.md +0 -0
  71. {mt5api-0.0.1 → mt5api-0.0.3}/.agents/skills/speckit-taskstoissues/SKILL.md +0 -0
  72. {mt5api-0.0.1 → mt5api-0.0.3}/.claude/agents/codex.md +0 -0
  73. {mt5api-0.0.1 → mt5api-0.0.3}/.claude/agents/copilot.md +0 -0
  74. {mt5api-0.0.1 → mt5api-0.0.3}/.claude/commands/speckit.analyze.md +0 -0
  75. {mt5api-0.0.1 → mt5api-0.0.3}/.claude/commands/speckit.checklist.md +0 -0
  76. {mt5api-0.0.1 → mt5api-0.0.3}/.claude/commands/speckit.clarify.md +0 -0
  77. {mt5api-0.0.1 → mt5api-0.0.3}/.claude/commands/speckit.constitution.md +0 -0
  78. {mt5api-0.0.1 → mt5api-0.0.3}/.claude/commands/speckit.implement.md +0 -0
  79. {mt5api-0.0.1 → mt5api-0.0.3}/.claude/commands/speckit.plan.md +0 -0
  80. {mt5api-0.0.1 → mt5api-0.0.3}/.claude/commands/speckit.specify.md +0 -0
  81. {mt5api-0.0.1 → mt5api-0.0.3}/.claude/commands/speckit.tasks.md +0 -0
  82. {mt5api-0.0.1 → mt5api-0.0.3}/.claude/commands/speckit.taskstoissues.md +0 -0
  83. {mt5api-0.0.1 → mt5api-0.0.3}/.claude/settings.json +0 -0
  84. {mt5api-0.0.1 → mt5api-0.0.3}/.github/FUNDING.yml +0 -0
  85. {mt5api-0.0.1 → mt5api-0.0.3}/.github/dependabot.yml +0 -0
  86. {mt5api-0.0.1 → mt5api-0.0.3}/.github/renovate.json +0 -0
  87. {mt5api-0.0.1 → mt5api-0.0.3}/.github/workflows/ci.yml +0 -0
  88. {mt5api-0.0.1 → mt5api-0.0.3}/.github/workflows/claude-code.yml +0 -0
  89. {mt5api-0.0.1 → mt5api-0.0.3}/.gitignore +0 -0
  90. {mt5api-0.0.1 → mt5api-0.0.3}/.specify/memory/constitution.md +0 -0
  91. {mt5api-0.0.1 → mt5api-0.0.3}/.specify/scripts/bash/check-prerequisites.sh +0 -0
  92. {mt5api-0.0.1 → mt5api-0.0.3}/.specify/scripts/bash/common.sh +0 -0
  93. {mt5api-0.0.1 → mt5api-0.0.3}/.specify/scripts/bash/create-new-feature.sh +0 -0
  94. {mt5api-0.0.1 → mt5api-0.0.3}/.specify/scripts/bash/setup-plan.sh +0 -0
  95. {mt5api-0.0.1 → mt5api-0.0.3}/.specify/scripts/bash/update-agent-context.sh +0 -0
  96. {mt5api-0.0.1 → mt5api-0.0.3}/.specify/templates/agent-file-template.md +0 -0
  97. {mt5api-0.0.1 → mt5api-0.0.3}/.specify/templates/checklist-template.md +0 -0
  98. {mt5api-0.0.1 → mt5api-0.0.3}/.specify/templates/plan-template.md +0 -0
  99. {mt5api-0.0.1 → mt5api-0.0.3}/.specify/templates/spec-template.md +0 -0
  100. {mt5api-0.0.1 → mt5api-0.0.3}/.specify/templates/tasks-template.md +0 -0
  101. {mt5api-0.0.1 → mt5api-0.0.3}/CLAUDE.md +0 -0
  102. {mt5api-0.0.1 → mt5api-0.0.3}/LICENSE +0 -0
  103. {mt5api-0.0.1 → mt5api-0.0.3}/mt5api/__init__.py +0 -0
  104. {mt5api-0.0.1 → mt5api-0.0.3}/mt5api/dependencies.py +0 -0
  105. {mt5api-0.0.1 → mt5api-0.0.3}/mt5api/formatters.py +0 -0
  106. {mt5api-0.0.1 → mt5api-0.0.3}/mt5api/routers/__init__.py +0 -0
  107. {mt5api-0.0.1 → mt5api-0.0.3}/specs/041-mt5-rest-api/spec.md +0 -0
  108. {mt5api-0.0.1 → mt5api-0.0.3}/specs/042-mt5-core-client/spec.md +0 -0
  109. {mt5api-0.0.1 → mt5api-0.0.3}/specs/043-mt5-dataframe-client/spec.md +0 -0
  110. {mt5api-0.0.1 → mt5api-0.0.3}/specs/044-mt5-trading-client/spec.md +0 -0
  111. {mt5api-0.0.1 → mt5api-0.0.3}/specs/045-mt5-utils/spec.md +0 -0
  112. {mt5api-0.0.1 → mt5api-0.0.3}/specs/046-mt5-api-service/spec.md +0 -0
  113. {mt5api-0.0.1 → mt5api-0.0.3}/specs/047-api-auth-rate-limit/spec.md +0 -0
  114. {mt5api-0.0.1 → mt5api-0.0.3}/specs/048-api-response-format/spec.md +0 -0
  115. {mt5api-0.0.1 → mt5api-0.0.3}/specs/049-api-routing-models/spec.md +0 -0
  116. {mt5api-0.0.1 → mt5api-0.0.3}/specs/050-api-runtime-deploy/spec.md +0 -0
  117. {mt5api-0.0.1 → mt5api-0.0.3}/specs/051-api-error-logging/spec.md +0 -0
  118. {mt5api-0.0.1 → mt5api-0.0.3}/specs/052-api-dependencies/spec.md +0 -0
  119. {mt5api-0.0.1 → mt5api-0.0.3}/tests/__init__.py +0 -0
  120. {mt5api-0.0.1 → mt5api-0.0.3}/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.
@@ -41,7 +41,7 @@ Use `uv` for local work:
41
41
  ## Security & Configuration Tips
42
42
 
43
43
  - Do not commit real MT5 credentials or API keys.
44
- - Configure `MT5_API_KEY`, `API_RATE_LIMIT`, `API_CORS_ORIGINS`, and `API_LOG_LEVEL` through environment variables.
44
+ - Configure `MT5API_SECRET_KEY`, `API_RATE_LIMIT`, `API_CORS_ORIGINS`, and `API_LOG_LEVEL` through environment variables.
45
45
  - The API server must run on Windows with a logged-in MetaTrader 5 terminal.
46
46
  - Linux and macOS are for HTTP clients and local non-runtime work only.
47
47
 
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mt5api
3
- Version: 0.0.1
4
- Summary: MetaTrader 5 REST API using FastAPI
3
+ Version: 0.0.3
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>
7
7
  Maintainer-email: dceoy <dceoy@users.noreply.github.com>
@@ -30,7 +30,7 @@ Description-Content-Type: text/markdown
30
30
 
31
31
  # mt5api
32
32
 
33
- MetaTrader 5 REST API using FastAPI
33
+ MetaTrader 5 REST API
34
34
 
35
35
  [![CI/CD](https://github.com/dceoy/mt5api/actions/workflows/ci.yml/badge.svg)](https://github.com/dceoy/mt5api/actions/workflows/ci.yml)
36
36
 
@@ -55,7 +55,8 @@ any operating system.
55
55
 
56
56
  - Python 3.11+
57
57
  - Windows host with MetaTrader 5 terminal installed and logged in
58
- - Linux and macOS are not supported for the API server runtime
58
+ - Linux and macOS are not supported for the API server runtime, but they work
59
+ for HTTP clients
59
60
 
60
61
  ## Installation
61
62
 
@@ -67,10 +68,11 @@ cd mt5api
67
68
  uv sync
68
69
  ```
69
70
 
70
- ## Running the API
71
+ ## Running the API on Windows
71
72
 
72
73
  ```powershell
73
- $env:MT5_API_KEY = "your-secret-api-key" # Optional: omit to disable auth
74
+ $env:MT5API_SECRET_KEY = "your-secret-api-key" # Optional: omit to disable auth
75
+ $env:API_ROUTER_PREFIX = "/api/v1" # Optional: omit for root-level routes
74
76
  uv run uvicorn mt5api.main:app --host 0.0.0.0 --port 8000
75
77
  ```
76
78
 
@@ -79,30 +81,45 @@ Docs:
79
81
  - Swagger UI: `http://localhost:8000/docs`
80
82
  - OpenAPI JSON: `http://localhost:8000/openapi.json`
81
83
 
82
- ## Example Requests
84
+ Set `API_ROUTER_PREFIX` to mount the read-only API endpoints under a shared path
85
+ such as `/api/v1`. The default is `""`, which keeps routes like `/health` and
86
+ `/symbols` at the root. `"/api/v1"`, `"api/v1"`, and `"/api/v1/"` are treated
87
+ the same.
83
88
 
84
- ```powershell
85
- curl.exe http://localhost:8000/api/v1/health
89
+ ## Example Requests with curl
90
+
91
+ Replace `windows-host` with the DNS name or IP address of the Windows machine
92
+ running `mt5api`. If you run the request on that Windows host, `localhost` also
93
+ works. In PowerShell, use `curl.exe` if `curl` resolves to
94
+ `Invoke-WebRequest`.
95
+
96
+ ```console
97
+ curl "http://windows-host:8000/health"
86
98
  ```
87
99
 
88
- ```powershell
89
- # Include X-API-Key only when MT5_API_KEY is configured on the server.
90
- curl.exe -H "X-API-Key: your-secret-api-key" "http://localhost:8000/api/v1/symbols?group=*USD*"
100
+ ```console
101
+ # Include X-API-Key only when MT5API_SECRET_KEY is configured on the server.
102
+ curl -H "X-API-Key: your-secret-api-key" "http://windows-host:8000/symbols?group=*USD*"
91
103
  ```
92
104
 
93
- ```powershell
94
- curl.exe -H "X-API-Key: your-secret-api-key" -H "Accept: application/parquet" "http://localhost:8000/api/v1/rates/from?symbol=EURUSD&timeframe=1&date_from=2024-01-01T00:00:00Z&count=100"
105
+ ```console
106
+ 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"
95
107
  ```
96
108
 
109
+ Market-data endpoints accept MetaTrader 5 constants either by official name
110
+ (`TIMEFRAME_M1`, `COPY_TICKS_ALL`) or by their integer value.
111
+
97
112
  ## Endpoints (Read-Only)
98
113
 
99
- - Health: `/api/v1/health`, `/api/v1/version`
100
- - Symbols: `/api/v1/symbols`, `/api/v1/symbols/{symbol}`, `/api/v1/symbols/{symbol}/tick`
101
- - Market data: `/api/v1/rates/from`, `/api/v1/rates/from-pos`, `/api/v1/rates/range`,
102
- `/api/v1/ticks/from`, `/api/v1/ticks/range`, `/api/v1/market-book/{symbol}`
103
- - Account: `/api/v1/account`, `/api/v1/terminal`
104
- - Trading state: `/api/v1/positions`, `/api/v1/orders`
105
- - History: `/api/v1/history/orders`, `/api/v1/history/deals`
114
+ - Health: `/health`, `/version`
115
+ - Symbols: `/symbols`, `/symbols/{symbol}`, `/symbols/{symbol}/tick`
116
+ - Market data: `/rates/from`, `/rates/from-pos`, `/rates/range`,
117
+ `/ticks/from`, `/ticks/range`, `/market-book/{symbol}`
118
+ - Account: `/account`, `/terminal`
119
+ - Trading state: `/positions`, `/orders`
120
+ - History: `/history/orders`, `/history/deals`
121
+
122
+ If `API_ROUTER_PREFIX` is set, prepend that value to every API route above.
106
123
 
107
124
  ## License
108
125
 
mt5api-0.0.3/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # mt5api
2
+
3
+ MetaTrader 5 REST API
4
+
5
+ [![CI/CD](https://github.com/dceoy/mt5api/actions/workflows/ci.yml/badge.svg)](https://github.com/dceoy/mt5api/actions/workflows/ci.yml)
6
+
7
+ mt5api exposes read-only MT5 market data, account info, and trading history
8
+ over HTTP. It uses the `pdmt5` client internally and adds optional API-key
9
+ auth, rate limiting, and JSON/Parquet response formatting.
10
+
11
+ The API server must run on Windows. The `MetaTrader5` Python package used by
12
+ `pdmt5` is supported only on Windows, so you must host `mt5api` on a Windows
13
+ machine with a logged-in MetaTrader 5 terminal. HTTP clients can connect from
14
+ any operating system.
15
+
16
+ ## Features
17
+
18
+ - Read-only REST endpoints for symbols, market data, account info, orders, and history
19
+ - JSON and Apache Parquet responses (content negotiation)
20
+ - Optional API key authentication with per-minute rate limiting
21
+ - Structured JSON logging and configurable CORS
22
+ - OpenAPI/Swagger docs built into the API
23
+
24
+ ## Requirements
25
+
26
+ - Python 3.11+
27
+ - Windows host with MetaTrader 5 terminal installed and logged in
28
+ - Linux and macOS are not supported for the API server runtime, but they work
29
+ for HTTP clients
30
+
31
+ ## Installation
32
+
33
+ Install and run the API on the Windows machine where MetaTrader 5 is installed.
34
+
35
+ ```powershell
36
+ git clone https://github.com/dceoy/mt5api.git
37
+ cd mt5api
38
+ uv sync
39
+ ```
40
+
41
+ ## Running the API on Windows
42
+
43
+ ```powershell
44
+ $env:MT5API_SECRET_KEY = "your-secret-api-key" # Optional: omit to disable auth
45
+ $env:API_ROUTER_PREFIX = "/api/v1" # Optional: omit for root-level routes
46
+ uv run uvicorn mt5api.main:app --host 0.0.0.0 --port 8000
47
+ ```
48
+
49
+ Docs:
50
+
51
+ - Swagger UI: `http://localhost:8000/docs`
52
+ - OpenAPI JSON: `http://localhost:8000/openapi.json`
53
+
54
+ Set `API_ROUTER_PREFIX` to mount the read-only API endpoints under a shared path
55
+ such as `/api/v1`. The default is `""`, which keeps routes like `/health` and
56
+ `/symbols` at the root. `"/api/v1"`, `"api/v1"`, and `"/api/v1/"` are treated
57
+ the same.
58
+
59
+ ## Example Requests with curl
60
+
61
+ Replace `windows-host` with the DNS name or IP address of the Windows machine
62
+ running `mt5api`. If you run the request on that Windows host, `localhost` also
63
+ works. In PowerShell, use `curl.exe` if `curl` resolves to
64
+ `Invoke-WebRequest`.
65
+
66
+ ```console
67
+ curl "http://windows-host:8000/health"
68
+ ```
69
+
70
+ ```console
71
+ # Include X-API-Key only when MT5API_SECRET_KEY is configured on the server.
72
+ curl -H "X-API-Key: your-secret-api-key" "http://windows-host:8000/symbols?group=*USD*"
73
+ ```
74
+
75
+ ```console
76
+ 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"
77
+ ```
78
+
79
+ Market-data endpoints accept MetaTrader 5 constants either by official name
80
+ (`TIMEFRAME_M1`, `COPY_TICKS_ALL`) or by their integer value.
81
+
82
+ ## Endpoints (Read-Only)
83
+
84
+ - Health: `/health`, `/version`
85
+ - Symbols: `/symbols`, `/symbols/{symbol}`, `/symbols/{symbol}/tick`
86
+ - Market data: `/rates/from`, `/rates/from-pos`, `/rates/range`,
87
+ `/ticks/from`, `/ticks/range`, `/market-book/{symbol}`
88
+ - Account: `/account`, `/terminal`
89
+ - Trading state: `/positions`, `/orders`
90
+ - History: `/history/orders`, `/history/deals`
91
+
92
+ If `API_ROUTER_PREFIX` is set, prepend that value to every API route above.
93
+
94
+ ## License
95
+
96
+ MIT License - see [LICENSE](https://github.com/dceoy/mt5api/blob/main/LICENSE).
@@ -33,11 +33,12 @@ nssm install mt5api
33
33
  5. Set environment variables in the NSSM GUI:
34
34
 
35
35
  ```
36
- # Optional: set MT5_API_KEY only when you want to require X-API-Key headers.
37
- MT5_API_KEY=your-secret-api-key
36
+ # Optional: set MT5API_SECRET_KEY only when you want to require X-API-Key headers.
37
+ MT5API_SECRET_KEY=your-secret-api-key
38
38
  API_LOG_LEVEL=INFO
39
39
  API_RATE_LIMIT=100
40
40
  API_CORS_ORIGINS=*
41
+ API_ROUTER_PREFIX=/api/v1
41
42
  ```
42
43
 
43
44
  6. Start the service:
@@ -48,8 +49,10 @@ nssm start mt5api
48
49
 
49
50
  ## Validation
50
51
 
51
- ```powershell
52
- curl.exe http://localhost:8000/api/v1/health
52
+ In PowerShell, use `curl.exe` if `curl` resolves to `Invoke-WebRequest`.
53
+
54
+ ```console
55
+ curl "http://localhost:8000/health"
53
56
  ```
54
57
 
55
58
  Expected status: `healthy` (or `unhealthy` if MT5 is not connected).
@@ -0,0 +1,57 @@
1
+ # API Reference
2
+
3
+ This section contains the public documentation for mt5api.
4
+
5
+ The API server must run on Windows because the `MetaTrader5` Python package is
6
+ Windows-only. Run `mt5api` on a Windows host with MetaTrader 5 installed and
7
+ logged in. Clients can call the HTTP API from any operating system.
8
+
9
+ ## Guides
10
+
11
+ ### [REST API](rest-api.md)
12
+
13
+ FastAPI-based REST API that exposes read-only MT5 data over HTTP with JSON and
14
+ Parquet support.
15
+
16
+ ### [Deployment](deployment.md)
17
+
18
+ Windows service deployment guide for hosting the REST API alongside MetaTrader 5.
19
+
20
+ ## Architecture Overview
21
+
22
+ mt5api provides a FastAPI layer on top of the MetaTrader 5 terminal runtime:
23
+
24
+ 1. **API Layer** (`mt5api.main`, `mt5api.routers`): FastAPI app, routers, and response formatting
25
+ 2. **Dependency Layer** (`mt5api.dependencies`): MT5 client lifecycle and format negotiation
26
+ 3. **Model Layer** (`mt5api.models`): Response schemas and MT5 constant metadata helpers
27
+ 4. **Formatter Layer** (`mt5api.formatters`): JSON and Parquet serialization helpers
28
+
29
+ ## Usage Guidelines
30
+
31
+ - **Type Safety**: All endpoints and helpers include comprehensive type hints
32
+ - **Error Handling**: Centralized through RFC 7807 responses (see REST API docs)
33
+ - **Documentation**: Google-style docstrings with examples
34
+ - **Validation**: Pydantic models for requests and responses
35
+ - **Data Formats**: JSON and Parquet via content negotiation
36
+
37
+ ## Quick Start
38
+
39
+ ```powershell
40
+ $env:MT5API_SECRET_KEY = "your-secret-api-key" # Optional: omit to disable auth
41
+ $env:API_ROUTER_PREFIX = "/api/v1" # Optional: omit for root-level routes
42
+ uv run uvicorn mt5api.main:app --host 0.0.0.0 --port 8000
43
+ ```
44
+
45
+ Replace `windows-host` with the DNS name or IP address of the Windows machine
46
+ running `mt5api`. If you run the request on that Windows host, `localhost` also
47
+ works. In PowerShell, use `curl.exe` if `curl` resolves to
48
+ `Invoke-WebRequest`.
49
+
50
+ ```console
51
+ # Include X-API-Key only when MT5API_SECRET_KEY is configured on the server.
52
+ curl -H "X-API-Key: your-secret-api-key" "http://windows-host:8000/rates/from?symbol=EURUSD&timeframe=TIMEFRAME_M1&date_from=2024-01-01T00:00:00Z&count=100"
53
+ ```
54
+
55
+ ## Examples
56
+
57
+ See the [REST API](rest-api.md) guide for endpoint examples and request syntax.