feat: wire live decision loop and enable paper trading

Phase 2 of the autonomous trading engine:

- Replace start()/stop() stubs with real async implementations
- Decision loop: polls recommendations from PostgreSQL, deduplicates
  via Redis, evaluates through the full pipeline, submits orders to
  stonks:queue:broker_orders
- Stop-loss monitor: fetches prices from Polygon API, checks crossings,
  submits immediate sell orders, safety sell after 15 min without data
- Performance loop: computes metrics every 5 min during market hours,
  persists daily snapshots at market close
- Risk tier scheduler: evaluates daily at 16:00 ET, persists tier changes
- Rebalance scheduler: evaluates Monday 09:45 ET, respects circuit breaker
- Notification dispatch: SNS + Gmail with rate limiting and retry
- Backtest replay: fetches historical data, simulates decisions, persists
- Real asyncpg/redis connections in FastAPI lifespan (graceful degradation)
- Migration 019: enable paper trading with conservative tier, 5 cap
- Added max_open_positions to TradingConfig with env var loading
- Phase 2 tasks added to autonomous-trading-engine spec
This commit is contained in:
Celes Renata
2026-04-15 20:52:28 +00:00
parent c4b90a5224
commit 70bad7709a
8 changed files with 2159 additions and 28 deletions
+4
View File
@@ -208,6 +208,10 @@ config:
ALERT_BROKER_ERROR_THRESHOLD: "3"
ALERT_BROKER_ERROR_WINDOW_HOURS: "1"
ALERT_CHECK_INTERVAL_SECONDS: "120"
TRADING_ENABLED: "true"
TRADING_RISK_TIER: "conservative"
TRADING_ABSOLUTE_POSITION_CAP: "25.0"
TRADING_MAX_OPEN_POSITIONS: "5"
## Secrets
secrets:
@@ -0,0 +1,9 @@
-- Migration 019: Enable paper trading configuration
-- Sets conservative defaults for initial paper trading deployment.
-- Requirements: 16.1, 5.1
UPDATE trading_engine_config
SET enabled = true,
risk_tier = 'conservative',
absolute_position_cap = 25.0,
max_open_positions = 5;