2
0
forked from kodorvan/stcs

Added the addition of a common commission

This commit is contained in:
algizn97
2025-10-10 13:56:43 +05:00
parent 4663888190
commit 0945be242a

View File

@@ -906,7 +906,7 @@ async def set_user_deal(
max_bets_in_series: int,
take_profit_percent: int,
stop_loss_percent: int,
base_quantity: float
base_quantity: float,
):
"""
Set the user deal in the database.
@@ -969,7 +969,7 @@ async def set_user_deal(
max_bets_in_series=max_bets_in_series,
take_profit_percent=take_profit_percent,
stop_loss_percent=stop_loss_percent,
base_quantity=base_quantity
base_quantity=base_quantity,
)
session.add(new_deal)
@@ -978,7 +978,9 @@ async def set_user_deal(
return True
except Exception as e:
logger.error("Error setting user deal for user %s and symbol %s: %s", tg_id, symbol, e)
logger.error(
"Error setting user deal for user %s and symbol %s: %s", tg_id, symbol, e
)
return False
@@ -998,7 +1000,9 @@ async def get_user_deal_by_symbol(tg_id: int, symbol: str):
deal = result_deal.scalars().first()
return deal
except Exception as e:
logger.error("Error getting deal for user %s and symbol %s: %s", tg_id, symbol, e)
logger.error(
"Error getting deal for user %s and symbol %s: %s", tg_id, symbol, e
)
return None
@@ -1040,18 +1044,26 @@ async def set_fee_user_deal_by_symbol(tg_id: int, symbol: str, fee: float):
if record:
record.fee = fee
else:
logger.error(f"User deal with user_id={user.id} and symbol={symbol} not found")
logger.error(
f"User deal with user_id={user.id} and symbol={symbol} not found"
)
return False
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 deal fee for user %s and symbol %s: %s", tg_id, symbol, e)
logger.error(
"Error setting user deal fee 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):
"""Get all user auto trading from the database asynchronously."""
try:
@@ -1086,7 +1098,9 @@ async def get_user_auto_trading(tg_id: int, symbol: str):
auto_trading = result_auto_trading.scalars().first()
return auto_trading
except Exception as e:
logger.error("Error getting auto trading for user %s and symbol %s: %s", tg_id, symbol, e)
logger.error(
"Error getting auto trading for user %s and symbol %s: %s", tg_id, symbol, e
)
return None
@@ -1120,10 +1134,17 @@ async def set_auto_trading(tg_id: int, symbol: str, auto_trading: bool) -> bool:
)
session.add(new_record)
await session.commit()
logger.info("Set auto_trading=%s for user %s and symbol %s", auto_trading, tg_id, symbol)
logger.info(
"Set auto_trading=%s for user %s and symbol %s",
auto_trading,
tg_id,
symbol,
)
return True
except Exception as e:
logger.error("Error setting auto_trading for user %s and symbol %s: %s", tg_id, symbol, e)
logger.error(
"Error setting auto_trading for user %s and symbol %s: %s", tg_id, symbol, e
)
return False
@@ -1161,11 +1182,18 @@ async def set_fee_user_auto_trading(tg_id: int, symbol: str, fee: float) -> bool
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)
logger.error(
"Error setting user auto trading fee for user %s and symbol %s: %s",
tg_id,
symbol,
e,
)
return False
async def set_total_fee_user_auto_trading(tg_id: int, symbol: str, total_fee: float) -> bool:
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
@@ -1199,5 +1227,10 @@ async def set_total_fee_user_auto_trading(tg_id: int, symbol: str, total_fee: fl
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)
logger.error(
"Error setting user auto trading total fee for user %s and symbol %s: %s",
tg_id,
symbol,
e,
)
return False