forked from kodorvan/stcs
Added the addition of a common commission
This commit is contained in:
@@ -893,20 +893,20 @@ async def set_stop_timer(tg_id: int, timer_end: int) -> bool:
|
|||||||
|
|
||||||
# USER DEALS
|
# USER DEALS
|
||||||
async def set_user_deal(
|
async def set_user_deal(
|
||||||
tg_id: int,
|
tg_id: int,
|
||||||
symbol: str,
|
symbol: str,
|
||||||
last_side: str,
|
last_side: str,
|
||||||
current_step: int,
|
current_step: int,
|
||||||
trade_mode: str,
|
trade_mode: str,
|
||||||
margin_type: str,
|
margin_type: str,
|
||||||
leverage: str,
|
leverage: str,
|
||||||
order_quantity: float,
|
order_quantity: 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,
|
||||||
base_quantity: float
|
base_quantity: float,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Set the user deal in the database.
|
Set the user deal in the database.
|
||||||
@@ -969,7 +969,7 @@ async def set_user_deal(
|
|||||||
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,
|
||||||
base_quantity=base_quantity
|
base_quantity=base_quantity,
|
||||||
)
|
)
|
||||||
session.add(new_deal)
|
session.add(new_deal)
|
||||||
|
|
||||||
@@ -978,7 +978,9 @@ async def set_user_deal(
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
except Exception as e:
|
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
|
return False
|
||||||
|
|
||||||
|
|
||||||
@@ -998,7 +1000,9 @@ async def get_user_deal_by_symbol(tg_id: int, symbol: str):
|
|||||||
deal = result_deal.scalars().first()
|
deal = result_deal.scalars().first()
|
||||||
return deal
|
return deal
|
||||||
except Exception as e:
|
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
|
return None
|
||||||
|
|
||||||
|
|
||||||
@@ -1040,18 +1044,26 @@ async def set_fee_user_deal_by_symbol(tg_id: int, symbol: str, fee: float):
|
|||||||
if record:
|
if record:
|
||||||
record.fee = fee
|
record.fee = fee
|
||||||
else:
|
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
|
return False
|
||||||
await session.commit()
|
await session.commit()
|
||||||
logger.info("Set fee for user %s and symbol %s", tg_id, symbol)
|
logger.info("Set fee for user %s and symbol %s", tg_id, symbol)
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
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
|
return False
|
||||||
|
|
||||||
|
|
||||||
# USER AUTO TRADING
|
# USER AUTO TRADING
|
||||||
|
|
||||||
|
|
||||||
async def get_all_user_auto_trading(tg_id: int):
|
async def get_all_user_auto_trading(tg_id: int):
|
||||||
"""Get all user auto trading from the database asynchronously."""
|
"""Get all user auto trading from the database asynchronously."""
|
||||||
try:
|
try:
|
||||||
@@ -1086,7 +1098,9 @@ async def get_user_auto_trading(tg_id: int, symbol: str):
|
|||||||
auto_trading = result_auto_trading.scalars().first()
|
auto_trading = result_auto_trading.scalars().first()
|
||||||
return auto_trading
|
return auto_trading
|
||||||
except Exception as e:
|
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
|
return None
|
||||||
|
|
||||||
|
|
||||||
@@ -1120,10 +1134,17 @@ async def set_auto_trading(tg_id: int, symbol: str, auto_trading: bool) -> bool:
|
|||||||
)
|
)
|
||||||
session.add(new_record)
|
session.add(new_record)
|
||||||
await session.commit()
|
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
|
return True
|
||||||
except Exception as e:
|
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
|
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)
|
logger.info("Set fee for user %s and symbol %s", tg_id, symbol)
|
||||||
return True
|
return True
|
||||||
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:
|
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.
|
Set the total fee for a user auto trading in the database.
|
||||||
:param tg_id: Telegram user ID
|
: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)
|
logger.info("Set total fee for user %s and symbol %s", tg_id, symbol)
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
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
|
return False
|
||||||
|
Reference in New Issue
Block a user