T09 · Insecure Skill Coding Practices
- Location
src/trader.py:251- Finding
Live Positions Are Recorded as Closed Without Executing an Exchange Exit Order
- Content
View full analysis
= position.stop_loss: self._close_position(position, current_price, "STOP_LOSS") return # Check take profits for tier in position.take_profits: if tier["hit"]: continue tp_price = tier["price"] if (position.side == "BUY" and current_price >= tp_price) or \ (position.side == "SELL" and current_price <= tp_price): # In real trading, this would partially close the position tier["hit"] = True logging.info(f"Take profit hit for {position.symbol} at ${tp_price:.2f}") # If all TPs hit, close position if all(t["hit"] for t in position.take_profits): self._close_position(position, current_price, "TAKE_PROFIT") def _close_position(self, position: Position, exit_price: float, reason: str): """Close a position.""" # Calculate P&L if position.side == "BUY": pnl = (exit_price - position.entry_price) * position.quantity pnl_percent = (exit_price - position.entry_price) / position.entry_price * 100 else: pnl = (position.entry_price - exit_price) * position.quantity pnl_percent = (position.entry_price - exit_price) / position.entry_price * 100 # Update database conn = sqlite3.connect(self.db_path) cursor = conn.cursor() cursor.execute(""" UPDATE trades SET ...[truncated 2720 chars]- Remediation
View remediation
