From d4400f5dcd67a026ce18bbb10edb906cbc7cf80a Mon Sep 17 00:00:00 2001 From: shokollm <270575765+shokollm@users.noreply.github.com> Date: Sun, 12 Apr 2026 00:53:05 +0000 Subject: [PATCH] fix: simulation conditions now check properly from first iteration The first price check was always skipped because last_price was None. Now first iteration primes last_price, subsequent iterations check conditions. --- src/backend/app/services/simulate/engine.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/backend/app/services/simulate/engine.py b/src/backend/app/services/simulate/engine.py index 90a1f4a..0660f45 100644 --- a/src/backend/app/services/simulate/engine.py +++ b/src/backend/app/services/simulate/engine.py @@ -69,12 +69,14 @@ class SimulateEngine: current_volume = float(price_data.get("volume", 0)) if current_price > 0: - await self._check_conditions( - current_price, current_volume, price_data - ) - - self.last_price = current_price - self.last_volume = current_volume + # Only check conditions if we have a previous price to compare + if self.last_price is not None: + await self._check_conditions( + current_price, current_volume, price_data + ) + # Update last price AFTER checking (so next iteration has comparison data) + self.last_price = current_price + self.last_volume = current_volume except Exception as e: logger.warning(f"Failed to get price for {token_id}: {e}")