The formula for calculating the number of contracts by price has been changed
This commit is contained in:
@@ -25,11 +25,9 @@ async def start_trading_cycle(
|
|||||||
:param tg_id: Telegram user ID
|
:param tg_id: Telegram user ID
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
client = await get_bybit_client(tg_id=tg_id)
|
|
||||||
symbol = await rq.get_user_symbol(tg_id=tg_id)
|
symbol = await rq.get_user_symbol(tg_id=tg_id)
|
||||||
additional_data = await rq.get_user_additional_settings(tg_id=tg_id)
|
additional_data = await rq.get_user_additional_settings(tg_id=tg_id)
|
||||||
risk_management_data = await rq.get_user_risk_management(tg_id=tg_id)
|
risk_management_data = await rq.get_user_risk_management(tg_id=tg_id)
|
||||||
commission_fee = risk_management_data.commission_fee
|
|
||||||
user_deals_data = await rq.get_user_deal_by_symbol(
|
user_deals_data = await rq.get_user_deal_by_symbol(
|
||||||
tg_id=tg_id, symbol=symbol
|
tg_id=tg_id, symbol=symbol
|
||||||
)
|
)
|
||||||
@@ -43,6 +41,7 @@ async def start_trading_cycle(
|
|||||||
max_bets_in_series = additional_data.max_bets_in_series
|
max_bets_in_series = additional_data.max_bets_in_series
|
||||||
take_profit_percent = risk_management_data.take_profit_percent
|
take_profit_percent = risk_management_data.take_profit_percent
|
||||||
stop_loss_percent = risk_management_data.stop_loss_percent
|
stop_loss_percent = risk_management_data.stop_loss_percent
|
||||||
|
total_commission = 0
|
||||||
|
|
||||||
get_side = "Buy"
|
get_side = "Buy"
|
||||||
|
|
||||||
@@ -63,34 +62,6 @@ async def start_trading_cycle(
|
|||||||
else:
|
else:
|
||||||
side = "Sell"
|
side = "Sell"
|
||||||
|
|
||||||
# Get fee rates
|
|
||||||
fee_info = client.get_fee_rates(category="linear", symbol=symbol)
|
|
||||||
|
|
||||||
# Check if commission fee is enabled
|
|
||||||
commission_fee_percent = 0.0
|
|
||||||
if commission_fee == "Yes_commission_fee":
|
|
||||||
commission_fee_percent = safe_float(
|
|
||||||
fee_info["result"]["list"][0]["takerFeeRate"]
|
|
||||||
)
|
|
||||||
|
|
||||||
get_ticker = await get_tickers(tg_id, symbol=symbol)
|
|
||||||
price_symbol = safe_float(get_ticker.get("lastPrice")) or 0
|
|
||||||
instruments_info = await get_instruments_info(tg_id=tg_id, symbol=symbol)
|
|
||||||
qty_step_str = instruments_info.get("lotSizeFilter").get("qtyStep")
|
|
||||||
qty_step = safe_float(qty_step_str)
|
|
||||||
qty = safe_float(order_quantity) / safe_float(price_symbol)
|
|
||||||
decimals = abs(int(round(math.log10(qty_step))))
|
|
||||||
qty_formatted = math.floor(qty / qty_step) * qty_step
|
|
||||||
qty_formatted = round(qty_formatted, decimals)
|
|
||||||
|
|
||||||
if trigger_price > 0:
|
|
||||||
po_trigger_price = str(trigger_price)
|
|
||||||
else:
|
|
||||||
po_trigger_price = None
|
|
||||||
|
|
||||||
price_for_cals = trigger_price if po_trigger_price is not None else price_symbol
|
|
||||||
total_commission = price_for_cals * qty_formatted * commission_fee_percent
|
|
||||||
|
|
||||||
await set_switch_position_mode(
|
await set_switch_position_mode(
|
||||||
tg_id=tg_id,
|
tg_id=tg_id,
|
||||||
symbol=symbol,
|
symbol=symbol,
|
||||||
@@ -269,7 +240,7 @@ async def open_positions(
|
|||||||
instruments_info = await get_instruments_info(tg_id=tg_id, symbol=symbol)
|
instruments_info = await get_instruments_info(tg_id=tg_id, symbol=symbol)
|
||||||
qty_step_str = instruments_info.get("lotSizeFilter").get("qtyStep")
|
qty_step_str = instruments_info.get("lotSizeFilter").get("qtyStep")
|
||||||
qty_step = safe_float(qty_step_str)
|
qty_step = safe_float(qty_step_str)
|
||||||
qty = safe_float(order_quantity) / safe_float(price_symbol)
|
qty = (safe_float(order_quantity) * safe_float(leverage)) / safe_float(price_symbol)
|
||||||
decimals = abs(int(round(math.log10(qty_step))))
|
decimals = abs(int(round(math.log10(qty_step))))
|
||||||
qty_formatted = math.floor(qty / qty_step) * qty_step
|
qty_formatted = math.floor(qty / qty_step) * qty_step
|
||||||
qty_formatted = round(qty_formatted, decimals)
|
qty_formatted = round(qty_formatted, decimals)
|
||||||
@@ -285,6 +256,9 @@ async def open_positions(
|
|||||||
|
|
||||||
price_for_cals = trigger_price if po_trigger_price is not None else price_symbol
|
price_for_cals = trigger_price if po_trigger_price is not None else price_symbol
|
||||||
|
|
||||||
|
if qty_formatted <= 0:
|
||||||
|
return "Order does not meet minimum order value"
|
||||||
|
|
||||||
if margin_type == "ISOLATED_MARGIN":
|
if margin_type == "ISOLATED_MARGIN":
|
||||||
liq_long, liq_short = await get_liquidation_price(
|
liq_long, liq_short = await get_liquidation_price(
|
||||||
tg_id=tg_id,
|
tg_id=tg_id,
|
||||||
@@ -361,5 +335,5 @@ async def open_positions(
|
|||||||
return "InvalidRequestError"
|
return "InvalidRequestError"
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("Error opening position for user %s: %s", tg_id, e)
|
logger.error("Error opening position for user %s: %s", tg_id, e, exc_info=True)
|
||||||
return None
|
return None
|
||||||
|
@@ -140,7 +140,7 @@ class TelegramMessageHandler:
|
|||||||
await rq.set_total_fee_user_auto_trading(
|
await rq.set_total_fee_user_auto_trading(
|
||||||
tg_id=tg_id, symbol=symbol, total_fee=total_fee
|
tg_id=tg_id, symbol=symbol, total_fee=total_fee
|
||||||
)
|
)
|
||||||
text += f"Текущая ставка: {user_deals_data.order_quantity}\n"
|
text += f"Текущая ставка: {user_deals_data.order_quantity} USDT\n"
|
||||||
else:
|
else:
|
||||||
text += f"Количество: {exec_qty}\n"
|
text += f"Количество: {exec_qty}\n"
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user