fix: resolve 13 important issues from code review
I1: Add graceful shutdown (SIGTERM/SIGINT) to all 5 background services I2: Fix Dockerfile healthcheck to use curl on /metrics endpoint I3: Fix StreamConsumer.ensure_group() to only catch BUSYGROUP errors I4: Fix SimulatedBroker to reject orders with insufficient cash/shares I5: Move ORM attribute access inside DB session context in trades routes I6: Add Redis-based rate limiting (10 req/min/IP) on all auth endpoints I8: Prevent backtest background task garbage collection I9: Use Numeric(16,6) instead of Float for financial columns in migration I10: Add index on trades.created_at for time-range queries I11: Bind infrastructure ports to 127.0.0.1 in docker-compose I12: Add migrations init service; all app services depend on it I13: Fix user enumeration in login_begin (return options for non-existent users)
This commit is contained in:
parent
2a56727267
commit
5a6b20c8f1
13 changed files with 355 additions and 188 deletions
|
|
@ -93,10 +93,32 @@ class SimulatedBroker(BaseBroker):
|
|||
|
||||
# Deduct / credit cash
|
||||
if order.side == OrderSide.BUY:
|
||||
self.cash -= cost
|
||||
self.cash -= self.commission_per_trade
|
||||
total_cost = cost + self.commission_per_trade
|
||||
if total_cost > self.cash:
|
||||
return OrderResult(
|
||||
order_id=str(uuid.uuid4()),
|
||||
ticker=order.ticker,
|
||||
side=order.side,
|
||||
qty=order.qty,
|
||||
filled_price=None,
|
||||
status=OrderStatus.REJECTED,
|
||||
timestamp=datetime.now(tz=timezone.utc),
|
||||
)
|
||||
self.cash -= total_cost
|
||||
self._update_position_buy(order.ticker, order.qty, fill_price)
|
||||
else:
|
||||
# Validate sufficient shares to sell
|
||||
current_qty = self._positions.get(order.ticker, {}).get("qty", 0.0)
|
||||
if order.qty > current_qty:
|
||||
return OrderResult(
|
||||
order_id=str(uuid.uuid4()),
|
||||
ticker=order.ticker,
|
||||
side=order.side,
|
||||
qty=order.qty,
|
||||
filled_price=None,
|
||||
status=OrderStatus.REJECTED,
|
||||
timestamp=datetime.now(tz=timezone.utc),
|
||||
)
|
||||
self.cash += cost
|
||||
self.cash -= self.commission_per_trade
|
||||
self._update_position_sell(order.ticker, order.qty)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue