mt5api 0.0.3__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.
- mt5api-0.0.4/AGENTS.md +90 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/PKG-INFO +64 -19
- mt5api-0.0.4/README.md +141 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/docs/api/deployment.md +5 -4
- {mt5api-0.0.3 → mt5api-0.0.4}/docs/api/index.md +19 -7
- mt5api-0.0.4/docs/api/rest-api.md +323 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/docs/index.md +13 -7
- {mt5api-0.0.3 → mt5api-0.0.4}/mt5api/config.py +45 -15
- mt5api-0.0.4/mt5api/constants.py +36 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/mt5api/main.py +47 -4
- {mt5api-0.0.3 → mt5api-0.0.4}/mt5api/models.py +306 -2
- mt5api-0.0.4/mt5api/routers/__init__.py +7 -0
- mt5api-0.0.4/mt5api/routers/calc.py +87 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/mt5api/routers/health.py +24 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/mt5api/routers/history.py +87 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/mt5api/routers/symbols.py +19 -0
- mt5api-0.0.4/mt5api/routers/trading.py +218 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/pyproject.toml +1 -1
- {mt5api-0.0.3 → mt5api-0.0.4}/specs/041-mt5-rest-api/quickstart.md +5 -5
- {mt5api-0.0.3 → mt5api-0.0.4}/tests/conftest.py +48 -5
- {mt5api-0.0.3 → mt5api-0.0.4}/tests/mt5_constants.py +8 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/tests/test_auth.py +45 -1
- mt5api-0.0.4/tests/test_calc.py +296 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/tests/test_cli.py +12 -12
- {mt5api-0.0.3 → mt5api-0.0.4}/tests/test_config.py +51 -8
- {mt5api-0.0.3 → mt5api-0.0.4}/tests/test_health.py +34 -0
- mt5api-0.0.4/tests/test_history.py +394 -0
- mt5api-0.0.4/tests/test_main.py +158 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/tests/test_middleware.py +2 -2
- mt5api-0.0.4/tests/test_models.py +243 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/tests/test_symbols.py +31 -0
- mt5api-0.0.4/tests/test_trading.py +523 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/uv.lock +1 -1
- mt5api-0.0.3/AGENTS.md +0 -65
- mt5api-0.0.3/README.md +0 -96
- mt5api-0.0.3/docs/api/rest-api.md +0 -212
- mt5api-0.0.3/mt5api/constants.py +0 -31
- mt5api-0.0.3/mt5api/routers/__init__.py +0 -7
- mt5api-0.0.3/tests/test_history.py +0 -195
- mt5api-0.0.3/tests/test_main.py +0 -59
- mt5api-0.0.3/tests/test_models.py +0 -113
- {mt5api-0.0.3 → mt5api-0.0.4}/.agents/skills/local-qa/SKILL.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.agents/skills/local-qa/scripts/qa.sh +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.agents/skills/mt5api/SKILL.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.agents/skills/speckit-analyze/SKILL.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.agents/skills/speckit-checklist/SKILL.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.agents/skills/speckit-clarify/SKILL.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.agents/skills/speckit-constitution/SKILL.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.agents/skills/speckit-implement/SKILL.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.agents/skills/speckit-plan/SKILL.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.agents/skills/speckit-specify/SKILL.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.agents/skills/speckit-tasks/SKILL.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.agents/skills/speckit-taskstoissues/SKILL.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.claude/agents/codex.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.claude/agents/copilot.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.claude/commands/speckit.analyze.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.claude/commands/speckit.checklist.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.claude/commands/speckit.clarify.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.claude/commands/speckit.constitution.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.claude/commands/speckit.implement.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.claude/commands/speckit.plan.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.claude/commands/speckit.specify.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.claude/commands/speckit.tasks.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.claude/commands/speckit.taskstoissues.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.claude/settings.json +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.github/FUNDING.yml +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.github/dependabot.yml +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.github/renovate.json +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.github/workflows/ci.yml +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.github/workflows/claude-code.yml +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.gitignore +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.specify/memory/constitution.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.specify/scripts/bash/check-prerequisites.sh +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.specify/scripts/bash/common.sh +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.specify/scripts/bash/create-new-feature.sh +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.specify/scripts/bash/setup-plan.sh +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.specify/scripts/bash/update-agent-context.sh +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.specify/templates/agent-file-template.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.specify/templates/checklist-template.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.specify/templates/plan-template.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.specify/templates/spec-template.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/.specify/templates/tasks-template.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/CLAUDE.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/LICENSE +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/mkdocs.yml +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/mt5api/__init__.py +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/mt5api/__main__.py +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/mt5api/auth.py +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/mt5api/dependencies.py +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/mt5api/formatters.py +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/mt5api/middleware.py +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/mt5api/routers/account.py +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/mt5api/routers/market.py +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/specs/041-mt5-rest-api/contracts/openapi.yaml +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/specs/041-mt5-rest-api/data-model.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/specs/041-mt5-rest-api/plan.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/specs/041-mt5-rest-api/research.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/specs/041-mt5-rest-api/spec.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/specs/041-mt5-rest-api/tasks.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/specs/042-mt5-core-client/spec.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/specs/043-mt5-dataframe-client/spec.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/specs/044-mt5-trading-client/spec.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/specs/045-mt5-utils/spec.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/specs/046-mt5-api-service/spec.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/specs/047-api-auth-rate-limit/spec.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/specs/048-api-response-format/spec.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/specs/049-api-routing-models/spec.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/specs/050-api-runtime-deploy/spec.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/specs/051-api-error-logging/spec.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/specs/052-api-dependencies/spec.md +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/tests/__init__.py +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/tests/test_account.py +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/tests/test_dependencies.py +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/tests/test_formatters.py +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/tests/test_integration.py +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/tests/test_lifespan.py +0 -0
- {mt5api-0.0.3 → mt5api-0.0.4}/tests/test_market.py +0 -0
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.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mt5api
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.4
|
|
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>
|
|
@@ -34,18 +34,46 @@ MetaTrader 5 REST API
|
|
|
34
34
|
|
|
35
35
|
[](https://github.com/dceoy/mt5api/actions/workflows/ci.yml)
|
|
36
36
|
|
|
37
|
-
mt5api exposes
|
|
38
|
-
over HTTP. It uses the `pdmt5`
|
|
39
|
-
auth, rate limiting, and
|
|
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.
|
|
40
41
|
|
|
41
42
|
The API server must run on Windows. The `MetaTrader5` Python package used by
|
|
42
43
|
`pdmt5` is supported only on Windows, so you must host `mt5api` on a Windows
|
|
43
44
|
machine with a logged-in MetaTrader 5 terminal. HTTP clients can connect from
|
|
44
45
|
any operating system.
|
|
45
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
|
+
|
|
46
73
|
## Features
|
|
47
74
|
|
|
48
|
-
-
|
|
75
|
+
- REST endpoints for symbols, market data, account info, orders, history,
|
|
76
|
+
calculations, and trading operations
|
|
49
77
|
- JSON and Apache Parquet responses (content negotiation)
|
|
50
78
|
- Optional API key authentication with per-minute rate limiting
|
|
51
79
|
- Structured JSON logging and configurable CORS
|
|
@@ -72,7 +100,7 @@ uv sync
|
|
|
72
100
|
|
|
73
101
|
```powershell
|
|
74
102
|
$env:MT5API_SECRET_KEY = "your-secret-api-key" # Optional: omit to disable auth
|
|
75
|
-
$env:
|
|
103
|
+
$env:MT5API_ROUTER_PREFIX = "/api/v1" # Optional: omit for root-level routes
|
|
76
104
|
uv run uvicorn mt5api.main:app --host 0.0.0.0 --port 8000
|
|
77
105
|
```
|
|
78
106
|
|
|
@@ -81,11 +109,14 @@ Docs:
|
|
|
81
109
|
- Swagger UI: `http://localhost:8000/docs`
|
|
82
110
|
- OpenAPI JSON: `http://localhost:8000/openapi.json`
|
|
83
111
|
|
|
84
|
-
Set `
|
|
85
|
-
|
|
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
|
|
86
114
|
`/symbols` at the root. `"/api/v1"`, `"api/v1"`, and `"/api/v1/"` are treated
|
|
87
115
|
the same.
|
|
88
116
|
|
|
117
|
+
Set `MT5API_MAX_MARKET_BOOK_SUBSCRIPTIONS` to cap active market-book
|
|
118
|
+
subscriptions. The default limit is `100`.
|
|
119
|
+
|
|
89
120
|
## Example Requests with curl
|
|
90
121
|
|
|
91
122
|
Replace `windows-host` with the DNS name or IP address of the Windows machine
|
|
@@ -106,20 +137,34 @@ curl -H "X-API-Key: your-secret-api-key" "http://windows-host:8000/symbols?group
|
|
|
106
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"
|
|
107
138
|
```
|
|
108
139
|
|
|
109
|
-
Market-data endpoints accept MetaTrader 5 constants either by
|
|
110
|
-
(`TIMEFRAME_M1`, `COPY_TICKS_ALL`) or by their
|
|
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
|
|
111
149
|
|
|
112
|
-
|
|
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`
|
|
113
161
|
|
|
114
|
-
|
|
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`
|
|
162
|
+
### Operational Endpoints
|
|
121
163
|
|
|
122
|
-
|
|
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
|
|
123
168
|
|
|
124
169
|
## License
|
|
125
170
|
|
mt5api-0.0.4/README.md
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# mt5api
|
|
2
|
+
|
|
3
|
+
MetaTrader 5 REST API
|
|
4
|
+
|
|
5
|
+
[](https://github.com/dceoy/mt5api/actions/workflows/ci.yml)
|
|
6
|
+
|
|
7
|
+
mt5api exposes MT5 market data, account info, trading history, and trading
|
|
8
|
+
operations over HTTP. It uses the [`pdmt5`](https://github.com/dceoy/pdmt5)
|
|
9
|
+
client internally and adds optional API-key auth, rate limiting, and
|
|
10
|
+
JSON/Parquet response formatting.
|
|
11
|
+
|
|
12
|
+
The API server must run on Windows. The `MetaTrader5` Python package used by
|
|
13
|
+
`pdmt5` is supported only on Windows, so you must host `mt5api` on a Windows
|
|
14
|
+
machine with a logged-in MetaTrader 5 terminal. HTTP clients can connect from
|
|
15
|
+
any operating system.
|
|
16
|
+
|
|
17
|
+
## Architecture
|
|
18
|
+
|
|
19
|
+
```mermaid
|
|
20
|
+
graph TB
|
|
21
|
+
Client["HTTP Client<br/>(Any OS)"]
|
|
22
|
+
|
|
23
|
+
subgraph "Windows Host"
|
|
24
|
+
subgraph "FastAPI Application"
|
|
25
|
+
Middleware["Middleware Stack<br/>CORS · Logging · Error Handler · Rate Limiter"]
|
|
26
|
+
Routers["Routers<br/>health · symbols · market · account · history · calc · trading"]
|
|
27
|
+
Auth["API Key Security Dependency<br/>Security(api_key_header) · verify_api_key"]
|
|
28
|
+
Deps["FastAPI Dependencies<br/>MT5 Client Singleton · Format Negotiation"]
|
|
29
|
+
Formatters["Response Formatters<br/>JSON · Parquet"]
|
|
30
|
+
Middleware --> Routers --> Deps --> Formatters
|
|
31
|
+
Auth -.-> Routers
|
|
32
|
+
Formatters --> Middleware
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
Deps --> pdmt5["pdmt5<br/>MT5 Client Library"]
|
|
36
|
+
pdmt5 --> MT5["MetaTrader 5<br/>Terminal"]
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
Client -- "HTTP/REST" --> Middleware
|
|
40
|
+
Middleware -- "JSON / Parquet" --> Client
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Features
|
|
44
|
+
|
|
45
|
+
- REST endpoints for symbols, market data, account info, orders, history,
|
|
46
|
+
calculations, and trading operations
|
|
47
|
+
- JSON and Apache Parquet responses (content negotiation)
|
|
48
|
+
- Optional API key authentication with per-minute rate limiting
|
|
49
|
+
- Structured JSON logging and configurable CORS
|
|
50
|
+
- OpenAPI/Swagger docs built into the API
|
|
51
|
+
|
|
52
|
+
## Requirements
|
|
53
|
+
|
|
54
|
+
- Python 3.11+
|
|
55
|
+
- Windows host with MetaTrader 5 terminal installed and logged in
|
|
56
|
+
- Linux and macOS are not supported for the API server runtime, but they work
|
|
57
|
+
for HTTP clients
|
|
58
|
+
|
|
59
|
+
## Installation
|
|
60
|
+
|
|
61
|
+
Install and run the API on the Windows machine where MetaTrader 5 is installed.
|
|
62
|
+
|
|
63
|
+
```powershell
|
|
64
|
+
git clone https://github.com/dceoy/mt5api.git
|
|
65
|
+
cd mt5api
|
|
66
|
+
uv sync
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Running the API on Windows
|
|
70
|
+
|
|
71
|
+
```powershell
|
|
72
|
+
$env:MT5API_SECRET_KEY = "your-secret-api-key" # Optional: omit to disable auth
|
|
73
|
+
$env:MT5API_ROUTER_PREFIX = "/api/v1" # Optional: omit for root-level routes
|
|
74
|
+
uv run uvicorn mt5api.main:app --host 0.0.0.0 --port 8000
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Docs:
|
|
78
|
+
|
|
79
|
+
- Swagger UI: `http://localhost:8000/docs`
|
|
80
|
+
- OpenAPI JSON: `http://localhost:8000/openapi.json`
|
|
81
|
+
|
|
82
|
+
Set `MT5API_ROUTER_PREFIX` to mount the API endpoints under a shared path such
|
|
83
|
+
as `/api/v1`. The default is `""`, which keeps routes like `/health` and
|
|
84
|
+
`/symbols` at the root. `"/api/v1"`, `"api/v1"`, and `"/api/v1/"` are treated
|
|
85
|
+
the same.
|
|
86
|
+
|
|
87
|
+
Set `MT5API_MAX_MARKET_BOOK_SUBSCRIPTIONS` to cap active market-book
|
|
88
|
+
subscriptions. The default limit is `100`.
|
|
89
|
+
|
|
90
|
+
## Example Requests with curl
|
|
91
|
+
|
|
92
|
+
Replace `windows-host` with the DNS name or IP address of the Windows machine
|
|
93
|
+
running `mt5api`. If you run the request on that Windows host, `localhost` also
|
|
94
|
+
works. In PowerShell, use `curl.exe` if `curl` resolves to
|
|
95
|
+
`Invoke-WebRequest`.
|
|
96
|
+
|
|
97
|
+
```console
|
|
98
|
+
curl "http://windows-host:8000/health"
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
```console
|
|
102
|
+
# Include X-API-Key only when MT5API_SECRET_KEY is configured on the server.
|
|
103
|
+
curl -H "X-API-Key: your-secret-api-key" "http://windows-host:8000/symbols?group=*USD*"
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
```console
|
|
107
|
+
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
|
+
```
|
|
109
|
+
|
|
110
|
+
Market-data and calculation endpoints accept MetaTrader 5 constants either by
|
|
111
|
+
official name (`TIMEFRAME_M1`, `COPY_TICKS_ALL`, `ORDER_TYPE_BUY`) or by their
|
|
112
|
+
integer value.
|
|
113
|
+
|
|
114
|
+
## Endpoints
|
|
115
|
+
|
|
116
|
+
If `MT5API_ROUTER_PREFIX` is set, prepend that value to every API route below.
|
|
117
|
+
|
|
118
|
+
### Read-Only Endpoints
|
|
119
|
+
|
|
120
|
+
- Health: `GET /health`, `GET /version`, `GET /last-error`
|
|
121
|
+
- Symbols: `GET /symbols`, `GET /symbols/total`, `GET /symbols/{symbol}`,
|
|
122
|
+
`GET /symbols/{symbol}/tick`
|
|
123
|
+
- Market data: `GET /rates/from`, `GET /rates/from-pos`, `GET /rates/range`,
|
|
124
|
+
`GET /ticks/from`, `GET /ticks/range`, `GET /market-book/{symbol}`
|
|
125
|
+
- Calculations: `GET /calc/margin`, `GET /calc/profit`
|
|
126
|
+
- Account: `GET /account`, `GET /terminal`
|
|
127
|
+
- Trading state: `GET /positions`, `GET /positions/total`,
|
|
128
|
+
`GET /orders`, `GET /orders/total`
|
|
129
|
+
- History: `GET /history/orders`, `GET /history/orders/total`,
|
|
130
|
+
`GET /history/deals`, `GET /history/deals/total`
|
|
131
|
+
|
|
132
|
+
### Operational Endpoints
|
|
133
|
+
|
|
134
|
+
- `POST /symbols/{symbol}/select` — Show or hide symbol in MarketWatch
|
|
135
|
+
- `POST /market-book/{symbol}/subscribe` — Subscribe to DOM events
|
|
136
|
+
- `POST /market-book/{symbol}/unsubscribe` — Unsubscribe from DOM events
|
|
137
|
+
- `POST /order/check` — Validate a trade request without execution
|
|
138
|
+
|
|
139
|
+
## License
|
|
140
|
+
|
|
141
|
+
MIT License - see [LICENSE](https://github.com/dceoy/mt5api/blob/main/LICENSE).
|
|
@@ -35,10 +35,11 @@ nssm install mt5api
|
|
|
35
35
|
```
|
|
36
36
|
# Optional: set MT5API_SECRET_KEY only when you want to require X-API-Key headers.
|
|
37
37
|
MT5API_SECRET_KEY=your-secret-api-key
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
MT5API_LOG_LEVEL=INFO
|
|
39
|
+
MT5API_RATE_LIMIT=100
|
|
40
|
+
MT5API_MAX_MARKET_BOOK_SUBSCRIPTIONS=100
|
|
41
|
+
MT5API_CORS_ORIGINS=*
|
|
42
|
+
MT5API_ROUTER_PREFIX=/api/v1
|
|
42
43
|
```
|
|
43
44
|
|
|
44
45
|
6. Start the service:
|
|
@@ -10,8 +10,9 @@ logged in. Clients can call the HTTP API from any operating system.
|
|
|
10
10
|
|
|
11
11
|
### [REST API](rest-api.md)
|
|
12
12
|
|
|
13
|
-
FastAPI-based REST API that exposes
|
|
14
|
-
|
|
13
|
+
FastAPI-based REST API that exposes MT5 market data, account info, trading
|
|
14
|
+
history, calculations, and non-executing operational endpoints over HTTP with
|
|
15
|
+
JSON and Parquet support.
|
|
15
16
|
|
|
16
17
|
### [Deployment](deployment.md)
|
|
17
18
|
|
|
@@ -21,10 +22,21 @@ Windows service deployment guide for hosting the REST API alongside MetaTrader 5
|
|
|
21
22
|
|
|
22
23
|
mt5api provides a FastAPI layer on top of the MetaTrader 5 terminal runtime:
|
|
23
24
|
|
|
24
|
-
1. **API Layer** (`mt5api.main`, `mt5api.routers`): FastAPI app, routers, and
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
1. **API Layer** (`mt5api.main`, `mt5api.routers`): FastAPI app, routers, and
|
|
26
|
+
response formatting. Routers are grouped by domain:
|
|
27
|
+
- `health.py`: health check, version, last error
|
|
28
|
+
- `symbols.py`: symbol listing, details, tick, and total
|
|
29
|
+
- `market.py`: OHLCV rates, tick data, and market depth
|
|
30
|
+
- `calc.py`: margin and profit calculations
|
|
31
|
+
- `account.py`: account and terminal info
|
|
32
|
+
- `history.py`: positions, orders, history with totals
|
|
33
|
+
- `trading.py`: order check, symbol selection, market book subscriptions
|
|
34
|
+
2. **Dependency Layer** (`mt5api.dependencies`): MT5 client lifecycle and
|
|
35
|
+
format negotiation
|
|
36
|
+
3. **Model Layer** (`mt5api.models`): Response schemas and MT5 constant
|
|
37
|
+
metadata helpers (TIMEFRAME, COPY_TICKS, ORDER_TYPE)
|
|
38
|
+
4. **Formatter Layer** (`mt5api.formatters`): JSON and Parquet serialization
|
|
39
|
+
helpers
|
|
28
40
|
|
|
29
41
|
## Usage Guidelines
|
|
30
42
|
|
|
@@ -38,7 +50,7 @@ mt5api provides a FastAPI layer on top of the MetaTrader 5 terminal runtime:
|
|
|
38
50
|
|
|
39
51
|
```powershell
|
|
40
52
|
$env:MT5API_SECRET_KEY = "your-secret-api-key" # Optional: omit to disable auth
|
|
41
|
-
$env:
|
|
53
|
+
$env:MT5API_ROUTER_PREFIX = "/api/v1" # Optional: omit for root-level routes
|
|
42
54
|
uv run uvicorn mt5api.main:app --host 0.0.0.0 --port 8000
|
|
43
55
|
```
|
|
44
56
|
|