fix: risk engine blocking sell orders on over-concentrated positions

Two bugs: (1) trading engine omitted estimated_value from sell order
jobs, causing risk engine to compute 0 reduction; (2) risk engine
applied position size limits to sells, trapping users in positions
they couldn't exit. Sells now always pass position value/pct checks.
This commit is contained in:
Celes Renata
2026-04-22 02:07:24 +00:00
parent 3b49aa2fa2
commit f251c53f92
2 changed files with 34 additions and 13 deletions
+5 -1
View File
@@ -728,6 +728,7 @@ class TradingEngine:
"side": "sell",
"quantity": sell_qty,
"order_type": "market",
"estimated_value": estimated_proceeds,
"source": "trading_engine",
}
if self.redis is not None:
@@ -1813,14 +1814,17 @@ class TradingEngine:
self.portfolio_state.active_pool += current * qty
async def _submit_sell_order(
self, ticker: str, quantity: int, reason: str
self, ticker: str, quantity: int, reason: str,
estimated_value: float = 0.0,
) -> None:
"""Push a sell order to the broker queue via Redis."""
order_job = {
"ticker": ticker,
"action": "sell",
"side": "sell",
"quantity": quantity,
"order_type": "market",
"estimated_value": estimated_value,
"source": "trading_engine",
"reason": reason,
}