T09 · Insecure Skill Coding Practices
- Location
scripts/risk_manager.py:145- Finding
Market Orders Bypass Monetary Risk Limits When Price Is Missing
- Content
View full analysis
max_order: raise RiskLimitExceeded( "max_order_size", f"Order cost {estimated_cost:.2f} EUR exceeds max " f"{max_order:.2f} EUR for strategy '{strategy}'." ) max_open = self._get_limit(strategy, "max_open_orders") if max_open and open_order_count >= max_open: raise RiskLimitExceeded( "max_open_orders", f"Already {open_order_count} open orders (max {max_open}) " f"for strategy '{strategy}'." ) if side == "buy" and portfolio_value_eur > 0: max_pos_pct = self._get_limit(strategy, "max_position_size_pct") if max_pos_pct: pos_pct = (estimated_cost / portfolio_value_eur) * 100 if pos_pct > max_pos_pct: raise RiskLimitExceeded( "max_position_size", f"Position would be {pos_pct:.1f}% of portfolio " f"(max {max_pos_pct:.1f}%)." ) ``` ```python # scripts/strategies/dca.py amount = self.amount_per_buy / current_price return [{ "symbol": self.symbol, "side": "buy", "amount": round(amount, 8), "price": None, "order_type": "market", "exchange": self.exchange, "reason": ( f"DCA buy #{self.buy_count + 1}: {self.amount_per_buy:.2f} USDT " f"of {self.symbol} at {current_price:.2f} " f"(avg: {self.avg_price:.2f}, total: {self.total_invested:.2f} USDT)" ), }] ``` ### Technical Analysis The risk manager treats an absent market-order price as zero. Consequently, every market order with `price ...[truncated 1624 chars]- Remediation
View remediation
