This commit is contained in:
Boki 2026-11-26 22:23:07 -05:00
parent c353ddbe01
commit ce9e2df67c
310 changed files with 2550 additions and 36861 deletions

View file

@ -1,111 +1,58 @@
## **Your Complete Trading Infrastructure Overview**
# Infrastructure & Server Topology
### **🖥️ Server Architecture**
Stock Bot runs across dedicated local-network hardware separating research/data-curation workloads from live/paper broker execution and cold archival storage.
```yaml
9900K (ITX) - LIVE TRADING ENGINE
├── Purpose: Live + Paper Trading (Isolated)
├── Hardware: 8C/16T, 32GB RAM, NVMe storage
├── Databases:
│ ├── QuestDB: Hot OHLC (90 days)
│ └── Redis: Positions/Signals/State
├── Processes:
│ ├── Live Trading (cores 0-3)
│ ├── Paper Trading (cores 4-6)
│ └── Shared Services (core 7)
└── Network: 1GbE (sufficient for trading)
---
12900K - DATA PIPELINE & ANALYTICS
├── Purpose: ML, Backtesting, Data Processing
├── Hardware: 16C/24T, 64GB RAM, Multi-NVMe
├── Databases:
│ ├── PostgreSQL: Metadata/Fundamentals
│ ├── MongoDB: Raw provider data (8GB cache limited ✓)
│ └── QuestDB: Historical features
├── Processes:
│ ├── Data Pipeline
│ ├── ML Training
│ ├── Backtesting Engine
│ └── Dask Workers
└── Network: 10GbE (planned)
## 1. Host Inventory
TRUENAS - STORAGE
├── Purpose: Cold Storage, Backups, Archives
├── Hardware: 6700K, 32TB (6x8TB RAIDZ1), 2.5GbE
├── Services:
│ ├── MinIO/S3: Parquet files
│ ├── Frigate: 2 cameras + Google Coral
│ └── Backup targets
└── Consideration: RAIDZ1 → RAIDZ2 upgrade
| Host | Hardware | OS & Storage | Primary Role |
| --- | --- | --- | --- |
| **`quant` (`12900K`)** (`10.0.0.51`) | Intel Core i9-12900K (16C / 24T), 125 GiB RAM | Ubuntu 24.04 LTS; OS NVMe + **4 TB WD Black SN850X NVMe** mounted at `/mnt/data` (`/home/boki/stockbot` → `/mnt/data/stockbot`, Docker `data-root: /mnt/data/docker`) | Primary QA/Research stack: raw MongoDB corpus, PostgreSQL security master & `trial_ledger`, curated Hive Parquet + DuckDB store, QuestDB `10.2.0` intraday store, `data-pipeline`, `data-ingestion`, `orchestrator`, `web-api`, `web-app`, monitoring |
| **`9900K` (ITX)** | Intel Core i9-9900K (8C / 16T), 32 GB RAM, 1 GbE | Ubuntu 24.04 LTS, local NVMe | **Isolated Paper & Live Execution Host (`Milestone M5`):** headless `ib-gateway` (IBC), Python `ib-bridge` (`ib_async`), execution `orchestrator` + Rust `engine`, local Dragonfly state, hot rolling bar window. Zero research jobs or agent shell access |
| **`TrueNAS` (`6700K`)** | Intel Core i7-6700K, 32 TB ZFS (`6×8 TB`), 2.5 GbE | TrueNAS SCALE, MinIO (S3-compatible) | Cold backups: immutable curated Parquet dataset snapshots, PostgreSQL `pg_dump` backups, `trial_ledger` & air-gapped vault archives |
| **`Proxmox` (`8945HS`)** | AMD Ryzen 9 8945HS (8C / 16T) | Proxmox VE | Network & shared infrastructure: OPNsense, GitLab, Pi-hole |
| **Workstation (local)** | Developer desktop | Linux | Interactive code editing, `docker-compose.dev.yml` isolated dev stack, local `marimo` notebooks (`127.0.0.1:2718`), Claude Code & Studio copilot agents |
PROXMOX - INFRASTRUCTURE
├── Hardware: Ryzen 9 8945HS, 8C/16T
├── VMs/Containers:
│ ├── OPNSense: 4 threads (reduced from 8)
│ ├── GitLab: 3 threads
│ ├── Pihole: 1 thread
│ └── Monitoring: 4 threads (Prometheus/Grafana/Loki)
└── Purpose: Network, CI/CD, Monitoring
```
---
### **📊 Data Flow**
## 2. `quant` (`10.0.0.51`) Service & Port Map
```
1. INGESTION: Providers → 12900K MongoDB/Pipeline
2. PROCESSING: Raw → Features → 12900K QuestDB
3. HOT SYNC: Last 90 days → 9900K QuestDB
4. TRADING: 9900K reads hot data → Execute trades
5. ARCHIVE: Old data → TrueNAS MinIO (Parquet)
```
All 16 containers run from `/mnt/data/stockbot` (`docker compose --env-file .env.quant -f docker-compose.yml -f docker-compose.quant.yml`):
### **🔑 Key Design Decisions**
| Category | Container / Service | Host Port(s) | Notes |
| --- | --- | --- | --- |
| **UI & API** | `web-app` (Nginx) | `80`, `5173` | React dashboard & `/api` reverse proxy to `web-api` |
| | `web-api` | `2003` | Research API, dataset/trial admission, WebSocket updates |
| | `orchestrator` | `2004` | Durable research & backtest workers (Rust `engine` N-API addon) |
| **Data Services** | `data-ingestion` | `2001` | Provider crawlers writing raw collections to MongoDB |
| | `data-pipeline` | `2002` | Reads MongoDB strictly via `MONGODB_READ_URI` (`mongoReadOnly: true`); writes PostgreSQL master tables + curated Parquet/QuestDB |
| **Databases** | `mongodb` (`stock`) | `27017` | ~638 GB multi-billion-doc raw corpus (`wiredTigerCacheSizeGB` bounded). **Never drop or write from `dev`/tests** |
| | `postgres` (`trading_bot`) | `5432` | Security master, `trial_ledger`, backtests, promotions, `vault_evaluations` |
| | `questdb` (`10.2.0`) | `9000` (HTTP/UI), `8812` (PGWire), `9009` (ILP) | Intraday `1m`/`5m`/`1h` & hot streaming bars (`listing_id SYMBOL CAPACITY 65536 NOCACHE`) |
| | `dragonfly` | `6379` | BullMQ queues, pub/sub, ephemeral cache |
| **Curated Files** | `/mnt/data/stockbot/curated/` | Host NVMe | Hive-partitioned Parquet (`bars_1d`, `corporate_actions`, `fundamentals_pit`, `earnings_events_pit`, `short_interest_pit`, `macro_pit`, `fx_rates_1d`, `features/`) queried in-process via DuckDB |
| **Ops & Admin** | `grafana` | `3000` | Dashboards (`prometheus` + `loki`) |
| | `bull-board` | `3001` | BullMQ job queue inspector |
| | `loki` / `prometheus` | `3100` / `9090` | Centralized logs (`promtail`) & metrics |
| | `pgadmin` / `mongo-express` | `5050` / `8081` | Database admin UIs (LAN-only) |
```python
architecture_principles = {
"Isolation": "Live/Paper completely separated",
"Performance": "Hot data on NVMe, cold on HDD",
"Scalability": "200K symbols, 40+ years data",
"Processing": "Dask over Spark (Python native)",
"Safety": "Live trading NEVER competes for resources"
}
```
---
### **💾 Database Strategy**
## 3. Local Development vs `quant` Separation
| Database | Location | Purpose | Size |
|----------|----------|---------|------|
| QuestDB | 9900K | Hot OHLC/Ticks | ~200GB |
| Redis | 9900K | Live State | ~2GB |
| PostgreSQL | 12900K | Metadata/Config | ~100GB |
| MongoDB | 12900K | Raw Data (8GB cache) | ~500GB |
| QuestDB | 12900K | Historical | ~500GB |
| MinIO | TrueNAS | Archives | ~TBs |
| Environment | Compose File | PostgreSQL | MongoDB (Write) | MongoDB (Read / Pipeline) | Dragonfly | QuestDB |
| --- | --- | --- | --- | --- | --- | --- |
| **`dev` (workstation)** | `docker-compose.dev.yml` | `localhost:5433` (`trading_bot_dev`) | `localhost:27018` (`stock_dev`) | `quant:27017` or `localhost:27017` (`stock`, **read-only** via `MONGODB_READ_URI`) | `localhost:6380` | `localhost:9100` |
| **`qa` (`quant`)** | `docker-compose.yml` + `docker-compose.quant.yml` | `10.0.0.51:5432` (`trading_bot`) | `10.0.0.51:27017` (`stock`) | `10.0.0.51:27017` (`stock`, `MONGODB_READ_URI` for `data-pipeline`) | `10.0.0.51:6379` | `10.0.0.51:9000` |
| **Paper / Live (`9900K`)** | `docker-compose.prod.yml` (`M5`) | Isolated execution DB | None | Curated artifact pull only | Local `:6379` | Local `:9000` (90d hot window) |
### **🚀 Performance Optimizations**
> **Offline Local Snapshot:** The workstation's pre-migration Docker containers (`trading-bot-*`) are intentionally stopped with their local Docker volumes preserved untouched as a cold local fallback.
```yaml
Completed:
✓ MongoDB cache limited to 8GB
✓ CPU affinity for live/paper trading
✓ Network architecture planned
✓ Database separation by access pattern
✓ Ubuntu 24.04 LTS chosen
---
Next Steps:
- Set up Dask cluster on 12900K
- Implement data sync pipeline
- Configure monitoring stack
- Test 20-year backtest performance
```
## 4. Isolation & Resource Rules
### **📈 Capacity**
```
- Symbols: 200,000 total (10-20K active)
- History: 40+ years
- Storage: 32TB available
- Backtest: 20 years feasible in ~2 days
- Live latency: <1ms target
```
Your infrastructure is well-designed for institutional-grade algo trading with proper separation of concerns and room to scale! The MongoDB fix freed up significant resources for actual trading/analysis work.
1. **Live/Paper Never Competes with Research:** `9900K` runs only execution processes (`ib-gateway`, `ib-bridge`, execution `orchestrator`, local Dragonfly/QuestDB). Heavy DuckDB sweeps, CPCV folds, and `data-pipeline` backfills run exclusively on `quant` (`12900K`).
2. **Air-Gapped Holdout Storage:** On `quant`, the rolling 6-month vault partition (`/mnt/data/stockbot/vault/`) is readable only by the `vault-evaluator` OS/container user, never mounted into `marimo`, agent containers, or `web-api` research workers.
3. **MongoDB Cache Discipline:** Keep MongoDB WiredTiger cache bounded on `quant` so OS page cache, DuckDB, PostgreSQL, and QuestDB retain ample headroom across the 125 GiB RAM pool.