CoolFace
Apppublic

lakes41/execute

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
App README

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

  1. 1.FastAPI runs on Linux and binds 0.0.0.0:7860.
  2. 2.MT5 runs as its own Wine process under Xvfb.
  3. 3.The bridge runs as a separate Windows Python process under Wine.
  4. 4.The bridge listens only on 127.0.0.1:5555.
  5. 5.The bridge refuses to bind until MetaTrader5 imports, mt5.initialize() succeeds, and account info is available.
  6. 6.Windows Python and the MetaTrader5 wheel are baked during Docker build; startup never runs pip, ensurepip, get-pip.py, or downloads packages.
  7. 7.VC/UCRT runtime support is installed during image build with Debian Bookworm Wine 8+ plus the official Microsoft VC++ redistributable.
  8. 8.State is persisted under /app/state using atomic JSON file replacement.
  9. 9.Logs are written to stdout and /app/logs.
  10. 10.Health is fail-closed: /health returns 503 unless FastAPI, MT5, the bridge socket, and a bridge probe are all ready.

Environment

Set these Hugging Face Space variables:

VariableRequiredDescription
MT5_LOGINyesMT5 account number
MT5_PASSWORDyesMT5 account password
MT5_SERVERyesBroker server name
SPACE_B_API_KEYrecommendedRequired by admin endpoints when set
RISK_PERCENToptionalDefault 1.0
MAX_OPEN_TRADESoptionalDefault 3
SPACE_B_DEMO_MODEoptionaltrue records demo trades without sending orders

Endpoints

  • —GET /health
  • —GET /status
  • —POST /signal
  • —POST /kill-switch
  • —GET /trades
  • —GET /positions

Example signal:

json
{
  "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

  1. 1.Create a Hugging Face Space with SDK Docker.
  2. 2.Push this repository to the Space.
  3. 3.Add the MT5 environment variables in Space settings.
  4. 4.Keep secrets in Hugging Face variables, not in the repository.
  5. 5.Rebuild the Space from a clean Docker build.
  6. 6.Watch the build log for wine bridge runtime ok.
  7. 7.Watch runtime logs for Space B is ready.
  8. 8.Confirm GET /health returns HTTP 200.

Validation Checklist

  1. 1.curl -i https://<space>.hf.space/health returns 200.
  2. 2.The response shows bridge_ready: true, mt5_terminal_running: true, and bridge_port_open: true.
  3. 3.curl https://<space>.hf.space/status shows account data.
  4. 4.A valid POST /signal returns success: true.
  5. 5.Restart the Space and confirm /trades still contains prior records.
  6. 6.Confirm /app/logs/startup.log, /app/logs/bridge.log, /app/logs/mt5.log, and /app/logs/app.log show clear timestamps and stages.