Know-Defeat Documentation
High-frequency algorithmic trading system with 126 bots across multiple tickers
Overview
The Know-Defeat trading system is a high-frequency algorithmic trading platform that executes sub-minute trades through Interactive Brokers. The system manages 126 trading bots across multiple tickers (TSLA, COIN, NVDA, etc.), using 8 distinct trading algorithms to generate entry and exit signals. A dynamic fund allocation system ranks bots by performance and limits concurrent trades to 10.
System Purpose
- Automated trading execution through Interactive Brokers via IB Gateway API
- Multi-bot management with 126 independently configured bots
- Performance-based allocation using weighted ranking metrics
- Real-time analytics calculating 25+ performance metrics
- Trade capacity management enforcing max 10 concurrent positions
Getting Started
Prerequisites
| Component | Requirement | Purpose |
|---|---|---|
| Python | 3.8+ with Anaconda | Core runtime |
| PostgreSQL | With TimescaleDB | Time-series storage |
| Interactive Brokers | TWS or IB Gateway | Market data & execution |
| System Resources | 32GB RAM, 350GB+ | Tick data & bots |
Setup Steps
- 1
Environment Installation
Install PostgreSQL with TimescaleDB extension. Create the tick_data database. Install Python dependencies (asyncpg, ib_insync).
- 2
Database Initialization
Create tables: tick_data, bot_tick_data, sim_bot_trades, bot_metrics, bot_rankings, variable_weights.
- 3
Bot Configuration
Create YAML configs in src/bots/ with bot_id, algo_id, ticker, trade_direction, position_size, trailing_stop_pct.
- 4
Bot Registration
Run initialize_all_bots.py to register bots in the database.
- 5
IB Configuration
Enable API connections on port 4002 in IB Gateway/TWS settings.
- 6
Run the System
Start IB Controller, launch bots, monitor via Streamlit dashboard.
System Architecture
Core Components
IB Controller (IBDataIngestion)
Connects to IB Gateway on port 4002. Subscribes to real-time market data for tickers (TSLA, COIN, NVDA, ARWR, ROOT, JANX, AMZN, FLYW, AAPL, AMD, PYPL).
Trading Bots (BaseBot)
126 independently configured bots. Each runs via YAML config with algo_id, ticker, position_size, trailing_stop_pct.
Algorithm Modules
8 algorithm types: Momentum, Breakout, Mean Reversion, Minute Momentum, Price Pattern, Support/Resistance, Volatility Breakout, Volume Surge.
Trade Manager
Enforces 10-trade limit. Manages dynamic allocation. Opens/closes trades based on bot rankings.
Performance & Ranking
Bot Ranker (BotRanker)
Calculates weighted scores for all bots based on 25+ metrics. Updates rankings after each trade.
Metrics Calculator
Time-based: one_hour_performance, one_day_performance, one_week_performance. Risk: sharpe_ratio, profit_factor, max_drawdown.
Database Schema
| Table | Purpose | Key Columns |
|---|---|---|
| tick_data | Market data from IB | timestamp, ticker, price, volume |
| bot_tick_data | Bot-specific tick data | bot_id, timestamp, ticker, price |
| sim_bot_trades | Trade records | trade_id, bot_id, entry_price, exit_price, pnl |
| bot_metrics | Performance metrics | bot_id, total_pnl, sharpe_ratio, win_rate |
| bot_rankings | Bot rankings | bot_id, rank_score, rank, is_active |
| variable_weights | Ranking weights | variable_name, weight, description |
User Interfaces
Streamlit Dashboard
Primary interface with 9 tabs for system control and monitoring.
Remix Web Frontend
Secondary Node.js/React frontend for web-based dashboard. Queries PostgreSQL through server-side API layer. Deployable to Google Cloud Run.
Deployment
Local Development
- • PostgreSQL on localhost:5432
- • IB Gateway on port 4002
- • Streamlit dashboard
- • Direct asyncpg connections
Cloud (GCP)
- • Cloud SQL PostgreSQL
- • Cloud Run for Remix frontend
- • Cloud SQL Proxy
- • GitHub Actions CI/CD
- • Secret Manager