T09 · Insecure Skill Coding Practices
Error
- Location
- trader.py:303
- Finding
- Declared Minimum-Volume Safeguard Is Not Enforced<![CDATA[ ## Vulnerability Details **File Location**: `trader.py:42`, `trader.py:303-321`, and `trader.py:374-388` **Vulnerability Type**: Missing enforcement of a configured trading safeguard **Risk Level**: High ### Vulnerable Code The minimum-volume setting is loaded: ```python MIN_VOLUME = float(os.environ.get("SIMMER_MIN_VOLUME", "5000")) ``` However, market validation does not inspect market volume: ```python def valid_market(market) -> tuple[bool, str]: p = getattr(market, "current_probability", None) if not isinstance(p, (int, float)): return False, "missing probability" spread_cents = getattr(market, "spread_cents", None) if isinstance(spread_cents, (int, float)) and spread_cents / 100 > MAX_SPREAD: return False, f"Spread {spread_cents/100:.1%} > {MAX_SPREAD:.1%}" resolves_at = getattr(market, "resolves_at", None) if resolves_at: try: resolves = datetime.fromisoformat(resolves_at.replace("Z", "+00:00")) days = (resolves - datetime.now(timezone.utc)).days if days < MIN_DAYS: return False, f"Only {days} days to resolve" except Exception: pass return True, "ok" ``` Market discovery likewise adds markets without enforcing the configured volume threshold: ```python def find_markets(client: SimmerClient) -> list: """Find active crypto price-threshold markets, deduplicated. Filters out non-threshold markets (e.g. 'Up or Down' coin-flips).""" seen, unique = set(), [] for kw in KEYWORDS: try: for m in client.find_markets(query=kw): market_id = getattr(m, "id", None) if market_id and market_id not in seen: q = getattr(m, "question", "").lower() if any(w in q for w in ("above", "between", "reach", "hit", "dip", "below", "exceed")): seen.add(market_id) unique.append(m) e ...[truncated 1641 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions Enforce volume as a mandatory validation condition before signal calculation: ```python def valid_market(market) -> tuple[bool, str]: p = getattr(market, "current_probability", None) if not isinstance(p, (int, float)): return False, "missing probability" volume = getattr(market, "volume", None) if not isinstance(volume, (int, float)): return False, "missing market volume" if volume < MIN_VOLUME: return False, f"Volume ${volume:,.2f} < ${MIN_VOLUME:,.2f}" # Existing spread and resolution checks follow. ``` Use the exact SDK field representing executable or recent volume rather than assuming the field name. Prefer checking order-book depth at the intended order size in addition to aggregate volume. Further hardening should include: - Fail closed when volume or liquidity information is unavailable. - Validate effective execution price immediately before submission. - Set an order-specific maximum slippage. - Add tests proving that markets below `SIMMER_MIN_VOLUME` cannot reach `client.trade()`. ]]>
