Fixed
This commit is contained in:
@@ -166,7 +166,6 @@ class UserDeals(Base):
|
||||
switch_side_mode = Column(Boolean, nullable=True)
|
||||
limit_price = Column(Float, nullable=True)
|
||||
trigger_price = Column(Float, nullable=True)
|
||||
fee = Column(Float, nullable=True)
|
||||
|
||||
user = relationship("User", back_populates="user_deals")
|
||||
|
||||
@@ -185,9 +184,7 @@ class UserAutoTrading(Base):
|
||||
nullable=False)
|
||||
symbol = Column(String, nullable=True)
|
||||
auto_trading = Column(Boolean, nullable=True)
|
||||
side = Column(String, nullable=True)
|
||||
fee = Column(Float, nullable=True)
|
||||
|
||||
user = relationship("User", back_populates="user_auto_trading")
|
||||
|
||||
__table_args__ = (
|
||||
UniqueConstraint('user_id', 'symbol', name='uq_user_auto_trading_symbol'),
|
||||
)
|
||||
user = relationship("User", back_populates="user_auto_trading")
|
@@ -446,7 +446,7 @@ async def set_leverage(tg_id: int, leverage: str) -> bool:
|
||||
|
||||
|
||||
async def set_leverage_to_buy_and_sell(
|
||||
tg_id: int, leverage_to_buy: str, leverage_to_sell: str
|
||||
tg_id: int, leverage_to_buy: str, leverage_to_sell: str
|
||||
) -> bool:
|
||||
"""
|
||||
Set leverage for a user in the database.
|
||||
@@ -1066,26 +1066,26 @@ async def set_stop_timer(tg_id: int, timer_end: int) -> bool:
|
||||
|
||||
# USER DEALS
|
||||
async def set_user_deal(
|
||||
tg_id: int,
|
||||
symbol: str,
|
||||
last_side: str,
|
||||
current_step: int,
|
||||
trade_mode: str,
|
||||
margin_type: str,
|
||||
leverage: str,
|
||||
leverage_to_buy: str,
|
||||
leverage_to_sell: str,
|
||||
order_type: str,
|
||||
conditional_order_type: str,
|
||||
order_quantity: float,
|
||||
limit_price: float,
|
||||
trigger_price: float,
|
||||
martingale_factor: float,
|
||||
max_bets_in_series: int,
|
||||
take_profit_percent: int,
|
||||
stop_loss_percent: int,
|
||||
max_risk_percent: int,
|
||||
switch_side_mode: bool,
|
||||
tg_id: int,
|
||||
symbol: str,
|
||||
last_side: str,
|
||||
current_step: int,
|
||||
trade_mode: str,
|
||||
margin_type: str,
|
||||
leverage: str,
|
||||
leverage_to_buy: str,
|
||||
leverage_to_sell: str,
|
||||
order_type: str,
|
||||
conditional_order_type: str,
|
||||
order_quantity: float,
|
||||
limit_price: float,
|
||||
trigger_price: float,
|
||||
martingale_factor: float,
|
||||
max_bets_in_series: int,
|
||||
take_profit_percent: int,
|
||||
stop_loss_percent: int,
|
||||
max_risk_percent: int,
|
||||
switch_side_mode: bool,
|
||||
):
|
||||
"""
|
||||
Set the user deal in the database.
|
||||
@@ -1249,6 +1249,25 @@ async def set_fee_user_deal_by_symbol(tg_id: int, symbol: str, fee: float):
|
||||
|
||||
# USER AUTO TRADING
|
||||
|
||||
async def get_all_user_auto_trading(tg_id: int):
|
||||
"""Get all user auto trading from the database asynchronously."""
|
||||
try:
|
||||
async with async_session() as session:
|
||||
result_user = await session.execute(select(User).filter_by(tg_id=tg_id))
|
||||
user = result_user.scalars().first()
|
||||
if not user:
|
||||
return []
|
||||
|
||||
result_auto_trading = await session.execute(
|
||||
select(UserAutoTrading).filter_by(user_id=user.id)
|
||||
)
|
||||
auto_trading = result_auto_trading.scalars().all()
|
||||
return auto_trading
|
||||
except Exception as e:
|
||||
logger.error("Error getting auto trading for user %s: %s", tg_id, e)
|
||||
return []
|
||||
|
||||
|
||||
async def get_user_auto_trading(tg_id: int, symbol: str):
|
||||
"""Get user auto trading from the database asynchronously."""
|
||||
try:
|
||||
@@ -1268,12 +1287,13 @@ async def get_user_auto_trading(tg_id: int, symbol: str):
|
||||
return None
|
||||
|
||||
|
||||
async def set_auto_trading(tg_id: int, symbol: str, auto_trading: bool) -> bool:
|
||||
async def set_auto_trading(tg_id: int, symbol: str, auto_trading: bool, side: str) -> bool:
|
||||
"""
|
||||
Set the auto trading for a user in the database.
|
||||
:param tg_id: Telegram user ID
|
||||
:param symbol: Symbol
|
||||
:param auto_trading: Auto trading
|
||||
:param side: Side
|
||||
:return: bool
|
||||
"""
|
||||
try:
|
||||
@@ -1285,7 +1305,7 @@ async def set_auto_trading(tg_id: int, symbol: str, auto_trading: bool) -> bool:
|
||||
return False
|
||||
|
||||
result = await session.execute(
|
||||
select(UserAutoTrading).filter_by(user_id=user.id, symbol=symbol)
|
||||
select(UserAutoTrading).filter_by(user_id=user.id, symbol=symbol, side=side)
|
||||
)
|
||||
record = result.scalars().first()
|
||||
if record:
|
||||
@@ -1294,7 +1314,8 @@ async def set_auto_trading(tg_id: int, symbol: str, auto_trading: bool) -> bool:
|
||||
new_record = UserAutoTrading(
|
||||
user_id=user.id,
|
||||
symbol=symbol,
|
||||
auto_trading=auto_trading
|
||||
auto_trading=auto_trading,
|
||||
side=side
|
||||
)
|
||||
session.add(new_record)
|
||||
await session.commit()
|
||||
@@ -1302,4 +1323,44 @@ async def set_auto_trading(tg_id: int, symbol: str, auto_trading: bool) -> bool:
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error("Error setting auto_trading for user %s and symbol %s: %s", tg_id, symbol, e)
|
||||
return False
|
||||
return False
|
||||
|
||||
|
||||
async def set_fee_user_auto_trading(tg_id: int, symbol: str, side: str, fee: float) -> bool:
|
||||
"""
|
||||
Set the fee for a user auto trading in the database.
|
||||
:param tg_id:
|
||||
:param symbol:
|
||||
:param side:
|
||||
:param fee:
|
||||
:return:
|
||||
"""
|
||||
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(UserAutoTrading).filter_by(user_id=user.id, symbol=symbol, side=side)
|
||||
)
|
||||
record = result.scalars().first()
|
||||
|
||||
if record:
|
||||
record.fee = fee
|
||||
else:
|
||||
user_fee = UserAutoTrading(
|
||||
user_id=user.id,
|
||||
symbol=symbol,
|
||||
fee=fee,
|
||||
side=side
|
||||
)
|
||||
session.add(user_fee)
|
||||
await session.commit()
|
||||
logger.info("Set fee for user %s and symbol %s", tg_id, symbol)
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error("Error setting user auto trading fee for user %s and symbol %s: %s", tg_id, symbol, e)
|
||||
return False
|
||||
|
Reference in New Issue
Block a user