Commit graph

5 commits

Author SHA1 Message Date
Viktor Barzin
f7ca671bf3 feat(phase2): BRACKET orders + Kevin risk caps (Tasks 18, 19)
Some checks failed
ci/woodpecker/push/woodpecker Pipeline was canceled
Task 18 — OrderRequest + AlpacaBroker BRACKET support:
- OrderRequest gains order_class ("simple" | "bracket"),
  take_profit_price, stop_loss_price + model_validator that requires
  both legs when order_class == "bracket".
- AlpacaBroker._build_order_request branches to a MarketOrderRequest
  with OrderClass.BRACKET + TakeProfitRequest + StopLossRequest legs,
  TimeInForce.GTC so the bracket survives day boundaries.

Task 19 — RiskManager Kevin caps + circuit-breaker:
- TradeExecutorConfig gains 4 fields: kevin_daily_trade_cap,
  kevin_daily_alloc_cap_usd, kevin_equity_drawdown_halt_pct,
  kevin_daily_loss_circuit_pct.
- check_risk() applies the caps only when
  signal.strategy_id == KEVIN_STRATEGY_UUID; non-Kevin signals pass
  through the existing path unchanged.
- 4 new checks in order: drawdown halt (sets permanent
  trading:paused), daily-loss circuit (setex 24h), daily trade-count
  cap, daily allocation cap (rolling today's $ + this trade's
  notional).
- Counter keys: kevin:daily_trades:YYYY-MM-DD,
  kevin:daily_alloc_usd:YYYY-MM-DD, kevin:daily_pnl_usd:YYYY-MM-DD,
  kevin:starting_equity_usd. All read-only here; bridge + executor
  write them.

Tests: 5 bracket + 9 kevin-caps + 28 regression-safe. Total 67 + 14
new = 81 passing (excluding -m integration). No DB needed.
2026-05-26 21:03:59 +00:00
Viktor Barzin
bc479802db test(kevin): fix enum assertion + mark Postgres-dependent tests as integration
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Pipeline #46 surfaced two pre-existing CI bugs once fakeredis was
installed and tests could collect:

1. test_models.py:389 asserted "DISCOVERED" in status_col.type.enums,
   but the model defines KevinVideoStatus with values_callable so
   .enums returns the lowercase string values, not member names.
   Asserting "discovered" instead.

2. Four test files use the db_session fixture which requires a real
   Postgres on localhost:5432. CI has no Postgres, so 10 tests failed
   with Connect call failed (errno 111). These genuinely need a DB —
   mirroring tests/integration/* which already use
   @pytest.mark.integration. Adding module-level
   pytestmark = pytest.mark.integration to:
   - tests/shared/models/test_meet_kevin_trading.py
   - tests/services/kevin_signal_bridge/test_aggregator.py
   - tests/services/kevin_signal_bridge/test_audit.py
   - tests/services/kevin_signal_bridge/test_exit_scanner.py

CI runs with -m "not integration" so they're now deselected.
Local pytest still picks them up by default (no marker filter).
2026-05-26 20:01:37 +00:00
7dcce5ea0e feat(kevin): KevinStrategy standalone decision logic
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Stateless: mention + account_state -> KevinDecision. Conviction-weighted
sizing, time_horizon-derived hold periods, hard per-ticker cap. The
bridge and the backtest mini-engine both call evaluate_mention so
behaviour cannot drift.
2026-05-24 00:51:31 +00:00
4d40536da7 feat(kevin): SA models for bridge audit + backtest persistence
Some checks failed
ci/woodpecker/push/woodpecker Pipeline was canceled
3 tables (kevin_signal_bridge_state, kevin_backtest_runs,
kevin_backtest_trades) all UUID-keyed for consistency with Trade/Position.
KEVIN_STRATEGY_UUID constant pinned for FK joins from Trade.strategy_id.
2026-05-24 00:49:52 +00:00
9d752aa0a2 feat(kevin): KevinDecision + KevinAccountState schemas
Some checks failed
ci/woodpecker/push/woodpecker Pipeline was canceled
Standalone schemas (no BaseStrategy coupling) used by both the live
signal bridge and the backtest mini-engine.
2026-05-24 00:44:57 +00:00