Skip to content

Using with qkt

qkt is an event-driven trading engine that treats this gateway as its MT5 broker backend — qkt never talks to MT5 directly, it talks to mt5-gateway's HTTP API. This page covers the gateway side of that pairing; qkt's side is documented in qkt's Deploy MT5 guide and Deploy on Exness (MT5) how-to.

The relationship

  • mt5-gateway — this project. Wine + MT5 terminal, exposes the HTTP API on :5001.
  • qkt — the trading daemon. Waits for the gateway to report /health/ready before starting, then places orders and reads market data through the gateway's REST API instead of an in-process MT5 SDK.

Wiring them together

Run both as services in the same Compose project (or the same Docker network) so qkt can reach the gateway by service name:

services:
  mt5-gateway:
    image: elitekaycy/mt5-gateway-api:0.3.21
    restart: unless-stopped
    environment:
      MT5_LOGIN: ${MT5_LOGIN}
      MT5_PASSWORD: ${MT5_PASSWORD}
      MT5_SERVER: ${MT5_SERVER}
      API_KEY: ${API_KEY}
      # qkt does the broker-time to UTC conversion itself (see below)
      MT5_SERVER_UTC_OFFSET_SECONDS: "0"
    volumes:
      - mt5-gateway-config:/config
    healthcheck:
      test:
        [
          "CMD-SHELL",
          'curl -fsS -H "Authorization: Bearer $$API_KEY" http://localhost:5001/health/ready',
        ]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 90s

  qkt:
    image: elitekaycy/qkt:latest
    depends_on:
      mt5-gateway:
        condition: service_healthy
    environment:
      QKT_BROKER_GATEWAY_URL: http://mt5-gateway:5001
      QKT_BROKER_API_KEY: ${API_KEY}
      QKT_BROKER_SERVER_TIME_ZONE: ${QKT_BROKER_SERVER_TIME_ZONE}

volumes:
  mt5-gateway-config:

qkt's broker config then points gateway_url at that same address:

brokers:
  mt5:
    type: mt5
    gateway_url: ${QKT_BROKER_GATEWAY_URL:-http://mt5-gateway:5001}
    api_key: ${QKT_BROKER_API_KEY}
    server_time_zone: ${QKT_BROKER_SERVER_TIME_ZONE}   # UTC, new_york_close, an IANA id, or +02:00
    symbol_suffix: ${QKT_BROKER_SYMBOL_SUFFIX:-}       # e.g. "m" for Exness
    magic: ${QKT_BROKER_MAGIC:-10001}

This is the profile from qkt's own docs (qkt v0.56.1). Two settings matter on the gateway side:

  • api_key must equal the gateway's API_KEY, or every call gets 401.
  • Keep the gateway's MT5_SERVER_UTC_OFFSET_SECONDS=0 and set server_time_zone in qkt: qkt performs the single broker-wall-to-UTC conversion for bars and ticks.

The type: mt5 profile talks to this gateway. It is a different thing from type: gateway, which qkt uses for the venue gateway (futures and options).

qkt waits for the gateway's healthcheck (service_healthy, backed by /health/ready) before it starts trading — the same signal the Quickstart uses to confirm the gateway is up.

Multiple brokers

Each broker account needs its own gateway container — they don't share a Wine prefix or an MT5 session. Give each one a distinct service name and point:

brokers:
  icmarkets:
    type: mt5
    gateway_url: http://icmarkets-gateway:5001
    api_key: ${ICMARKETS_API_KEY}
    magic: 10001
  ftmo:
    type: mt5
    gateway_url: http://ftmo-gateway:5001
    api_key: ${FTMO_API_KEY}
    magic: 10002

Then reference each in a qkt strategy by its broker name, e.g. eur = ICMARKETS:EURUSD EVERY 5m. Add each gateway to docker-compose.yml with the same shape as mt5-gateway above — different MT5_LOGIN / MT5_SERVER, different container/service name.

Troubleshooting

If qkt reports the broker as unreachable, check the gateway directly first:

curl -H "Authorization: Bearer $API_KEY" http://localhost:5001/health/ready

A 503 or a non-connected mt5_status means the gateway itself hasn't authorized yet — see Install MT5 + mt5-gateway on a terminal for what a healthy boot looks like and how to read its logs. VNC on :3000 remains available as a manual-login fallback either way.

See also