Trading Gateway

The Trading Gateway is an open-source, self-hosted trading proxy that normalises multiple broker APIs behind a single REST + WebSocket interface on port 8080. Your strategy codes against one protocol; the Gateway routes to the broker (paper or live) or to the Tektii simulation backend (backtest). One codebase, zero branching.

Why Use the Gateway?

Every broker speaks a different language — different endpoints, auth, order models, failure modes. The Gateway sits between your strategy and the upstream provider and presents a single normalised API:

  • One protocol, any broker — one REST + WebSocket surface covers every supported broker.
  • Broker-agnostic exit management — stop-loss, take-profit, and trailing stops work identically on every broker, native support or not. State persists across restarts.
  • Backtest-to-live with zero code changes — the tektii provider connects the Gateway to the Tektii simulation backend using the same protocol as live brokers. Write once, backtest, then flip GATEWAY_PROVIDER to go live.

Each Gateway instance serves exactly one provider, chosen at startup via the GATEWAY_PROVIDER environment variable. To switch providers, restart the Gateway — there is no runtime provider switching.

Supported Providers

From the Trading Gateway README:

GATEWAY_PROVIDERFeature flagRequired credentials
alpacaalpaca (default)ALPACA_API_KEY, ALPACA_API_SECRET
binance_spotbinance (default)BINANCE_API_KEY, BINANCE_API_SECRET
oandaoanda (default)OANDA_API_KEY, OANDA_ACCOUNT_ID
saxosaxo (default)SAXO_APP_KEY, SAXO_APP_SECRET, SAXO_ACCOUNT_KEY
tektiitektii (opt-in)TEKTII_ENGINE_URL, TEKTII_ENGINE_WS_URL
mockmock (default)none — in-memory simulation for development

All five broker adapters (alpaca, binance_spot, oanda, saxo) plus mock ship as default Cargo features and are compiled into the published Docker image. The tektii simulation adapter is opt-in and must be enabled at build time with --features tektii — it is not bundled in the default image.

Paper vs live: set GATEWAY_MODE=paper (default) or GATEWAY_MODE=live. The Gateway picks the correct upstream URLs — no per-provider URL overrides are required.

Prerequisites

You need one of:

  • Docker (recommended) — no Rust toolchain required
  • Rust toolchain — version 1.91.0 or later

Installation

Docker (Recommended)

The published Docker image bundles all default broker adapters:

docker pull ghcr.io/tektii/gateway:latest

Build from Source

Build from source only if you need the opt-in tektii simulation adapter or a custom feature set:

git clone https://github.com/Tektii/trading-gateway.git
cd trading-gateway
cargo build --release

Requires Rust 1.91.0 or later. The output binary is at target/release/tektii-gateway.

Configuration

The Gateway is configured entirely via environment variables — no config files. The minimum to start is GATEWAY_PROVIDER plus the credentials that provider requires (see the Supported Providers table above). Paper vs live is controlled by GATEWAY_MODE (default paper), not per-provider flags.

For the full list of per-provider env vars (ALPACA_*, BINANCE_*, OANDA_*, SAXO_*), see .env.example in the Gateway repo.

Starting the Gateway

Docker

docker run -d \
  -p 8080:8080 \
  -e GATEWAY_PROVIDER=alpaca \
  -e GATEWAY_MODE=paper \
  -e ALPACA_API_KEY=your-key \
  -e ALPACA_API_SECRET=your-secret \
  ghcr.io/tektii/gateway:latest

For a quick-start that doesn't require credentials, use the mock provider:

docker run -e GATEWAY_PROVIDER=mock -e ENABLE_SWAGGER=true -p 8080:8080 \
  ghcr.io/tektii/gateway:latest

From Source

export GATEWAY_PROVIDER=alpaca
export GATEWAY_MODE=paper
export ALPACA_API_KEY=your-key
export ALPACA_API_SECRET=your-secret
cargo run --release

Verify It's Running

All traffic runs on port 8080:

EndpointPurpose
http://localhost:8080/v1/...REST API
ws://localhost:8080/v1/wsWebSocket event stream
http://localhost:8080/metricsPrometheus metrics
http://localhost:8080/healthHealth probe

Check the health endpoint to verify the Gateway is running:

curl http://localhost:8080/health

If port 8080 is already occupied on the host, remap the Gateway's host port with Docker (-p 9080:8080) — see Setup → Running on a Different Port.

Next Steps

  • Setup — Feature-gated builds, verification, monitoring, and troubleshooting
  • Going Live — Connect your backtested strategy to the Gateway for paper and live trading
  • Connection Guide — Detailed WebSocket and REST connection patterns