fix: risk engine now allows sells on over-concentrated positions
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/build-1 Pipeline failed
ci/woodpecker/push/build-2 Pipeline was successful
ci/woodpecker/push/build-3 Pipeline failed
ci/woodpecker/push/finalize unknown status
Build and Push / lint-and-test (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.adapters.broker_adapter name:broker-adapter]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.aggregation.worker name:aggregation]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.extractor.worker name:extractor]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.ingestion.worker name:ingestion]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.lake_publisher.worker name:lake-publisher]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.parser.worker name:parser]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.recommendation.worker name:recommendation]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.scheduler.app name:scheduler]) (push) Has been cancelled
Build and Push / build-services (map[cmd:uvicorn services.api.app:app --host 0.0.0.0 --port 8000 name:query-api]) (push) Has been cancelled
Build and Push / build-services (map[cmd:uvicorn services.risk.app:app --host 0.0.0.0 --port 8000 name:risk]) (push) Has been cancelled
Build and Push / build-services (map[cmd:uvicorn services.symbol_registry.app:app --host 0.0.0.0 --port 8000 name:symbol-registry]) (push) Has been cancelled
Build and Push / build-services (map[cmd:uvicorn services.trading.app:app --host 0.0.0.0 --port 8000 name:trading-engine]) (push) Has been cancelled
Build and Push / build-dashboard (push) Has been cancelled
Build and Push / build-superset (push) Has been cancelled
Build and Push / integration-test (push) Has been cancelled
Build and Push / beta-gate (push) Has been cancelled

This commit is contained in:
Celes Renata
2026-04-21 20:25:02 +00:00
parent 5dcbd286e8
commit 3b49aa2fa2
2 changed files with 22 additions and 1 deletions
+18
View File
@@ -254,6 +254,24 @@ def test_position_pct_exceeded():
assert any(c.check_name == "max_position_pct" and c.result == RiskCheckResult.FAIL for c in result.checks)
def test_sell_on_over_limit_position_allowed():
"""Selling an over-concentrated position should pass risk checks."""
config = _make_config(position_limits=PositionLimits(max_position_pct=0.05))
state = _make_state(
portfolio_value=100_000,
positions_by_symbol={"AVGO": 5200.0}, # 5.2% — over the 5% limit
)
order = ProposedOrder(
ticker="AVGO", sector="Technology", action="sell",
estimated_value=5200.0, quantity=13,
)
result = evaluate_order(order, config, state)
pct_check = next(c for c in result.checks if c.check_name == "max_position_pct")
assert pct_check.result == RiskCheckResult.PASS, (
f"Sell on over-limit position should pass, got: {pct_check.message}"
)
def test_max_shares_exceeded():
config = _make_config(position_limits=PositionLimits(max_shares_per_order=100))
order = ProposedOrder(ticker="AAPL", sector="Technology", estimated_value=1000, quantity=200)