devel #11
@@ -198,15 +198,12 @@ async def create_user_additional_settings(tg_id: int) -> None:
|
|||||||
# Create the user additional settings
|
# Create the user additional settings
|
||||||
user_additional_settings = UserAdditionalSettings(
|
user_additional_settings = UserAdditionalSettings(
|
||||||
user=user,
|
user=user,
|
||||||
trade_mode="Merged_Single", # Default value
|
trade_mode="Long", # Default value
|
||||||
order_type="Market",
|
switch_side="По направлению",
|
||||||
conditional_order_type="Market",
|
|
||||||
margin_type="ISOLATED_MARGIN",
|
margin_type="ISOLATED_MARGIN",
|
||||||
leverage="10",
|
leverage="10",
|
||||||
leverage_to_buy="10",
|
order_quantity=1.0,
|
||||||
leverage_to_sell="10",
|
martingale_factor=2.0,
|
||||||
order_quantity=5.0,
|
|
||||||
martingale_factor=1.0,
|
|
||||||
max_bets_in_series=10,
|
max_bets_in_series=10,
|
||||||
)
|
)
|
||||||
session.add(user_additional_settings)
|
session.add(user_additional_settings)
|
||||||
@@ -283,90 +280,6 @@ async def set_trade_mode(tg_id: int, trade_mode: str) -> bool:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
async def set_order_type(tg_id: int, order_type: str) -> bool:
|
|
||||||
"""
|
|
||||||
Set order type for a user in the database.
|
|
||||||
:param tg_id: Telegram user ID
|
|
||||||
:param order_type: "Market" or "Limit"
|
|
||||||
:return: True if successful, False otherwise
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
async with async_session() as session:
|
|
||||||
result = await session.execute(
|
|
||||||
select(User)
|
|
||||||
.options(joinedload(User.user_additional_settings))
|
|
||||||
.filter_by(tg_id=tg_id)
|
|
||||||
)
|
|
||||||
user = result.scalars().first()
|
|
||||||
|
|
||||||
if user:
|
|
||||||
if user.user_additional_settings:
|
|
||||||
# Updating existing record
|
|
||||||
user.user_additional_settings.order_type = order_type
|
|
||||||
else:
|
|
||||||
# Creating new record
|
|
||||||
user_additional_settings = UserAdditionalSettings(
|
|
||||||
order_type=order_type,
|
|
||||||
user=user,
|
|
||||||
)
|
|
||||||
session.add(user_additional_settings)
|
|
||||||
|
|
||||||
await session.commit()
|
|
||||||
logger.info("User order type updated for user: %s", tg_id)
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
logger.error("User not found with tg_id: %s", tg_id)
|
|
||||||
return False
|
|
||||||
except Exception as e:
|
|
||||||
logger.error("Error adding/updating user order type for user %s: %s", tg_id, e)
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
async def set_conditional_order_type(tg_id: int, conditional_order_type: str) -> bool:
|
|
||||||
"""
|
|
||||||
Set conditional order type for a user in the database.
|
|
||||||
:param tg_id: Telegram user ID
|
|
||||||
:param conditional_order_type: "Market" or "Limit"
|
|
||||||
:return: True if successful, False otherwise
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
async with async_session() as session:
|
|
||||||
result = await session.execute(
|
|
||||||
select(User)
|
|
||||||
.options(joinedload(User.user_additional_settings))
|
|
||||||
.filter_by(tg_id=tg_id)
|
|
||||||
)
|
|
||||||
user = result.scalars().first()
|
|
||||||
|
|
||||||
if user:
|
|
||||||
if user.user_additional_settings:
|
|
||||||
# Updating existing record
|
|
||||||
user.user_additional_settings.conditional_order_type = (
|
|
||||||
conditional_order_type
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
# Creating new record
|
|
||||||
user_additional_settings = UserAdditionalSettings(
|
|
||||||
conditional_order_type=conditional_order_type,
|
|
||||||
user=user,
|
|
||||||
)
|
|
||||||
session.add(user_additional_settings)
|
|
||||||
|
|
||||||
await session.commit()
|
|
||||||
logger.info("User conditional order type updated for user: %s", tg_id)
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
logger.error("User not found with tg_id: %s", tg_id)
|
|
||||||
return False
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(
|
|
||||||
"Error adding/updating user conditional order type for user %s: %s",
|
|
||||||
tg_id,
|
|
||||||
e,
|
|
||||||
)
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
async def set_margin_type(tg_id: int, margin_type: str) -> bool:
|
async def set_margin_type(tg_id: int, margin_type: str) -> bool:
|
||||||
"""
|
"""
|
||||||
Set margin type for a user in the database.
|
Set margin type for a user in the database.
|
||||||
@@ -406,6 +319,45 @@ async def set_margin_type(tg_id: int, margin_type: str) -> bool:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
async def set_switch_side(tg_id: int, switch_side: str) -> bool:
|
||||||
|
"""
|
||||||
|
Set switch side for a user in the database.
|
||||||
|
:param tg_id: Telegram user ID
|
||||||
|
:param switch_side: "По направлению" or "По цене"
|
||||||
|
:return: True if successful, False otherwise
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
async with async_session() as session:
|
||||||
|
result = await session.execute(
|
||||||
|
select(User)
|
||||||
|
.options(joinedload(User.user_additional_settings))
|
||||||
|
.filter_by(tg_id=tg_id)
|
||||||
|
)
|
||||||
|
user = result.scalars().first()
|
||||||
|
|
||||||
|
if user:
|
||||||
|
if user.user_additional_settings:
|
||||||
|
# Updating existing record
|
||||||
|
user.user_additional_settings.switch_side = switch_side
|
||||||
|
else:
|
||||||
|
# Creating new record
|
||||||
|
user_additional_settings = UserAdditionalSettings(
|
||||||
|
switch_side=switch_side,
|
||||||
|
user=user,
|
||||||
|
)
|
||||||
|
session.add(user_additional_settings)
|
||||||
|
|
||||||
|
await session.commit()
|
||||||
|
logger.info("User switch side updated for user: %s", tg_id)
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
logger.error("User not found with tg_id: %s", tg_id)
|
||||||
|
return False
|
||||||
|
except Exception as e:
|
||||||
|
logger.error("Error adding/updating user switch side for user %s: %s", tg_id, e)
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
async def set_leverage(tg_id: int, leverage: str) -> bool:
|
async def set_leverage(tg_id: int, leverage: str) -> bool:
|
||||||
"""
|
"""
|
||||||
Set leverage for a user in the database.
|
Set leverage for a user in the database.
|
||||||
@@ -445,50 +397,6 @@ async def set_leverage(tg_id: int, leverage: str) -> bool:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
async def set_leverage_to_buy_and_sell(
|
|
||||||
tg_id: int, leverage_to_buy: str, leverage_to_sell: str
|
|
||||||
) -> bool:
|
|
||||||
"""
|
|
||||||
Set leverage for a user in the database.
|
|
||||||
:param tg_id: Telegram user ID
|
|
||||||
:param leverage_to_buy: Leverage to buy
|
|
||||||
:param leverage_to_sell: Leverage to sell
|
|
||||||
:return: True if successful, False otherwise
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
async with async_session() as session:
|
|
||||||
result = await session.execute(
|
|
||||||
select(User)
|
|
||||||
.options(joinedload(User.user_additional_settings))
|
|
||||||
.filter_by(tg_id=tg_id)
|
|
||||||
)
|
|
||||||
user = result.scalars().first()
|
|
||||||
|
|
||||||
if user:
|
|
||||||
if user.user_additional_settings:
|
|
||||||
# Updating existing record
|
|
||||||
user.user_additional_settings.leverage_to_buy = leverage_to_buy
|
|
||||||
user.user_additional_settings.leverage_to_sell = leverage_to_sell
|
|
||||||
else:
|
|
||||||
# Creating new record
|
|
||||||
user_additional_settings = UserAdditionalSettings(
|
|
||||||
leverage_to_buy=leverage_to_buy,
|
|
||||||
leverage_to_sell=leverage_to_sell,
|
|
||||||
user=user,
|
|
||||||
)
|
|
||||||
session.add(user_additional_settings)
|
|
||||||
|
|
||||||
await session.commit()
|
|
||||||
logger.info("User leverage updated for user: %s", tg_id)
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
logger.error("User not found with tg_id: %s", tg_id)
|
|
||||||
return False
|
|
||||||
except Exception as e:
|
|
||||||
logger.error("Error adding/updating user leverage for user %s: %s", tg_id, e)
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
async def set_order_quantity(tg_id: int, order_quantity: float) -> bool:
|
async def set_order_quantity(tg_id: int, order_quantity: float) -> bool:
|
||||||
"""
|
"""
|
||||||
Set order quantity for a user in the database.
|
Set order quantity for a user in the database.
|
||||||
@@ -614,45 +522,6 @@ async def set_max_bets_in_series(tg_id: int, max_bets_in_series: int) -> bool:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
async def set_limit_price(tg_id: int, limit_price: float) -> bool:
|
|
||||||
"""
|
|
||||||
Set limit price for a user in the database.
|
|
||||||
:param tg_id:
|
|
||||||
:param limit_price:
|
|
||||||
:return: bool
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
async with async_session() as session:
|
|
||||||
result = await session.execute(
|
|
||||||
select(User)
|
|
||||||
.options(joinedload(User.user_additional_settings))
|
|
||||||
.filter_by(tg_id=tg_id)
|
|
||||||
)
|
|
||||||
user = result.scalars().first()
|
|
||||||
|
|
||||||
if user:
|
|
||||||
if user.user_additional_settings:
|
|
||||||
# Updating existing record
|
|
||||||
user.user_additional_settings.limit_price = limit_price
|
|
||||||
else:
|
|
||||||
# Creating new record
|
|
||||||
user_additional_settings = UserAdditionalSettings(
|
|
||||||
limit_price=limit_price,
|
|
||||||
user=user,
|
|
||||||
)
|
|
||||||
session.add(user_additional_settings)
|
|
||||||
|
|
||||||
await session.commit()
|
|
||||||
logger.info("User limit price updated for user: %s", tg_id)
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
logger.error("User not found with tg_id: %s", tg_id)
|
|
||||||
return False
|
|
||||||
except Exception as e:
|
|
||||||
logger.error("Error adding/updating user limit price for user %s: %s", tg_id, e)
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
async def set_trigger_price(tg_id: int, trigger_price: float) -> bool:
|
async def set_trigger_price(tg_id: int, trigger_price: float) -> bool:
|
||||||
"""
|
"""
|
||||||
Set trigger price for a user in the database.
|
Set trigger price for a user in the database.
|
||||||
@@ -718,9 +587,8 @@ async def create_user_risk_management(tg_id: int) -> None:
|
|||||||
# Create the user risk management
|
# Create the user risk management
|
||||||
user_risk_management = UserRiskManagement(
|
user_risk_management = UserRiskManagement(
|
||||||
user=user,
|
user=user,
|
||||||
take_profit_percent=1,
|
take_profit_percent=1.0,
|
||||||
stop_loss_percent=1,
|
stop_loss_percent=1.0,
|
||||||
max_risk_percent=100,
|
|
||||||
commission_fee="Yes_commission_fee",
|
commission_fee="Yes_commission_fee",
|
||||||
)
|
)
|
||||||
session.add(user_risk_management)
|
session.add(user_risk_management)
|
||||||
@@ -758,7 +626,7 @@ async def get_user_risk_management(tg_id: int):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
async def set_take_profit_percent(tg_id: int, take_profit_percent: int) -> bool:
|
async def set_take_profit_percent(tg_id: int, take_profit_percent: float) -> bool:
|
||||||
"""
|
"""
|
||||||
Set take profit percent for a user in the database.
|
Set take profit percent for a user in the database.
|
||||||
:param tg_id: Telegram user ID
|
:param tg_id: Telegram user ID
|
||||||
@@ -799,7 +667,7 @@ async def set_take_profit_percent(tg_id: int, take_profit_percent: int) -> bool:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
async def set_stop_loss_percent(tg_id: int, stop_loss_percent: int) -> bool:
|
async def set_stop_loss_percent(tg_id: int, stop_loss_percent: float) -> bool:
|
||||||
"""
|
"""
|
||||||
Set stop loss percent for a user in the database.
|
Set stop loss percent for a user in the database.
|
||||||
:param tg_id: Telegram user ID
|
:param tg_id: Telegram user ID
|
||||||
@@ -840,47 +708,6 @@ async def set_stop_loss_percent(tg_id: int, stop_loss_percent: int) -> bool:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
async def set_max_risk_percent(tg_id: int, max_risk_percent: int) -> bool:
|
|
||||||
"""
|
|
||||||
Set max risk percent for a user in the database.
|
|
||||||
:param tg_id: Telegram user ID
|
|
||||||
:param max_risk_percent: Max risk percent
|
|
||||||
:return: True if successful, False otherwise
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
async with async_session() as session:
|
|
||||||
result = await session.execute(
|
|
||||||
select(User)
|
|
||||||
.options(joinedload(User.user_risk_management))
|
|
||||||
.filter_by(tg_id=tg_id)
|
|
||||||
)
|
|
||||||
user = result.scalars().first()
|
|
||||||
|
|
||||||
if user:
|
|
||||||
if user.user_risk_management:
|
|
||||||
# Updating existing record
|
|
||||||
user.user_risk_management.max_risk_percent = max_risk_percent
|
|
||||||
else:
|
|
||||||
# Creating new record
|
|
||||||
user_risk_management = UserRiskManagement(
|
|
||||||
max_risk_percent=max_risk_percent,
|
|
||||||
user=user,
|
|
||||||
)
|
|
||||||
session.add(user_risk_management)
|
|
||||||
|
|
||||||
await session.commit()
|
|
||||||
logger.info("User max risk percent updated for user: %s", tg_id)
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
logger.error("User not found with tg_id: %s", tg_id)
|
|
||||||
return False
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(
|
|
||||||
"Error adding/updating user max risk percent for user %s: %s", tg_id, e
|
|
||||||
)
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
async def set_commission_fee(tg_id: int, commission_fee: str) -> bool:
|
async def set_commission_fee(tg_id: int, commission_fee: str) -> bool:
|
||||||
"""
|
"""
|
||||||
Set commission fee for a user in the database.
|
Set commission fee for a user in the database.
|
||||||
@@ -1073,19 +900,13 @@ async def set_user_deal(
|
|||||||
trade_mode: str,
|
trade_mode: str,
|
||||||
margin_type: str,
|
margin_type: str,
|
||||||
leverage: str,
|
leverage: str,
|
||||||
leverage_to_buy: str,
|
|
||||||
leverage_to_sell: str,
|
|
||||||
order_type: str,
|
|
||||||
conditional_order_type: str,
|
|
||||||
order_quantity: float,
|
order_quantity: float,
|
||||||
limit_price: float,
|
|
||||||
trigger_price: float,
|
trigger_price: float,
|
||||||
martingale_factor: float,
|
martingale_factor: float,
|
||||||
max_bets_in_series: int,
|
max_bets_in_series: int,
|
||||||
take_profit_percent: int,
|
take_profit_percent: int,
|
||||||
stop_loss_percent: int,
|
stop_loss_percent: int,
|
||||||
max_risk_percent: int,
|
base_quantity: float
|
||||||
switch_side_mode: bool,
|
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Set the user deal in the database.
|
Set the user deal in the database.
|
||||||
@@ -1096,19 +917,13 @@ async def set_user_deal(
|
|||||||
:param trade_mode: Trade mode
|
:param trade_mode: Trade mode
|
||||||
:param margin_type: Margin type
|
:param margin_type: Margin type
|
||||||
:param leverage: Leverage
|
:param leverage: Leverage
|
||||||
:param leverage_to_buy: Leverage to buy
|
|
||||||
:param leverage_to_sell: Leverage to sell
|
|
||||||
:param order_type: Order type
|
|
||||||
:param conditional_order_type: Conditional order type
|
|
||||||
:param order_quantity: Order quantity
|
:param order_quantity: Order quantity
|
||||||
:param limit_price: Limit price
|
|
||||||
:param trigger_price: Trigger price
|
:param trigger_price: Trigger price
|
||||||
:param martingale_factor: Martingale factor
|
:param martingale_factor: Martingale factor
|
||||||
:param max_bets_in_series: Max bets in series
|
:param max_bets_in_series: Max bets in series
|
||||||
:param take_profit_percent: Take profit percent
|
:param take_profit_percent: Take profit percent
|
||||||
:param stop_loss_percent: Stop loss percent
|
:param stop_loss_percent: Stop loss percent
|
||||||
:param max_risk_percent: Max risk percent
|
:param base_quantity: Base quantity
|
||||||
:param switch_side_mode: Switch side mode
|
|
||||||
:return: bool
|
:return: bool
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
@@ -1131,19 +946,13 @@ async def set_user_deal(
|
|||||||
deal.trade_mode = trade_mode
|
deal.trade_mode = trade_mode
|
||||||
deal.margin_type = margin_type
|
deal.margin_type = margin_type
|
||||||
deal.leverage = leverage
|
deal.leverage = leverage
|
||||||
deal.leverage_to_buy = leverage_to_buy
|
|
||||||
deal.leverage_to_sell = leverage_to_sell
|
|
||||||
deal.order_type = order_type
|
|
||||||
deal.conditional_order_type = conditional_order_type
|
|
||||||
deal.order_quantity = order_quantity
|
deal.order_quantity = order_quantity
|
||||||
deal.limit_price = limit_price
|
|
||||||
deal.trigger_price = trigger_price
|
deal.trigger_price = trigger_price
|
||||||
deal.martingale_factor = martingale_factor
|
deal.martingale_factor = martingale_factor
|
||||||
deal.max_bets_in_series = max_bets_in_series
|
deal.max_bets_in_series = max_bets_in_series
|
||||||
deal.take_profit_percent = take_profit_percent
|
deal.take_profit_percent = take_profit_percent
|
||||||
deal.stop_loss_percent = stop_loss_percent
|
deal.stop_loss_percent = stop_loss_percent
|
||||||
deal.max_risk_percent = max_risk_percent
|
deal.base_quantity = base_quantity
|
||||||
deal.switch_side_mode = switch_side_mode
|
|
||||||
else:
|
else:
|
||||||
# Creating new record
|
# Creating new record
|
||||||
new_deal = UserDeals(
|
new_deal = UserDeals(
|
||||||
@@ -1154,19 +963,13 @@ async def set_user_deal(
|
|||||||
trade_mode=trade_mode,
|
trade_mode=trade_mode,
|
||||||
margin_type=margin_type,
|
margin_type=margin_type,
|
||||||
leverage=leverage,
|
leverage=leverage,
|
||||||
leverage_to_buy=leverage_to_buy,
|
|
||||||
leverage_to_sell=leverage_to_sell,
|
|
||||||
order_type=order_type,
|
|
||||||
conditional_order_type=conditional_order_type,
|
|
||||||
order_quantity=order_quantity,
|
order_quantity=order_quantity,
|
||||||
limit_price=limit_price,
|
|
||||||
trigger_price=trigger_price,
|
trigger_price=trigger_price,
|
||||||
martingale_factor=martingale_factor,
|
martingale_factor=martingale_factor,
|
||||||
max_bets_in_series=max_bets_in_series,
|
max_bets_in_series=max_bets_in_series,
|
||||||
take_profit_percent=take_profit_percent,
|
take_profit_percent=take_profit_percent,
|
||||||
stop_loss_percent=stop_loss_percent,
|
stop_loss_percent=stop_loss_percent,
|
||||||
max_risk_percent=max_risk_percent,
|
base_quantity=base_quantity
|
||||||
switch_side_mode=switch_side_mode,
|
|
||||||
)
|
)
|
||||||
session.add(new_deal)
|
session.add(new_deal)
|
||||||
|
|
||||||
@@ -1268,7 +1071,7 @@ async def get_all_user_auto_trading(tg_id: int):
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
async def get_user_auto_trading(tg_id: int, symbol: str, side: str):
|
async def get_user_auto_trading(tg_id: int, symbol: str):
|
||||||
"""Get user auto trading from the database asynchronously."""
|
"""Get user auto trading from the database asynchronously."""
|
||||||
try:
|
try:
|
||||||
async with async_session() as session:
|
async with async_session() as session:
|
||||||
@@ -1278,7 +1081,7 @@ async def get_user_auto_trading(tg_id: int, symbol: str, side: str):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
result_auto_trading = await session.execute(
|
result_auto_trading = await session.execute(
|
||||||
select(UserAutoTrading).filter_by(user_id=user.id, symbol=symbol, side=side)
|
select(UserAutoTrading).filter_by(user_id=user.id, symbol=symbol)
|
||||||
)
|
)
|
||||||
auto_trading = result_auto_trading.scalars().first()
|
auto_trading = result_auto_trading.scalars().first()
|
||||||
return auto_trading
|
return auto_trading
|
||||||
@@ -1287,13 +1090,12 @@ async def get_user_auto_trading(tg_id: int, symbol: str, side: str):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
async def set_auto_trading(tg_id: int, symbol: str, auto_trading: bool, side: str) -> bool:
|
async def set_auto_trading(tg_id: int, symbol: str, auto_trading: bool) -> bool:
|
||||||
"""
|
"""
|
||||||
Set the auto trading for a user in the database.
|
Set the auto trading for a user in the database.
|
||||||
:param tg_id: Telegram user ID
|
:param tg_id: Telegram user ID
|
||||||
:param symbol: Symbol
|
:param symbol: Symbol
|
||||||
:param auto_trading: Auto trading
|
:param auto_trading: Auto trading
|
||||||
:param side: Side
|
|
||||||
:return: bool
|
:return: bool
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
@@ -1305,7 +1107,7 @@ async def set_auto_trading(tg_id: int, symbol: str, auto_trading: bool, side: st
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
result = await session.execute(
|
result = await session.execute(
|
||||||
select(UserAutoTrading).filter_by(user_id=user.id, symbol=symbol, side=side)
|
select(UserAutoTrading).filter_by(user_id=user.id, symbol=symbol)
|
||||||
)
|
)
|
||||||
record = result.scalars().first()
|
record = result.scalars().first()
|
||||||
if record:
|
if record:
|
||||||
@@ -1315,7 +1117,6 @@ async def set_auto_trading(tg_id: int, symbol: str, auto_trading: bool, side: st
|
|||||||
user_id=user.id,
|
user_id=user.id,
|
||||||
symbol=symbol,
|
symbol=symbol,
|
||||||
auto_trading=auto_trading,
|
auto_trading=auto_trading,
|
||||||
side=side
|
|
||||||
)
|
)
|
||||||
session.add(new_record)
|
session.add(new_record)
|
||||||
await session.commit()
|
await session.commit()
|
||||||
@@ -1326,12 +1127,11 @@ async def set_auto_trading(tg_id: int, symbol: str, auto_trading: bool, side: st
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
async def set_fee_user_auto_trading(tg_id: int, symbol: str, side: str, fee: float) -> bool:
|
async def set_fee_user_auto_trading(tg_id: int, symbol: str, fee: float) -> bool:
|
||||||
"""
|
"""
|
||||||
Set the fee for a user auto trading in the database.
|
Set the fee for a user auto trading in the database.
|
||||||
:param tg_id:
|
:param tg_id:
|
||||||
:param symbol:
|
:param symbol:
|
||||||
:param side:
|
|
||||||
:param fee:
|
:param fee:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
@@ -1344,7 +1144,7 @@ async def set_fee_user_auto_trading(tg_id: int, symbol: str, side: str, fee: flo
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
result = await session.execute(
|
result = await session.execute(
|
||||||
select(UserAutoTrading).filter_by(user_id=user.id, symbol=symbol, side=side)
|
select(UserAutoTrading).filter_by(user_id=user.id, symbol=symbol)
|
||||||
)
|
)
|
||||||
record = result.scalars().first()
|
record = result.scalars().first()
|
||||||
|
|
||||||
@@ -1355,7 +1155,6 @@ async def set_fee_user_auto_trading(tg_id: int, symbol: str, side: str, fee: flo
|
|||||||
user_id=user.id,
|
user_id=user.id,
|
||||||
symbol=symbol,
|
symbol=symbol,
|
||||||
fee=fee,
|
fee=fee,
|
||||||
side=side
|
|
||||||
)
|
)
|
||||||
session.add(user_fee)
|
session.add(user_fee)
|
||||||
await session.commit()
|
await session.commit()
|
||||||
@@ -1364,3 +1163,41 @@ async def set_fee_user_auto_trading(tg_id: int, symbol: str, side: str, fee: flo
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("Error setting user auto trading fee for user %s and symbol %s: %s", tg_id, symbol, e)
|
logger.error("Error setting user auto trading fee for user %s and symbol %s: %s", tg_id, symbol, e)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
async def set_total_fee_user_auto_trading(tg_id: int, symbol: str, total_fee: float) -> bool:
|
||||||
|
"""
|
||||||
|
Set the total fee for a user auto trading in the database.
|
||||||
|
:param tg_id: Telegram user ID
|
||||||
|
:param symbol: Symbol
|
||||||
|
:param total_fee: Total fee
|
||||||
|
:return: bool
|
||||||
|
"""
|
||||||
|
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)
|
||||||
|
)
|
||||||
|
record = result.scalars().first()
|
||||||
|
|
||||||
|
if record:
|
||||||
|
record.total_fee = total_fee
|
||||||
|
else:
|
||||||
|
user_total_fee = UserAutoTrading(
|
||||||
|
user_id=user.id,
|
||||||
|
symbol=symbol,
|
||||||
|
total_fee=total_fee,
|
||||||
|
)
|
||||||
|
session.add(user_total_fee)
|
||||||
|
await session.commit()
|
||||||
|
logger.info("Set total fee for user %s and symbol %s", tg_id, symbol)
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
logger.error("Error setting user auto trading total fee for user %s and symbol %s: %s", tg_id, symbol, e)
|
||||||
|
return False
|
||||||
|
Reference in New Issue
Block a user