Setup

After installing the Gateway, this page covers advanced configuration, verification, and local testing.

Feature-Gated Builds

When building from source, you can compile only the provider you need. This reduces binary size, compile time, and dependency surface:

# Build with only Alpaca support
cargo build --release --no-default-features --features alpaca

# Build with only Binance support
cargo build --release --no-default-features --features binance

# Combine multiple providers
cargo build --release --no-default-features --features alpaca,binance

# Build with all providers (default)
cargo build --release

Feature-gated builds are useful for production deployments where you only connect to a single provider.

Provider Selection

The Gateway serves exactly one provider per instance, chosen at startup by the GATEWAY_PROVIDER environment variable. The Gateway fails to start if GATEWAY_PROVIDER is unset.

Valid values and the credentials each requires are listed in the Overview provider table. To switch providers, stop the Gateway, change GATEWAY_PROVIDER (and the relevant credential env vars), and restart — there is no runtime provider switching.

Verifying the Gateway

After starting the Gateway, verify it is running correctly.

Health Check

The /metrics endpoint is the simplest health check:

curl -s http://localhost:8080/metrics | head -5

A healthy Gateway returns Prometheus-format metrics. If the endpoint does not respond, the Gateway is not running or is on a different port.

REST API

Verify provider connectivity by querying your account:

curl http://localhost:8080/v1/account

This returns account information from your configured provider. If you see an authentication error, check your provider credentials.

WebSocket

Connect to the event stream to verify real-time data:

ws://localhost:8080/v1/ws

A successful connection receives market events from your provider.

Monitoring

Prometheus Metrics

The Gateway exposes Prometheus-format metrics at /metrics on port 8080. These can be scraped by Prometheus, Grafana, Datadog, or any compatible monitoring tool.

Key metrics to watch:

  • Order counts — submitted, filled, rejected, cancelled
  • Latency — round-trip time from order submission to fill
  • Connection status — WebSocket connection state to the provider
  • Error rates — provider API errors, order rejections

Scraping Configuration

Add the Gateway to your Prometheus scrape targets:

scrape_configs:
  - job_name: 'trading-gateway'
    static_configs:
      - targets: ['localhost:8080']

OpenAPI Specification

Export the full REST API specification for code generation or API exploration:

cargo run --bin openapi-export > openapi.json

Testing Locally

Run the Gateway test suite with cargo-nextest:

# Install nextest (one-time)
cargo install cargo-nextest

# Run the full test suite
cargo nextest run --workspace --all-features

# Test a specific provider adapter
cargo nextest run -p tektii-gateway-alpaca

# Run tests with output visible
cargo nextest run --no-capture

Feature-gated testing lets you run tests for a single provider:

cargo nextest run --workspace --no-default-features --features alpaca

Running on a Different Port

The Gateway listens on port 8080 by default. If another service on the host already occupies 8080, remap the Gateway's host port using Docker:

docker run -d \
  -p 9080: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

Then connect your strategy to http://localhost:9080 (REST) and ws://localhost:9080/v1/ws (WebSocket). The container still listens internally on 8080; only the host-side port changes.

Troubleshooting

SymptomCauseFix
GATEWAY_PROVIDER is required at startupGATEWAY_PROVIDER not setSet it to one of the values in the Overview provider table
Port 8080 already in useAnother service on the host is bound to 8080Stop it or remap the Gateway's host port with -p 9080:8080
Connection refused on /v1/wsGateway not started or wrong portVerify the Gateway is running with curl http://localhost:8080/metrics
Authentication error on /v1/accountInvalid or expired provider API credentialsVerify credentials in your broker's dashboard
Multiple provider warnings at startupCredentials set for more than one providerRemove credentials for providers you don't want to use

Next Steps