Commit graph

3 commits

Author SHA1 Message Date
Viktor Barzin
065b634b99 feat(trade-executor): Slack bot-token transport + semver image tags
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Two changes that ship together so a single CI run lands both:

1) SlackNotifier — support bot-token + channel transport
   - Previous version only supported a pinned webhook URL.
   - New mode uses chat.postMessage with bot_token + channel.
   - Channel can be changed via env var without rotating webhooks.
   - bot-token transport wins when both are set.
   - Fail-soft: ok=false (e.g. channel_not_found if the user
     hasn't created #trading-bot yet) is logged + skipped, not
     raised.
   - 5 new tests (10 total): bot-token wins, channel_not_found
     swallowed, headers/payload shape verified.

2) Image tags — switch from :${CI_PIPELINE_NUMBER} → :0.1.${N}
   - 3-part semver so Keel patch policy (cluster-wide default
     in inject-keel-annotations) is bounded to patch bumps
     within 0.1.x. Prior 1-part tags (:53) were technically
     parseable as major-only, which Keel patch wouldn't bump
     but could still resolve oddly under digest tracking.
   - Memory id=1935 documents Keel patch ≠ bulletproof for
     non-semver; semver tags are the safer mode.
   - update-deployment + verify-deploy steps updated to match.
   - :latest still pushed for cache-from + bootstrap.
2026-05-27 10:06:49 +00:00
Viktor Barzin
382188a19b feat(trade-executor): Slack notifications on trade + risk-rejection
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
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
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