|
@@ -9,6 +9,7 @@ from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
|
|
|
from telegram.ext import ContextTypes
|
|
|
|
|
|
from src.config.config import Config
|
|
|
+from src.utils.price_formatter import get_formatter
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
@@ -92,31 +93,33 @@ class TradingCommands:
|
|
|
|
|
|
# Validate stop loss for long positions
|
|
|
if stop_loss_price and stop_loss_price >= price:
|
|
|
+ formatter = get_formatter()
|
|
|
await context.bot.send_message(chat_id=chat_id, text=(
|
|
|
f"⚠️ Stop loss price should be BELOW entry price for long positions\n\n"
|
|
|
f"📊 Your order:\n"
|
|
|
- f"• Entry Price: ${price:,.2f}\n"
|
|
|
- f"• Stop Loss: ${stop_loss_price:,.2f} ❌\n\n"
|
|
|
- f"💡 Try a lower stop loss like: sl:{price * 0.95:.0f}"
|
|
|
+ f"• Entry Price: {formatter.format_price_with_symbol(price, token)}\n"
|
|
|
+ f"• Stop Loss: {formatter.format_price_with_symbol(stop_loss_price, token)} ❌\n\n"
|
|
|
+ f"💡 Try a lower stop loss like: sl:{formatter.format_price(price * 0.95, token)}"
|
|
|
))
|
|
|
return
|
|
|
|
|
|
# Create confirmation message
|
|
|
+ formatter = get_formatter()
|
|
|
confirmation_text = f"""
|
|
|
🟢 <b>Long Order Confirmation</b>
|
|
|
|
|
|
📊 <b>Order Details:</b>
|
|
|
• Token: {token}
|
|
|
-• USDC Amount: ${usdc_amount:,.2f}
|
|
|
+• USDC Amount: {formatter.format_price_with_symbol(usdc_amount)}
|
|
|
• Token Amount: {token_amount:.6f} {token}
|
|
|
• Order Type: {order_type}
|
|
|
-• Price: ${price:,.2f}
|
|
|
-• Current Price: ${current_price:,.2f}
|
|
|
-• Est. Value: ${token_amount * price:,.2f}"""
|
|
|
+• Price: {formatter.format_price_with_symbol(price, token)}
|
|
|
+• Current Price: {formatter.format_price_with_symbol(current_price, token)}
|
|
|
+• Est. Value: {formatter.format_price_with_symbol(token_amount * price)}"""
|
|
|
|
|
|
if stop_loss_price:
|
|
|
confirmation_text += f"""
|
|
|
-• 🛑 Stop Loss: ${stop_loss_price:,.2f}"""
|
|
|
+• 🛑 Stop Loss: {formatter.format_price_with_symbol(stop_loss_price, token)}"""
|
|
|
|
|
|
confirmation_text += f"""
|
|
|
|
|
@@ -211,31 +214,33 @@ This will {"place a limit buy order" if limit_price else "execute a market buy o
|
|
|
|
|
|
# Validate stop loss for short positions
|
|
|
if stop_loss_price and stop_loss_price <= price:
|
|
|
+ formatter = get_formatter()
|
|
|
await context.bot.send_message(chat_id=chat_id, text=(
|
|
|
f"⚠️ Stop loss price should be ABOVE entry price for short positions\n\n"
|
|
|
f"📊 Your order:\n"
|
|
|
- f"• Entry Price: ${price:,.2f}\n"
|
|
|
- f"• Stop Loss: ${stop_loss_price:,.2f} ❌\n\n"
|
|
|
- f"💡 Try a higher stop loss like: sl:{price * 1.05:.0f}"
|
|
|
+ f"• Entry Price: {formatter.format_price_with_symbol(price, token)}\n"
|
|
|
+ f"• Stop Loss: {formatter.format_price_with_symbol(stop_loss_price, token)} ❌\n\n"
|
|
|
+ f"💡 Try a higher stop loss like: sl:{formatter.format_price(price * 1.05, token)}"
|
|
|
))
|
|
|
return
|
|
|
|
|
|
# Create confirmation message
|
|
|
+ formatter = get_formatter()
|
|
|
confirmation_text = f"""
|
|
|
🔴 <b>Short Order Confirmation</b>
|
|
|
|
|
|
📊 <b>Order Details:</b>
|
|
|
• Token: {token}
|
|
|
-• USDC Amount: ${usdc_amount:,.2f}
|
|
|
+• USDC Amount: {formatter.format_price_with_symbol(usdc_amount)}
|
|
|
• Token Amount: {token_amount:.6f} {token}
|
|
|
• Order Type: {order_type}
|
|
|
-• Price: ${price:,.2f}
|
|
|
-• Current Price: ${current_price:,.2f}
|
|
|
-• Est. Value: ${token_amount * price:,.2f}"""
|
|
|
+• Price: {formatter.format_price_with_symbol(price, token)}
|
|
|
+• Current Price: {formatter.format_price_with_symbol(current_price, token)}
|
|
|
+• Est. Value: {formatter.format_price_with_symbol(token_amount * price)}"""
|
|
|
|
|
|
if stop_loss_price:
|
|
|
confirmation_text += f"""
|
|
|
-• 🛑 Stop Loss: ${stop_loss_price:,.2f}"""
|
|
|
+• 🛑 Stop Loss: {formatter.format_price_with_symbol(stop_loss_price, token)}"""
|
|
|
|
|
|
confirmation_text += f"""
|
|
|
|
|
@@ -315,15 +320,15 @@ This will {"place a limit sell order" if limit_price else "execute a market sell
|
|
|
📊 <b>Position Details:</b>
|
|
|
• Token: {token}
|
|
|
• Position: {position_type}
|
|
|
-• Size: {contracts:.6f} contracts
|
|
|
-• Entry Price: ${entry_price:,.2f}
|
|
|
-• Current Price: ${current_price:,.2f}
|
|
|
-• {pnl_emoji} Unrealized P&L: ${unrealized_pnl:,.2f}
|
|
|
+• Size: {get_formatter(contracts)} contracts
|
|
|
+• Entry Price: {get_formatter(entry_price)}
|
|
|
+• Current Price: {get_formatter(current_price)}
|
|
|
+• {pnl_emoji} Unrealized P&L: {get_formatter(unrealized_pnl)}
|
|
|
|
|
|
🎯 <b>Exit Order:</b>
|
|
|
• Action: {exit_side.upper()} (Close {position_type})
|
|
|
-• Amount: {contracts:.6f} {token}
|
|
|
-• Est. Value: ~${exit_value:,.2f}
|
|
|
+• Amount: {get_formatter(contracts)} {token}
|
|
|
+• Est. Value: ~{get_formatter(exit_value)}
|
|
|
• Order Type: Market Order
|
|
|
|
|
|
⚠️ <b>Are you sure you want to close this {position_type} position?</b>
|
|
@@ -377,18 +382,18 @@ This will {"place a limit sell order" if limit_price else "execute a market sell
|
|
|
await context.bot.send_message(chat_id=chat_id, text=(
|
|
|
f"⚠️ Stop loss price should be BELOW entry price for long positions\n\n"
|
|
|
f"📊 Your {token} LONG position:\n"
|
|
|
- f"• Entry Price: ${entry_price:,.2f}\n"
|
|
|
- f"• Stop Price: ${stop_price:,.2f} ❌\n\n"
|
|
|
- f"💡 Try a lower price like: /sl {token} {entry_price * 0.95:.0f}"
|
|
|
+ f"• Entry Price: {get_formatter(entry_price)}\n"
|
|
|
+ f"• Stop Price: {get_formatter(stop_price)} ❌\n\n"
|
|
|
+ f"💡 Try a lower price like: /sl {token} {get_formatter(entry_price * 0.95)}\n"
|
|
|
))
|
|
|
return
|
|
|
elif position_type == "SHORT" and stop_price <= entry_price:
|
|
|
await context.bot.send_message(chat_id=chat_id, text=(
|
|
|
f"⚠️ Stop loss price should be ABOVE entry price for short positions\n\n"
|
|
|
f"📊 Your {token} SHORT position:\n"
|
|
|
- f"• Entry Price: ${entry_price:,.2f}\n"
|
|
|
- f"• Stop Price: ${stop_price:,.2f} ❌\n\n"
|
|
|
- f"💡 Try a higher price like: /sl {token} {entry_price * 1.05:.0f}"
|
|
|
+ f"• Entry Price: {get_formatter(entry_price)}\n"
|
|
|
+ f"• Stop Price: {get_formatter(stop_price)} ❌\n\n"
|
|
|
+ f"💡 Try a higher price like: /sl {token} {get_formatter(entry_price * 1.05)}\n"
|
|
|
))
|
|
|
return
|
|
|
|
|
@@ -412,20 +417,20 @@ This will {"place a limit sell order" if limit_price else "execute a market sell
|
|
|
📊 <b>Position Details:</b>
|
|
|
• Token: {token}
|
|
|
• Position: {position_type}
|
|
|
-• Size: {contracts:.6f} contracts
|
|
|
-• Entry Price: ${entry_price:,.2f}
|
|
|
-• Current Price: ${current_price:,.2f}
|
|
|
+• Size: {get_formatter(contracts)} contracts
|
|
|
+• Entry Price: {get_formatter(entry_price)}
|
|
|
+• Current Price: {get_formatter(current_price)}
|
|
|
|
|
|
🎯 <b>Stop Loss Order:</b>
|
|
|
-• Stop Price: ${stop_price:,.2f}
|
|
|
+• Stop Price: {get_formatter(stop_price)}
|
|
|
• Action: {exit_side.upper()} (Close {position_type})
|
|
|
-• Amount: {contracts:.6f} {token}
|
|
|
+• Amount: {get_formatter(contracts)} {token}
|
|
|
• Order Type: Limit Order
|
|
|
-• {pnl_emoji} Est. P&L: ${pnl_at_stop:,.2f}
|
|
|
+• {pnl_emoji} Est. P&L: {get_formatter(pnl_at_stop)}
|
|
|
|
|
|
⚠️ <b>Are you sure you want to set this stop loss?</b>
|
|
|
|
|
|
-This will place a limit {exit_side} order at ${stop_price:,.2f} to protect your {position_type} position.
|
|
|
+This will place a limit {exit_side} order at {get_formatter(stop_price)} to protect your {position_type} position.
|
|
|
"""
|
|
|
|
|
|
keyboard = [
|
|
@@ -478,18 +483,18 @@ This will place a limit {exit_side} order at ${stop_price:,.2f} to protect your
|
|
|
await context.bot.send_message(chat_id=chat_id, text=(
|
|
|
f"⚠️ Take profit price should be ABOVE entry price for long positions\n\n"
|
|
|
f"📊 Your {token} LONG position:\n"
|
|
|
- f"• Entry Price: ${entry_price:,.2f}\n"
|
|
|
- f"• Take Profit: ${tp_price:,.2f} ❌\n\n"
|
|
|
- f"💡 Try a higher price like: /tp {token} {entry_price * 1.05:.0f}"
|
|
|
+ f"• Entry Price: {get_formatter(entry_price)}\n"
|
|
|
+ f"• Take Profit: {get_formatter(tp_price)} ❌\n\n"
|
|
|
+ f"💡 Try a higher price like: /tp {token} {get_formatter(entry_price * 1.05)}\n"
|
|
|
))
|
|
|
return
|
|
|
elif position_type == "SHORT" and tp_price >= entry_price:
|
|
|
await context.bot.send_message(chat_id=chat_id, text=(
|
|
|
f"⚠️ Take profit price should be BELOW entry price for short positions\n\n"
|
|
|
f"📊 Your {token} SHORT position:\n"
|
|
|
- f"• Entry Price: ${entry_price:,.2f}\n"
|
|
|
- f"• Take Profit: ${tp_price:,.2f} ❌\n\n"
|
|
|
- f"💡 Try a lower price like: /tp {token} {entry_price * 0.95:.0f}"
|
|
|
+ f"• Entry Price: {get_formatter(entry_price)}\n"
|
|
|
+ f"• Take Profit: {get_formatter(tp_price)} ❌\n\n"
|
|
|
+ f"💡 Try a lower price like: /tp {token} {get_formatter(entry_price * 0.95)}\n"
|
|
|
))
|
|
|
return
|
|
|
|
|
@@ -513,20 +518,20 @@ This will place a limit {exit_side} order at ${stop_price:,.2f} to protect your
|
|
|
📊 <b>Position Details:</b>
|
|
|
• Token: {token}
|
|
|
• Position: {position_type}
|
|
|
-• Size: {contracts:.6f} contracts
|
|
|
-• Entry Price: ${entry_price:,.2f}
|
|
|
-• Current Price: ${current_price:,.2f}
|
|
|
+• Size: {get_formatter(contracts)} contracts
|
|
|
+• Entry Price: {get_formatter(entry_price)}
|
|
|
+• Current Price: {get_formatter(current_price)}
|
|
|
|
|
|
🎯 <b>Take Profit Order:</b>
|
|
|
-• Take Profit Price: ${tp_price:,.2f}
|
|
|
+• Take Profit Price: {get_formatter(tp_price)}
|
|
|
• Action: {exit_side.upper()} (Close {position_type})
|
|
|
-• Amount: {contracts:.6f} {token}
|
|
|
+• Amount: {get_formatter(contracts)} {token}
|
|
|
• Order Type: Limit Order
|
|
|
-• {pnl_emoji} Est. P&L: ${pnl_at_tp:,.2f}
|
|
|
+• {pnl_emoji} Est. P&L: {get_formatter(pnl_at_tp)}
|
|
|
|
|
|
⚠️ <b>Are you sure you want to set this take profit?</b>
|
|
|
|
|
|
-This will place a limit {exit_side} order at ${tp_price:,.2f} to secure profits from your {position_type} position.
|
|
|
+This will place a limit {exit_side} order at {get_formatter(tp_price)} to secure profits from your {position_type} position.
|
|
|
"""
|
|
|
|
|
|
keyboard = [
|