Files
my-NexusTradingForexBot/docs/linux_wsl2_mt5_platform.md
gavindiazandClaude Code 3a005ddcc6
Docs / Validate documentation (push) Canceled after 0s
Docs / Deploy GitHub Pages (push) Canceled after 0s
CI Final Summary (AI) / AI Final Summary (push) Canceled after 0s
CI Final Summary (AI) / Push/PR event feed (push) Canceled after 0s
CI / CI Integrity and Change Classification (push) Canceled after 0s
CI / Code Quality & Tests (push) Canceled after 0s
Dependency Lock & Migration Safety / Dependency drift (lock vs pyproject) (push) Canceled after 0s
Dependency Lock & Migration Safety / Migration safety (fail-loud + version postconditions) (push) Canceled after 0s
JS Tests / Frontend JS Unit Tests (push) Canceled after 0s
Security / CodeQL Analysis (push) Canceled after 0s
Security / Trivy Vulnerability Scan (push) Canceled after 0s
Tests (OS Matrix) / Py Tests (macos-latest) (push) Canceled after 0s
Tests (OS Matrix) / Py Tests (windows-latest) (push) Canceled after 0s
CI / Extended Validation (Tier 2) (push) Canceled after 0s
CI / Heavy CI (database-provider) (push) Canceled after 0s
CI / Heavy CI (e2e) (push) Canceled after 0s
CI / Heavy CI (integration) (push) Canceled after 0s
CI / Heavy CI (model-validation) (push) Canceled after 0s
CI / Heavy CI (research-backtest) (push) Canceled after 0s
CI / Aggregate CI Results (push) Canceled after 0s
chore(repo): initial import of Nexus Trading Forex Bot into self-hosted hosting
Full project import for the self-hosted code hosting
(https://code.aifunny.ltd/gavindiaz/my-NexusTradingForexBot.git).

Includes the live-freshness + scaler-hash fixes for the permanent
STALE dashboard (tick_pipeline now_utc stamps; infer_probabilities
computes model_input_hash on the actual scaled 70D tensor), the
data-fetch default-path fix, the g29 web-auth test fixes, and a
Chinese user manual (使用手册.md) for the web dashboard.

Scratch diagnostic scripts (check*.py, contain a live web-auth token)
and the .kilo/ agent-worktree directory are gitignored, not committed.

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-09-23 23:24:54 +08:00

6.5 KiB

WSL2 Linux Test Platform (MT5 under Wine)

Status: TEST/PAPER platform only. Nothing in this document enables live trading. No "production ready" claim is made while operator broker probes remain unverified.

This is the environment registry entry + reproduction guide for the Linux test platform verified on 2026-09-11 (mission TASK-LINUX-MT5-WSL2-REVERIFY, commit 8fdcbdb9; original VM mission TASK-LINUX-MT5-PLATFORM, commit 38f3b80e).


1. Environment entry (registry)

Property Value
Platform WSL2 (Kali GNU/Linux Rolling, kernel 6.18.x-microsoft-standard-WSL2)
Host Windows 11 Pro, i3-12100 (8 vCPU exposed to WSL), ~7.6 GB RAM, 1 TB virtual disk
MT5 terminal MetaTrader 5 x64 build 6191 under Wine 10.0 (Kali wine/wine64/wine32:i386 10.0~repack-11)
Wine prefix isolated, user-owned: $NEXUS_MT5_ROOT/test/prefix (WINEARCH=win64, terminal run /portable)
Headless display Xvfb required (:99, 1280x1024x24)
Direct Python MetaTrader5 IPC UNSUPPORTED - initialize() returns (-10005, 'IPC timeout'); proven with WINEDEBUG=+file pipe forensics (client connect/write OK, terminal-side pipe server never replies). Reproduced on wine 9.0, 10.0 and 11.16
Supported Nexus integration RemoteMT5GatewayAdapter (HTTP + HMAC) - localhost RTT median 0.80 ms / p95 1.26 ms (200 calls)
Network topology caveat WSL2 to Windows host TCP/ICMP is blocked by default (Hyper-V firewall). A gateway on the Windows host is unreachable from WSL until mirrored networking or a narrowly scoped allow rule exists. For tests, run engine + gateway inside WSL
Shell EOL requirement scripts/linux/*.sh must be LF (pinned in .gitattributes, commit 8fdcbdb9); CRLF copies fail in bash with set: -CR: invalid option while exiting 0 - masked breakage
LIVE capability None. No credentials on this host (doctor-enforced), gateway demo-guard + --allow-live refusal intact, DirectMT5Adapter fails closed on Linux

Verified uses: MT5 runtime lifecycle (start/stop/restart/health/version), release engineering dry-runs, gateway-adapter integration tests, soak stability (11.7 h, see section 5).

Not verified / out of scope: broker demo-account login, market data, order APIs (BLOCKED-ON-OPERATOR - no credentials supplied by design).


2. Reproduce from scratch (no sudo at runtime)

One-time system packages (needs sudo, WSL: wsl.exe -d kali-linux):

sudo apt-get update
sudo apt-get install -y wine wine64 wine32:i386 xvfb python3-pip python3-venv
# i386 multiarch first: dpkg --add-architecture i386 && sudo apt-get update

Everything else is user-space under NEXUS_MT5_ROOT (default /root/nexus-mt5 on this box; any writable dir works):

export NEXUS_MT5_ROOT=$HOME/nexus-mt5
export NEXUS_MT5_WINE=$(command -v wine)          # /usr/bin/wine (Kali)
export NEXUS_MT5_WINESERVER=$(command -v wineserver)
scripts/linux/mt5_runtime.sh install   # official mt5setup.exe, silent /auto
scripts/linux/mt5_runtime.sh start     # Xvfb :99 + terminal64 /portable
scripts/linux/mt5_runtime.sh health
scripts/linux/mt5_runtime.sh logs      # UTF-16 -> UTF-8 tail
scripts/linux/mt5_runtime.sh version
scripts/linux/mt5_runtime.sh stop
python3 scripts/linux/mt5_doctor.py    # environment verification (fail-closed)

Installer provenance: sha256 of mt5setup.exe recorded to $NEXUS_MT5_ROOT/cache/mt5setup.exe.sha256 on every install (a879492d...f4c93 for the 2026-09 runs). MT5 self-updates via LiveUpdate on first start (6184 to 6191 observed; the terminal manages its own build).

WSL2 display gotcha: /tmp/.X11-unix is a read-only tmpfs in some WSL distros. If Xvfb cannot bind (log: failed to bind listener), kill stale Xvfb :99 processes, remove /tmp/.X99-lock, and retry; mt5_runtime.sh detects the socket and reuses a running Xvfb.


3. Direct Python-in-Wine probe (documented as UNSUPPORTED - do not deploy)

Reproduction of the disproof (kept for future wine-version re-tests):

  1. Install Windows CPython 3.11.9 embeddable zip into the prefix at C:\python311 (the MSI installer aborts under wine 10; the zip works). Patch python311._pth -> uncomment import site.
  2. python.exe -m pip via get-pip, then pip install MetaTrader5 "numpy<2". numpy MUST be <2: numpy 2.x bundles an openblas that calls ucrtbase.crealf, unimplemented in wine 10's builtin ucrtbase -> the interpreter aborts on import numpy (WineHQ bug 58943).
  3. With terminal64 running: initialize() returns False after ~60 s with (-10005, 'IPC timeout'). WINEDEBUG=+file shows the client's CreateFileW on \\.\pipe\MT5.Terminal.<sha256> succeeds, the handshake write completes, then every 4-byte read blocks - the terminal side never completes the handshake. No Wine IPC workaround will be shipped; re-test only when a newer Wine claims named-pipe fixes.

4. Supported integration path

WSL2: LiveEngine -> RemoteMT5GatewayAdapter --HTTP/HMAC--> gateway (same WSL host for tests)
                                                            -> (future) Windows host MT5 gateway
  • NSE_GATEWAY_URL / NSE_GATEWAY_API_KEY / NSE_GATEWAY_SECRET configure the client; defaults are refused for LIVE-allowed gateways (AUDIT-B2).
  • nse gateway status verifies reachability + HMAC PING from Linux.
  • Gateway-unavailable behaviour (verified): connect() returns False, get_last_tick() raises RuntimeError - the engine fails closed, never fabricates market data.
  • If topology B (gateway on Windows host) is ever chosen, the minimal safe change is mirrored networking (networkingMode=mirrored in .wslconfig) or a Hyper-V firewall rule scoped to WSL subnet -> host 127.0.0.1:<gateway-port> - never a global firewall disable.

5. Soak evidence (2026-09-11)

  • Started 02:17:54Z, collected 13:42Z -> 11.7 h wall, single process (pid 14621), zero restarts after the final start (05:31:46Z; terminal log shows 13 starts total = the mission's own install/LiveUpdate/probe cycles, 1 clean shutdown with 0).
  • RSS 260 -> 276 MB over 10.9 h (+16 MB, then flat; 0.0 MB delta in 60 s windows), 20 threads constant, 106 fds constant (no FD leak), VmSwap 0 kB.
  • CPU: 2.0-2.2% of one core average, ~5% instantaneous, wineserver ~1%.
  • Terminal health: process alive, log written, MCP listener on 127.0.0.1:22346 up, mt5_runtime.sh health PASS.
  • Verdict: no unexplained crash, no runaway memory, no FD leak, no lifecycle degradation (idle-terminal soak, no account logged in).