trading/services/trade_executor/config.py
Viktor Barzin 382188a19b
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
feat(trade-executor): Slack notifications on trade + risk-rejection
SlackNotifier posts a short message to a Slack incoming webhook on:
  - trade-executor submits an order (filled or pending)
  - RiskManager rejects a signal (except outside_market_hours, which
    spams every poll when the bot tries to trade after-hours)

Key properties:
  - No-op when slack_webhook_url is empty (fail-soft default).
  - HTTP errors are swallowed — a Slack outage MUST NOT crash the
    consumer loop; the trade already happened on Alpaca.
  - Kevin-strategy signals tagged "Meet Kevin" in the message so I can
    tell which strategy fired.

Wiring:
  - TradeExecutorConfig.slack_webhook_url + TRADING_SLACK_WEBHOOK_URL
    env var, sourced from Vault secret/trading-bot/slack_webhook_url
    via existing ExternalSecret.
  - SlackNotifier passed to process_signal; both rejection + post-trade
    paths call it.

Tests: 7 new (no-op when disabled, post calls webhook with correct
text, Kevin strategy tag, swallows HTTP errors, suppresses noisy
rejections).
2026-05-26 21:55:55 +00:00

28 lines
973 B
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 webhook for per-trade notifications (empty → notifier no-ops).
slack_webhook_url: str = ""
model_config = {"env_prefix": "TRADING_"}