Kevin's signals are mid-long term (weeks/months) and he uploads almost
exclusively pre-market or evenings. Before this change, every such
signal hit RiskManager.outside_market_hours, got consumed off the
Redis stream, and was lost. End result: 71 emitted signals, 0 trades.
New behaviour: when RiskManager rejects with outside_market_hours,
push the signal into a Redis sorted-set keyed by next_market_open
(via Alpaca's clock API — handles weekends + holidays). A background
drain task polls the set every kevin_defer_drain_interval_s (60s);
any signal whose target <= now gets re-run through process_signal.
Safety:
- kevin_max_defer_hours (default 72h) caps signal staleness so we
don't trade on week-old views.
- Other RiskManager rejections (cooldown, kill-switch, drawdown
halt) fall through to the existing drop path.
- kevin_defer_outside_market_hours toggle defaults True; flip to
false for legacy behaviour.
Slack: new notify_deferred() emits "🕒 Meet Kevin: DEFERRED
NVDA until Mon 13:30 UTC (market closed; conviction 0.85)" instead
of the noisy outside_market_hours rejection spam.
Tests: 5 queue + 4 integration = 9 new, all 32 trade-executor tests
GREEN.
43 lines
1.7 KiB
Python
43 lines
1.7 KiB
Python
"""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
|
|
|
|
# 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
|
|
|
|
# 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.
|
|
slack_webhook_url: str = ""
|
|
slack_bot_token: str = ""
|
|
slack_channel: str = ""
|
|
|
|
# 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
|
|
|
|
model_config = {"env_prefix": "TRADING_"}
|