1) Executive Summary
ZED is a server-hosted automated trading platform built around Interactive Brokers (IBKR) connectivity and a simple quantitative signal engine.
What it does today
- Runs IB Gateway (paper) with automated login.
- Connects via the IBKR API using
ib_insync. - Computes intraday VWAP + z-score deviation signals on a fixed ETF universe.
- Exposes a WhatsApp control plane (pause/resume/flatten/status/snapshots).
- Can place paper orders (long-only), subject to risk limits.
Design intent
- Default-safe: PAUSED unless explicitly resumed.
- Operational clarity: concise commands + journald logs.
- Incremental hardening before any live trading.
2) System Architecture
2.1 Components
IB Gateway (Paper) + IBC automation
Systemd service: ibgateway-ibc.service
- Maintains authenticated IBKR paper session
- IBC handles login and dialog automation
- Exposes the IB API locally (default port
7497)
ZED Trading Bot
Systemd service: trading-bot.service
- Python +
ib_insync - Config:
/home/ubuntu/clawd/trading/config/bot.yaml - Runtime commands/state:
/home/ubuntu/clawd/trading/state/commands.json - Logs:
journalctl -u trading-bot.service
WhatsApp Control Plane
- Send commands like
zed status,zed resume,zed flatten - Commands update bot state; bot loop reacts on next cycle
- Observability commands read service state and logs
Public Documentation Hosting (This White Paper)
- Served by nginx on the trading server
- Primary URL: https://apiqx.com/
- HTTPS via Let’s Encrypt; HTTP redirects to HTTPS
- Health check:
/health→ok
2.2 Data Flow
- IB Gateway maintains authenticated connection to IBKR paper account.
- ZED connects to IB Gateway via IB API on
127.0.0.1:7497. - On each cycle (typically ~60s):
- Fetches 1-minute bars (
reqHistoricalData, last 1 day) - Computes VWAP and z-score signals
- If unpaused, may submit orders to align positions with targets
- Fetches 1-minute bars (
Operational note: IBKR may restrict historical data when another session is connected from a different IP.
ZED is designed for a single active IBKR session per account.
3) Strategy v0 (As Implemented)
3.1 Universe
Current ETF basket (23 symbols):
SPY, QQQ, IWM, DIA, EEM, EFA, VWO, VGK, FXI, GLD, SLV, USO,
TLT, IEF, LQD, HYG, XLF, XLK, XLE, XLV, XLI, XLY, XLP
3.2 Signal
- Compute intraday VWAP from 1-minute bars
- Compute z-score of
(last - VWAP)normalized by the day’s dispersion
z = (last - vwap) / std(last - vwap)
3.3 Entry/Exit (Long-only Mean Reversion)
- Entry (buy):
z <= -entry_z(defaultentry_z = 2.0) - Exit (reduce to zero):
z >= -exit_z(defaultexit_z = 0.5) - Long-only: no shorts.
3.4 Sizing
Targets are allocated in USD exposure using configuration limits (total gross cap, per-symbol cap, max candidates per side). Allocation is approximately equal across qualifying entries, bounded by caps.
4) Risk, Safety & Governance
4.1 Current Safety Controls
Global controls
- Paused by default; trading requires explicit
zed resume - Flatten:
zed flattencloses positions and pauses
Execution limits
- Total gross exposure cap
- Per-symbol exposure cap
- Minimum trade USD + max order USD chunking
- Cooldown controls to avoid rapid re-trading
4.2 Paper Trading Only
ZED is explicitly operating in paper mode. Any step toward live trading should be treated as a controlled change with additional testing and governance.
5) Observability & WhatsApp Commands
Status/Info
zed helpzed summaryzed statuszed snapshot Nzed errors Nzed tradeszed connectivity N
Control
zed pause— stop new orderszed resume— allow tradingzed flatten— close positions + pausezed restart— restart bot service
6) Current Constraints / Known Issues
- IBKR API timeouts (intermittent). These can cause skipped cycles; ZED currently tolerates and retries.
- Market data subscriptions. Some data may be delayed without real-time subscriptions.
- Multi-login restrictions. IBKR may block historical data if the same account is active from another IP.
- Execution maturity. v0 execution prioritizes robustness in paper; live readiness needs limit orders, fill tracking, and PnL measurement.
7) Roadmap (Next Steps)
Near-term
- Connectivity hardening (backoff, circuit-breaker, better telemetry)
- Market-hours awareness to reduce noisy rejects
- Improve trade reporting (fills, deltas, positions)
Execution hardening
- Limit orders / price controls
- Explicit order state machine (submitted/partial/filled/cancelled)
- Daily loss stop and realized/unrealized PnL tracking
Governance
- Controlled change process for any move toward live trading
- Audit log / trade blotter export