lakes41/execute
0
Space B
Space B is a Hugging Face Docker Space that exposes a Linux FastAPI service on port 7860 and executes validated XAU/USD signals through MetaTrader 5 running inside Wine.
Architecture
- FastAPI runs on Linux and binds
0.0.0.0:7860. - MT5 runs as its own Wine process under Xvfb.
- The bridge runs as a separate Windows Python process under Wine.
- The bridge listens only on
127.0.0.1:5555. - The bridge refuses to bind until
MetaTrader5imports,mt5.initialize()succeeds, and account info is available. - Windows Python and the
MetaTrader5wheel are baked during Docker build; startup never runspip,ensurepip,get-pip.py, or downloads packages. - VC/UCRT runtime support is installed during image build with Debian Bookworm Wine 8+ plus the official Microsoft VC++ redistributable.
- State is persisted under
/app/stateusing atomic JSON file replacement. - Logs are written to stdout and
/app/logs. - Health is fail-closed:
/healthreturns503unless FastAPI, MT5, the bridge socket, and a bridge probe are all ready.
Environment
Set these Hugging Face Space variables:
Endpoints
GET /healthGET /statusPOST /signalPOST /kill-switchGET /tradesGET /positions
Example signal:
{
"signal_id": "xau-test-001",
"action": "BUY",
"symbol": "XAUUSD",
"entry_price": 2335.50,
"stop_loss": 2328.50,
"take_profit_1": 2349.50,
"timeout_bars": 72
}Hugging Face Deployment Checklist
- Create a Hugging Face Space with SDK
Docker. - Push this repository to the Space.
- Add the MT5 environment variables in Space settings.
- Keep secrets in Hugging Face variables, not in the repository.
- Rebuild the Space from a clean Docker build.
- Watch the build log for
wine bridge runtime ok. - Watch runtime logs for
Space B is ready. - Confirm
GET /healthreturns HTTP200.
Validation Checklist
curl -i https://<space>.hf.space/healthreturns200.- The response shows
bridge_ready: true,mt5_terminal_running: true, andbridge_port_open: true. curl https://<space>.hf.space/statusshows account data.- A valid
POST /signalreturnssuccess: true. - Restart the Space and confirm
/tradesstill contains prior records. - Confirm
/app/logs/startup.log,/app/logs/bridge.log,/app/logs/mt5.log, and/app/logs/app.logshow clear timestamps and stages.
