Bracket stop-loss/take-profit legs fill at Alpaca without passing through the executor, so those closes (and their P&L) were invisible locally.
- broker: add get_order(nested) + list_orders to BaseBroker/AlpacaBroker (+ SimulatedBroker); BrokerOrder carries child legs
- Trade gains broker_order_id (migration f6a7b8c9d0e1); executor stamps the entry order id
- new api_gateway trade-reconcile loop: books a closing SELL + realized P&L when a bracket leg fills (idempotent on the leg order id), syncs PENDING->terminal status, logs drift; runs alongside portfolio_sync
[ci skip]
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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).