The trading mode has been moved to the main settings, Position mode, limit order and conditional order have been removed. The number of bids has been renamed to the base rate. The choice of the direction of the first transaction has been moved to the main settings
This commit is contained in:
@@ -7,8 +7,8 @@ from aiogram.types import CallbackQuery
|
||||
import app.telegram.keyboards.inline as kbi
|
||||
import database.request as rq
|
||||
from app.bybit import get_bybit_client
|
||||
from app.bybit.get_functions.get_tickers import get_tickers
|
||||
from app.helper_functions import calculate_total_budget, get_base_currency, safe_float
|
||||
|
||||
from app.helper_functions import calculate_total_budget, safe_float
|
||||
from logger_helper.logger_helper import LOGGING_CONFIG
|
||||
|
||||
logging.config.dictConfig(LOGGING_CONFIG)
|
||||
@@ -40,77 +40,30 @@ async def additional_settings(callback_query: CallbackQuery, state: FSMContext)
|
||||
return
|
||||
|
||||
trade_mode_map = {
|
||||
"Merged_Single": "Односторонний режим",
|
||||
"Both_Sides": "Хеджирование",
|
||||
"Long": "Лонг",
|
||||
"Short": "Шорт",
|
||||
"Switch": "Свитч",
|
||||
}
|
||||
margin_type_map = {
|
||||
"ISOLATED_MARGIN": "Изолированная",
|
||||
"REGULAR_MARGIN": "Кросс",
|
||||
}
|
||||
order_type_map = {"Market": "Рыночный", "Limit": "Лимитный"}
|
||||
|
||||
trade_mode = additional_data.trade_mode or ""
|
||||
margin_type = additional_data.margin_type or ""
|
||||
order_type = additional_data.order_type or ""
|
||||
|
||||
trade_mode_rus = trade_mode_map.get(trade_mode, trade_mode)
|
||||
margin_type_rus = margin_type_map.get(margin_type, margin_type)
|
||||
order_type_rus = order_type_map.get(order_type, "Условный")
|
||||
switch_side = additional_data.switch_side
|
||||
|
||||
def f(x):
|
||||
return safe_float(x)
|
||||
|
||||
leverage = f(additional_data.leverage)
|
||||
leverage_to_buy = f(additional_data.leverage_to_buy)
|
||||
leverage_to_sell = f(additional_data.leverage_to_sell)
|
||||
martingale = f(additional_data.martingale_factor)
|
||||
max_bets = additional_data.max_bets_in_series
|
||||
quantity = f(additional_data.order_quantity)
|
||||
limit_price = f(additional_data.limit_price)
|
||||
trigger_price = f(additional_data.trigger_price) or 0
|
||||
|
||||
tickers = await get_tickers(tg_id=tg_id, symbol=symbol)
|
||||
price_symbol = safe_float(tickers.get("lastPrice")) or 0
|
||||
bid = f(tickers.get("bid1Price")) or 0
|
||||
ask = f(tickers.get("ask1Price")) or 0
|
||||
|
||||
sym = get_base_currency(symbol)
|
||||
|
||||
if trade_mode == "Merged_Single":
|
||||
leverage_str = f"{leverage:.2f}x"
|
||||
else:
|
||||
if margin_type == "ISOLATED_MARGIN":
|
||||
leverage_str = f"{leverage_to_buy:.2f}x:{leverage_to_sell:.2f}x"
|
||||
else:
|
||||
leverage_str = f"{leverage:.2f}x"
|
||||
|
||||
conditional_order_type = additional_data.conditional_order_type or ""
|
||||
conditional_order_type_rus = (
|
||||
"Лимитный"
|
||||
if conditional_order_type == "Limit"
|
||||
else (
|
||||
"Рыночный"
|
||||
if conditional_order_type == "Market"
|
||||
else conditional_order_type
|
||||
)
|
||||
)
|
||||
|
||||
conditional_order_type_text = (
|
||||
f"- Тип условного ордера: {conditional_order_type_rus}\n"
|
||||
if order_type == "Conditional"
|
||||
else ""
|
||||
)
|
||||
|
||||
limit_price_text = ""
|
||||
trigger_price_text = ""
|
||||
|
||||
if order_type == "Limit":
|
||||
limit_price_text = f"- Цена лимитного ордера: {limit_price:.4f} USDT\n"
|
||||
elif order_type == "Conditional":
|
||||
if conditional_order_type == "Limit":
|
||||
limit_price_text = f"- Цена лимитного ордера: {limit_price:.4f} USDT\n"
|
||||
trigger_price_text = f"- Триггер цена: {trigger_price:.4f} USDT\n"
|
||||
|
||||
risk_management_data = await rq.get_user_risk_management(tg_id=tg_id)
|
||||
commission_fee = risk_management_data.commission_fee
|
||||
client = await get_bybit_client(tg_id=tg_id)
|
||||
@@ -124,54 +77,32 @@ async def additional_settings(callback_query: CallbackQuery, state: FSMContext)
|
||||
else:
|
||||
commission_fee_percent = 0.0
|
||||
|
||||
if order_type == "Conditional":
|
||||
if conditional_order_type == "Limit":
|
||||
entry_price = limit_price
|
||||
ask_price = limit_price
|
||||
bid_price = limit_price
|
||||
else:
|
||||
ask_price = trigger_price
|
||||
bid_price = trigger_price
|
||||
entry_price = trigger_price
|
||||
else:
|
||||
if order_type == "Limit":
|
||||
entry_price = limit_price
|
||||
ask_price = limit_price
|
||||
bid_price = limit_price
|
||||
else:
|
||||
entry_price = price_symbol
|
||||
ask_price = ask
|
||||
bid_price = bid
|
||||
switch_side_mode = ""
|
||||
if trade_mode == "Switch":
|
||||
switch_side_mode = f"- Направление первой сделки: {switch_side}\n"
|
||||
|
||||
durability_buy = quantity * bid_price
|
||||
durability_sell = quantity * ask_price
|
||||
quantity_price = quantity * entry_price
|
||||
quantity_price = quantity * trigger_price
|
||||
total_commission = quantity_price * commission_fee_percent
|
||||
total_budget = await calculate_total_budget(
|
||||
quantity=durability_buy,
|
||||
quantity=quantity,
|
||||
martingale_factor=martingale,
|
||||
max_steps=max_bets,
|
||||
commission_fee_percent=total_commission,
|
||||
)
|
||||
text = (
|
||||
f"Основные настройки:\n\n"
|
||||
f"- Режим позиции: {trade_mode_rus}\n"
|
||||
f"- Режим торговли: {trade_mode_rus}\n"
|
||||
f"{switch_side_mode}"
|
||||
f"- Тип маржи: {margin_type_rus}\n"
|
||||
f"- Размер кредитного плеча: {leverage_str}\n"
|
||||
f"- Тип ордера: {order_type_rus}\n"
|
||||
f"- Количество ордера: {quantity} {sym}\n"
|
||||
f"- Размер кредитного плеча: {leverage:.2f}\n"
|
||||
f"- Базовая ставка: {quantity} USDT\n"
|
||||
f"- Коэффициент мартингейла: {martingale:.2f}\n"
|
||||
f"{conditional_order_type_text}"
|
||||
f"{trigger_price_text}"
|
||||
f"{limit_price_text}"
|
||||
f"- Триггер цена: {trigger_price:.4f} USDT\n"
|
||||
f"- Максимальное кол-во ставок в серии: {max_bets}\n\n"
|
||||
f"- Стоимость: {durability_buy:.2f}/{durability_sell:.2f} USDT\n"
|
||||
f"- Рекомендуемый бюджет: {total_budget:.4f} USDT\n"
|
||||
f"- Бюджет серии: {total_budget:.4f} USDT\n"
|
||||
)
|
||||
|
||||
keyboard = kbi.get_additional_settings_keyboard(
|
||||
current_order_type=order_type, conditional_order=conditional_order_type
|
||||
)
|
||||
keyboard = kbi.get_additional_settings_keyboard(mode=trade_mode)
|
||||
await callback_query.message.edit_text(text=text, reply_markup=keyboard)
|
||||
logger.debug(
|
||||
"Command additional_settings processed successfully for user: %s", tg_id
|
||||
@@ -202,7 +133,6 @@ async def risk_management(callback_query: CallbackQuery, state: FSMContext) -> N
|
||||
if risk_management_data:
|
||||
take_profit_percent = risk_management_data.take_profit_percent or ""
|
||||
stop_loss_percent = risk_management_data.stop_loss_percent or ""
|
||||
max_risk_percent = risk_management_data.max_risk_percent or ""
|
||||
commission_fee = risk_management_data.commission_fee or ""
|
||||
commission_fee_rus = (
|
||||
"Да" if commission_fee == "Yes_commission_fee" else "Нет"
|
||||
@@ -212,7 +142,6 @@ async def risk_management(callback_query: CallbackQuery, state: FSMContext) -> N
|
||||
text=f"Риск-менеджмент:\n\n"
|
||||
f"- Процент изменения цены для фиксации прибыли: {take_profit_percent}%\n"
|
||||
f"- Процент изменения цены для фиксации убытка: {stop_loss_percent}%\n\n"
|
||||
f"- Максимальный риск на сделку (в % от баланса): {max_risk_percent}%\n\n"
|
||||
f"- Комиссия биржи для расчета прибыли: {commission_fee_rus}\n\n",
|
||||
reply_markup=kbi.risk_management,
|
||||
)
|
||||
|
Reference in New Issue
Block a user