Stage 07.3.3: multi live screens and UI optimization
This commit is contained in:
@@ -11,6 +11,7 @@ from src.integrations.exchange.exceptions import ExchangeError
|
||||
from src.integrations.exchange.service import ExchangeService
|
||||
from src.telegram.live.runner import LiveScreen, LiveScreenRunner
|
||||
from src.telegram.ui.common import mode_line, now_line
|
||||
from src.telegram.ui.currency_ui import format_usd_amount
|
||||
from src.telegram.ui.exchange_error import (
|
||||
classify_exchange_error,
|
||||
show_callback_exchange_error,
|
||||
@@ -21,6 +22,8 @@ from src.trading.journal.service import JournalService
|
||||
|
||||
|
||||
router = Router(name="market")
|
||||
_last_market_prices: dict[str, float] = {}
|
||||
_last_market_directions: dict[str, str] = {}
|
||||
|
||||
|
||||
# клавиатура экрана рынка
|
||||
@@ -36,20 +39,21 @@ def _build_market_text(
|
||||
*,
|
||||
ticker_price: float,
|
||||
name: str,
|
||||
symbol_status: str,
|
||||
market_type: str,
|
||||
base_asset: str,
|
||||
quote_asset: str,
|
||||
tick_size: str,
|
||||
) -> str:
|
||||
from src.telegram.ui.common import now_line
|
||||
previous_price = _last_market_prices.get(name)
|
||||
price_direction = _last_market_directions.get(name, "▲")
|
||||
|
||||
status_map = {
|
||||
"TRADING": "доступен для торговли",
|
||||
"HALT": "торги остановлены",
|
||||
"BREAK": "перерыв",
|
||||
}
|
||||
status_ru = status_map.get(symbol_status.upper(), symbol_status.lower())
|
||||
if previous_price is not None:
|
||||
if ticker_price > previous_price:
|
||||
price_direction = "▲"
|
||||
elif ticker_price < previous_price:
|
||||
price_direction = "▼"
|
||||
|
||||
_last_market_prices[name] = ticker_price
|
||||
_last_market_directions[name] = price_direction
|
||||
|
||||
type_map = {
|
||||
"LEVERAGE": "leverage",
|
||||
@@ -60,13 +64,9 @@ def _build_market_text(
|
||||
return (
|
||||
"<b>📈 Рынок</b>\n"
|
||||
f"{mode_line()}"
|
||||
f"Пара: <b>{name}</b>\n"
|
||||
f"Цена: <b>{ticker_price:.2f} {quote_asset}</b>\n"
|
||||
f"Статус: {status_ru}\n"
|
||||
f"Тип инструмента: {market_type_ru}\n"
|
||||
f"Базовый актив: {base_asset}\n"
|
||||
f"Валюта котировки: {quote_asset}\n"
|
||||
f"Шаг цены: {tick_size} {quote_asset}\n\n"
|
||||
"\n"
|
||||
f"<b>{base_asset} / {quote_asset}</b> ({market_type_ru})\n\n"
|
||||
f"<b>$ {format_usd_amount(ticker_price)}</b> {price_direction}\n\n"
|
||||
f"{now_line()}"
|
||||
)
|
||||
|
||||
@@ -89,13 +89,7 @@ def _build_market_live_text() -> str:
|
||||
ticker = service.get_price(validation.normalized_symbol)
|
||||
|
||||
symbol_info = validation.symbol_info
|
||||
symbol_status = symbol_info.status if symbol_info else "n/a"
|
||||
market_type = symbol_info.market_type if symbol_info else "n/a"
|
||||
tick_size = (
|
||||
f"{symbol_info.tick_size}"
|
||||
if symbol_info and symbol_info.tick_size is not None
|
||||
else "n/a"
|
||||
)
|
||||
base_asset = symbol_info.base_asset if symbol_info and symbol_info.base_asset else "n/a"
|
||||
quote_asset = symbol_info.quote_asset if symbol_info and symbol_info.quote_asset else "n/a"
|
||||
name = symbol_info.name if symbol_info and symbol_info.name else ticker.symbol
|
||||
@@ -103,11 +97,9 @@ def _build_market_live_text() -> str:
|
||||
return _build_market_text(
|
||||
ticker_price=ticker.price,
|
||||
name=name,
|
||||
symbol_status=symbol_status,
|
||||
market_type=market_type,
|
||||
base_asset=base_asset,
|
||||
quote_asset=quote_asset,
|
||||
tick_size=tick_size,
|
||||
)
|
||||
|
||||
|
||||
@@ -137,7 +129,6 @@ async def _render_market_screen(
|
||||
action: str,
|
||||
) -> None:
|
||||
AutoTradeRunner.set_current_screen("market")
|
||||
LiveScreenRunner.set_current_screen("market")
|
||||
|
||||
service = ExchangeService()
|
||||
journal = JournalService()
|
||||
@@ -188,13 +179,7 @@ async def _render_market_screen(
|
||||
ticker = service.get_price(validation.normalized_symbol)
|
||||
|
||||
symbol_info = validation.symbol_info
|
||||
symbol_status = symbol_info.status if symbol_info else "n/a"
|
||||
market_type = symbol_info.market_type if symbol_info else "n/a"
|
||||
tick_size = (
|
||||
f"{symbol_info.tick_size}"
|
||||
if symbol_info and symbol_info.tick_size is not None
|
||||
else "n/a"
|
||||
)
|
||||
base_asset = symbol_info.base_asset if symbol_info and symbol_info.base_asset else "n/a"
|
||||
quote_asset = symbol_info.quote_asset if symbol_info and symbol_info.quote_asset else "n/a"
|
||||
name = symbol_info.name if symbol_info and symbol_info.name else ticker.symbol
|
||||
@@ -202,11 +187,9 @@ async def _render_market_screen(
|
||||
text = _build_market_text(
|
||||
ticker_price=ticker.price,
|
||||
name=name,
|
||||
symbol_status=symbol_status,
|
||||
market_type=market_type,
|
||||
base_asset=base_asset,
|
||||
quote_asset=quote_asset,
|
||||
tick_size=tick_size,
|
||||
)
|
||||
|
||||
journal.log_ui_info(
|
||||
|
||||
Reference in New Issue
Block a user