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:
@@ -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,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user