Fixed the counting of the series, added a request to set the serial number

This commit is contained in:
algizn97
2025-10-26 19:44:16 +05:00
parent a2164853d9
commit a0ef48810a
3 changed files with 95 additions and 68 deletions

View File

@@ -1171,6 +1171,34 @@ async def set_last_side_by_symbol(tg_id: int, symbol: str, last_side: str):
return False
async def set_current_series(tg_id: int, symbol: str, current_series: int):
"""Set current series for a user deal by symbol in the database."""
try:
async with async_session() as session:
result = await session.execute(select(User).filter_by(tg_id=tg_id))
user = result.scalars().first()
if user is None:
logger.error(f"User with tg_id={tg_id} not found")
return False
result = await session.execute(
select(UserDeals).filter_by(user_id=user.id, symbol=symbol)
)
record = result.scalars().first()
if record:
record.current_series = current_series
else:
logger.error(f"User deal with user_id={user.id} and symbol={symbol} not found")
return False
await session.commit()
logger.info("Set current series for user %s and symbol %s", tg_id, symbol)
return True
except Exception as e:
logger.error("Error setting user deal current series for user %s and symbol %s: %s", tg_id, symbol, e)
return False
# USER AUTO TRADING
async def get_all_user_auto_trading(tg_id: int):