|
@@ -4,30 +4,22 @@ Trading Commands - Handles all trading-related Telegram commands.
|
|
|
"""
|
|
|
|
|
|
import logging
|
|
|
-from typing import Optional
|
|
|
+from typing import Optional, Dict
|
|
|
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
|
|
|
from telegram.ext import ContextTypes
|
|
|
|
|
|
from src.config.config import Config
|
|
|
-from src.utils.token_display_formatter import get_formatter, normalize_token_case
|
|
|
+from src.trading.trading_engine import TradingEngine
|
|
|
+from src.notifications.notification_manager import NotificationManager
|
|
|
+from src.commands.info.utils import normalize_token_case
|
|
|
+from src.utils.token_display_formatter import get_formatter
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
-def _normalize_token_case(token: str) -> str:
|
|
|
- """
|
|
|
- Normalize token case: if any characters are already uppercase, keep as-is.
|
|
|
- Otherwise, convert to uppercase. This handles mixed-case tokens like kPEPE, kBONK.
|
|
|
- """
|
|
|
- # Check if any character is already uppercase
|
|
|
- if any(c.isupper() for c in token):
|
|
|
- return token # Keep original case for mixed-case tokens
|
|
|
- else:
|
|
|
- return token.upper() # Convert to uppercase for all-lowercase input
|
|
|
-
|
|
|
class TradingCommands:
|
|
|
"""Handles all trading-related Telegram commands."""
|
|
|
|
|
|
- def __init__(self, trading_engine, notification_manager, management_commands_handler=None, info_commands_handler=None):
|
|
|
+ def __init__(self, trading_engine: TradingEngine, notification_manager: NotificationManager, management_commands_handler=None, info_commands_handler=None):
|
|
|
"""Initialize trading commands with required dependencies."""
|
|
|
self.trading_engine = trading_engine
|
|
|
self.notification_manager = notification_manager
|
|
@@ -57,7 +49,7 @@ class TradingCommands:
|
|
|
))
|
|
|
return
|
|
|
|
|
|
- token = _normalize_token_case(context.args[0])
|
|
|
+ token = normalize_token_case(context.args[0])
|
|
|
usdc_amount = float(context.args[1])
|
|
|
|
|
|
# Parse arguments for price and stop loss
|
|
@@ -182,7 +174,7 @@ This will {"place a limit buy order" if limit_price else "execute a market buy o
|
|
|
))
|
|
|
return
|
|
|
|
|
|
- token = _normalize_token_case(context.args[0])
|
|
|
+ token = normalize_token_case(context.args[0])
|
|
|
usdc_amount = float(context.args[1])
|
|
|
|
|
|
# Parse arguments (similar to long_command)
|
|
@@ -301,7 +293,7 @@ This will {"place a limit sell order" if limit_price else "execute a market sell
|
|
|
))
|
|
|
return
|
|
|
|
|
|
- token = _normalize_token_case(context.args[0])
|
|
|
+ token = normalize_token_case(context.args[0])
|
|
|
|
|
|
# Find the position
|
|
|
position = await self.trading_engine.find_position(token)
|
|
@@ -378,7 +370,7 @@ This will {"place a limit sell order" if limit_price else "execute a market sell
|
|
|
))
|
|
|
return
|
|
|
|
|
|
- token = _normalize_token_case(context.args[0])
|
|
|
+ token = normalize_token_case(context.args[0])
|
|
|
stop_price = float(context.args[1])
|
|
|
|
|
|
# Find the position
|
|
@@ -491,7 +483,7 @@ This will place a limit {exit_side} order at {await formatter.format_price_with_
|
|
|
))
|
|
|
return
|
|
|
|
|
|
- token = _normalize_token_case(context.args[0])
|
|
|
+ token = normalize_token_case(context.args[0])
|
|
|
tp_price = float(context.args[1])
|
|
|
|
|
|
# Find the position
|
|
@@ -595,7 +587,7 @@ This will place a limit {exit_side} order at {await formatter.format_price_with_
|
|
|
))
|
|
|
return
|
|
|
|
|
|
- token = _normalize_token_case(context.args[0])
|
|
|
+ token = normalize_token_case(context.args[0])
|
|
|
|
|
|
confirmation_text = f"""
|
|
|
🚫 <b>Cancel All Orders Confirmation</b>
|