From 3505cf4ade52d380603e045641ea3447e1e455db Mon Sep 17 00:00:00 2001 From: shokollm <270575765+shokollm@users.noreply.github.com> Date: Sat, 11 Apr 2026 23:52:00 +0000 Subject: [PATCH] refactor: simplify simulation to run forever as paper trade - No duration limit - runs forever until user stops - Only 1 running simulation per bot (returns existing if already running) - Always paper trade (no auto-execute option) - Removed Pro upgrade banner - Removed duration and auto-execute config options - Simplified API to only require token, chain, check_interval --- src/backend/app/api/simulate.py | 16 ++++++++-- src/backend/app/db/schemas.py | 2 -- src/backend/app/services/simulate/engine.py | 11 +++---- src/frontend/src/lib/api/client.ts | 2 +- .../src/routes/bot/[id]/simulate/+page.svelte | 29 ++----------------- 5 files changed, 22 insertions(+), 38 deletions(-) diff --git a/src/backend/app/api/simulate.py b/src/backend/app/api/simulate.py index 8d3fbcf..d04bb45 100644 --- a/src/backend/app/api/simulate.py +++ b/src/backend/app/api/simulate.py @@ -124,6 +124,19 @@ async def start_simulation( status_code=status.HTTP_403_FORBIDDEN, detail="Not authorized" ) + # Check if there's already a running simulation for this bot + existing_simulation = ( + db.query(Simulation) + .filter(Simulation.bot_id == bot_id, Simulation.status == "running") + .first() + ) + if existing_simulation: + # Return existing running simulation + if existing_simulation.id in running_simulations: + engine = running_simulations[existing_simulation.id] + existing_simulation.signals = engine.get_signals() + return existing_simulation + settings = get_settings() simulation_id = str(uuid.uuid4()) @@ -135,9 +148,8 @@ async def start_simulation( "bot_id": bot_id, "token": config.token, "chain": config.chain, - "duration_seconds": config.duration_seconds, "check_interval": check_interval, - "auto_execute": config.auto_execute, + "auto_execute": False, # Always paper trade "strategy_config": bot.strategy_config, "ave_api_key": settings.AVE_API_KEY, "ave_api_plan": settings.AVE_API_PLAN, diff --git a/src/backend/app/db/schemas.py b/src/backend/app/db/schemas.py index 59b87f3..9f3f443 100644 --- a/src/backend/app/db/schemas.py +++ b/src/backend/app/db/schemas.py @@ -100,9 +100,7 @@ class BacktestResponse(BaseModel): class SimulationCreate(BaseModel): token: str chain: str - duration_seconds: int = 3600 check_interval: int = 60 - auto_execute: bool = False @field_validator("chain") @classmethod diff --git a/src/backend/app/services/simulate/engine.py b/src/backend/app/services/simulate/engine.py index 3996809..90a1f4a 100644 --- a/src/backend/app/services/simulate/engine.py +++ b/src/backend/app/services/simulate/engine.py @@ -59,10 +59,9 @@ class SimulateEngine: self.results = {"error": "Token ID is required"} return self.results - end_time = datetime.utcnow().timestamp() + self.duration_seconds - + # Run forever until stopped (no end_time limit) try: - while self.running and datetime.utcnow().timestamp() < end_time: + while self.running: try: price_data = await self.ave_client.get_token_price(token_id) if price_data: @@ -87,10 +86,8 @@ class SimulateEngine: break await asyncio.sleep(1) - if self.running: - self.status = "completed" - else: - self.status = "stopped" + # Simulation was stopped + self.status = "stopped" except Exception as e: self.status = "failed" diff --git a/src/frontend/src/lib/api/client.ts b/src/frontend/src/lib/api/client.ts index 2d591b8..ae22314 100644 --- a/src/frontend/src/lib/api/client.ts +++ b/src/frontend/src/lib/api/client.ts @@ -189,7 +189,7 @@ export const api = { }, simulate: { - async start(botId: string, config: { token: string; chain?: string; check_interval: number; duration_seconds: number; auto_execute: boolean }): Promise { + async start(botId: string, config: { token: string; chain?: string; check_interval: number }): Promise { const response = await fetch(`${API_URL}/bots/${botId}/simulate`, { method: 'POST', headers: getAuthHeaders(), diff --git a/src/frontend/src/routes/bot/[id]/simulate/+page.svelte b/src/frontend/src/routes/bot/[id]/simulate/+page.svelte index e6c2435..765de33 100644 --- a/src/frontend/src/routes/bot/[id]/simulate/+page.svelte +++ b/src/frontend/src/routes/bot/[id]/simulate/+page.svelte @@ -4,14 +4,12 @@ import { goto } from '$app/navigation'; import { isAuthenticated, isLoading, currentBotStore, setCurrentBot, simulationStore, setCurrentSimulation, addSignals, clearSignals, setSimulationLoading, setSimulationError } from '$lib/stores'; import { api } from '$lib/api'; - import { SignalChart, ProUpgradeBanner } from '$lib/components'; + import { SignalChart } from '$lib/components'; let botId = $derived($page.params.id); let tokenName = $state(''); let tokenAddress = $state(''); let intervalSeconds = $state(60); - let durationSeconds = $state(300); // 5 minutes default - let autoExecute = $state(false); let isRunning = $state(false); onMount(async () => { @@ -70,9 +68,7 @@ const simulation = await api.simulate.start(botId, { token: tokenAddress, chain: 'bsc', - check_interval: intervalSeconds, - duration_seconds: durationSeconds, - auto_execute: autoExecute + check_interval: intervalSeconds }); setCurrentSimulation(simulation); clearSignals(); @@ -133,33 +129,16 @@ {/if} -
- - -
- - -
-
- - -
- {#if isRunning}