2026-02-22 15:36:08 +00:00
|
|
|
"""Configuration for the trade executor service."""
|
|
|
|
|
|
|
|
|
|
from shared.config import BaseConfig
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TradeExecutorConfig(BaseConfig):
|
|
|
|
|
"""Extends BaseConfig with trade-executor-specific settings."""
|
|
|
|
|
|
|
|
|
|
max_position_pct: float = 0.05
|
|
|
|
|
max_total_exposure_pct: float = 0.80
|
|
|
|
|
max_positions: int = 20
|
|
|
|
|
default_stop_loss_pct: float = 0.03
|
|
|
|
|
cooldown_minutes: int = 30
|
|
|
|
|
alpaca_api_key: str = ""
|
|
|
|
|
alpaca_secret_key: str = ""
|
|
|
|
|
paper_trading: bool = True
|
|
|
|
|
|
feat(phase2): BRACKET orders + Kevin risk caps (Tasks 18, 19)
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
|
|
|
# Kevin v2 risk caps — only applied when TradeSignal.strategy_id ==
|
|
|
|
|
# KEVIN_STRATEGY_UUID.
|
|
|
|
|
kevin_daily_trade_cap: int = 10
|
|
|
|
|
kevin_daily_alloc_cap_usd: float = 20_000.0
|
|
|
|
|
kevin_equity_drawdown_halt_pct: float = 0.20 # 20% drawdown → permanent pause
|
|
|
|
|
kevin_daily_loss_circuit_pct: float = 0.05 # 5% daily loss → 24h pause
|
|
|
|
|
|
2026-05-27 10:06:49 +00:00
|
|
|
# Slack notifications — pick ONE transport:
|
|
|
|
|
# 1. Bot token + channel (preferred) → chat.postMessage API
|
|
|
|
|
# 2. Webhook URL (legacy) → single-channel webhook
|
|
|
|
|
# If both set, bot-token wins. If neither, notifier is a no-op.
|
2026-05-26 21:55:55 +00:00
|
|
|
slack_webhook_url: str = ""
|
2026-05-27 10:06:49 +00:00
|
|
|
slack_bot_token: str = ""
|
|
|
|
|
slack_channel: str = ""
|
2026-05-26 21:55:55 +00:00
|
|
|
|
2026-06-01 19:01:37 +00:00
|
|
|
# Kevin v2: defer signals that arrive outside US market hours into a
|
|
|
|
|
# Redis sorted-set and drain at next market open. Kevin's signals are
|
|
|
|
|
# mid/long-term — a Sunday-evening signal should turn into a Monday
|
|
|
|
|
# paper trade, not get dropped. Cap to 72h so we don't replay
|
|
|
|
|
# week-stale signals.
|
|
|
|
|
kevin_defer_outside_market_hours: bool = True
|
|
|
|
|
kevin_max_defer_hours: float = 72.0
|
|
|
|
|
# Drain task polls the deferred queue every kevin_defer_drain_interval_s.
|
|
|
|
|
kevin_defer_drain_interval_s: int = 60
|
|
|
|
|
|
2026-02-22 15:36:08 +00:00
|
|
|
model_config = {"env_prefix": "TRADING_"}
|