Extend mt5-httpapi with backtest endpoints on top of v4 config#2
Draft
Marinski wants to merge 4 commits intopsyb0t:masterfrom
Draft
Extend mt5-httpapi with backtest endpoints on top of v4 config#2Marinski wants to merge 4 commits intopsyb0t:masterfrom
Marinski wants to merge 4 commits intopsyb0t:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR extends
mt5-httpapiwith an opt-in backtest mode for MT5 terminals.The current project already runs real MT5 terminals inside a Windows VM and exposes them over HTTP for live trading and market data access. This PR adds a second execution mode focused on isolated tester runs, while keeping the same terminal/account routing model, Docker deployment model, and MT5-on-Windows runtime model.
A terminal configured with
mode: backtestexposes tester-oriented endpoints instead of the normal live-trading surface.This is intended as an extension of the core codebase, not as a separate wrapper around it.
Motivation
mt5-httpapiis already a strong base for remote MT5 automation because it gives each terminal a stable HTTP surface behind:/<broker>/<account>/...That same architecture is also a good fit for remote backtesting.
The missing piece was an API mode that can:
This PR adds that capability directly to the project.
What this PR adds
1. Per-terminal execution mode
A terminal entry in
config/config.yamlcan now declare amode.Example:
Behavior:
mode: livekeeps the normal trading/data API surfacemode: backtestexposes backtest-oriented endpoints onlyThis makes the feature opt-in and terminal-scoped. A single installation can run both live and backtest terminals side by side.
2. Backtest HTTP endpoints
Backtest terminals expose:
GET /pingGET /errorPOST /terminal/first-loginPOST /backtestGET /backtest/<job_id>This keeps the public surface narrow and explicit for tester workers.
POST /backtestSubmits a backtest job and returns
202 Acceptedwith a job payload.Accepted inputs:
ini— required MT5 tester INI as UTF-8 textexpert— optional uploaded.ex5expert_name— optional filename resolved fromassets/experts/set— optional uploaded.setset_name— optional filename resolved fromassets/sets/Rules:
expertorexpert_namemust be providedset/set_nameare optionalGET /backtest/<job_id>Returns job state and job result.
Status lifecycle:
queuedrunningcompletedfailedThe response includes job metadata, log/report/debug paths, and final result data when complete.
3. MT5 tester execution flow
The backtest handler performs the following steps:
config/config.yamlReports\...This makes MT5 tester execution available over HTTP using the same Windows VM runtime as the rest of the project.
4. First-login endpoint for backtest terminals
Backtest terminals also expose:
POST /terminal/first-loginThis gives backtest terminals an API-triggered initialization/login path before tester jobs run.
That is useful for terminals that need to be prepared through HTTP instead of only through manual VM interaction.
5. Optional reusable host-managed backtest assets
This PR adds an optional asset model for repeated isolated testing.
Reusable files can live in:
assets/experts/assets/sets/Those folders are mounted into the VM shared path and can be referenced in
POST /backtestusing:expert_nameset_nameThis keeps reusable EA/set binaries outside runtime-generated
data/and avoids re-uploading the same files on every request.Upload-based submission still works exactly as before for the new backtest API.
6. Integration with the current upstream configuration model
This PR uses the current single-file YAML configuration model centered on:
config/config.yamlRelated runtime and helper paths were updated so the new backtest functionality fits the current project structure and startup flow.
API behavior
Live terminals
Terminals in
mode: livekeep the current API shape, including:/terminal/account/symbols/orders/positions/historyNo change in intent there.
Backtest terminals
Terminals in
mode: backtestexpose only the backtest-oriented surface listed above.This separation was intentional so a tester terminal is not also presented as a live-trading terminal.
Example requests
Submit a backtest with uploaded files
Submit a backtest with host-managed reusable assets
Poll job status
Example queued response
{ "jobId": "4e3a7f5a1b0d4f6b8c9d2e1f3a4b5c6d", "status": "queued", "broker": "roboforex", "account": "demo", "submittedAt": "2026-05-08T12:34:56Z", "reportName": "backtest-report.htm", "reportPath": "C:\\...\\Reports\\backtest-report.htm", "logPath": "C:\\...\\logs\\backtest-roboforex-demo-<job>.log", "statusUrl": "/backtest/4e3a7f5a1b0d4f6b8c9d2e1f3a4b5c6d", "pollAfterSeconds": 1200, "queuePosition": 0, "resultStatusCode": null }Configuration changes
config/config.yamlNew terminal field:
modeAccepted values:
livebacktestHost-managed assets
Optional folders:
assets/experts/assets/sets/These are mounted into the VM and used only when the caller chooses
expert_name/set_name.Documentation updates included in this PR
This PR updates project documentation to reflect the new merged-state behavior, including:
mode: backtestconfigurationCompatibility
This PR is intentionally additive.
/<broker>/<account>/...Validation
Validated during development with:
python3 -m py_compile mt5api/config.py mt5api/handlers/backtest.pybash -n run.shdocker compose -f docker-compose.yml config -qdocker compose -f docker-compose.yml.example config -qIn addition, startup/config behavior was verified manually via run.sh, including config sync and installer handling.
Review notes
This PR is broader than a small endpoint patch because the feature crosses several layers of the project:
The core idea, though, is narrow:
If the full PR is too broad for merge as one unit, the backtest mode pieces can also be reviewed as a basis for follow-up splitting or selective integration.