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
This commit is contained in:
shokollm
2026-04-11 23:52:00 +00:00
parent 1b1358353f
commit 3505cf4ade
5 changed files with 22 additions and 38 deletions

View File

@@ -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,

View File

@@ -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

View File

@@ -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"