|
@@ -742,15 +742,24 @@ Tap any button below for instant access to bot functions:
|
|
|
parts = callback_data.split('_')
|
|
|
token = parts[2]
|
|
|
usdc_amount = float(parts[3])
|
|
|
- price = float(parts[4])
|
|
|
+ try:
|
|
|
+ price = float(parts[4])
|
|
|
+ except (ValueError, TypeError):
|
|
|
+ price = None # Will be handled in execute_long_order
|
|
|
is_limit = len(parts) > 5 and parts[5] == 'limit'
|
|
|
|
|
|
# Parse stop loss if present
|
|
|
stop_loss_price = None
|
|
|
if len(parts) > 6 and parts[6] == 'sl':
|
|
|
- stop_loss_price = float(parts[7])
|
|
|
+ try:
|
|
|
+ stop_loss_price = float(parts[7])
|
|
|
+ except (ValueError, TypeError):
|
|
|
+ stop_loss_price = None
|
|
|
elif len(parts) > 5 and parts[5] == 'sl':
|
|
|
- stop_loss_price = float(parts[6])
|
|
|
+ try:
|
|
|
+ stop_loss_price = float(parts[6])
|
|
|
+ except (ValueError, TypeError):
|
|
|
+ stop_loss_price = None
|
|
|
|
|
|
await self._execute_long_order(query, token, usdc_amount, price, is_limit, stop_loss_price)
|
|
|
return
|
|
@@ -759,15 +768,24 @@ Tap any button below for instant access to bot functions:
|
|
|
parts = callback_data.split('_')
|
|
|
token = parts[2]
|
|
|
usdc_amount = float(parts[3])
|
|
|
- price = float(parts[4])
|
|
|
+ try:
|
|
|
+ price = float(parts[4])
|
|
|
+ except (ValueError, TypeError):
|
|
|
+ price = None # Will be handled in execute_short_order
|
|
|
is_limit = len(parts) > 5 and parts[5] == 'limit'
|
|
|
|
|
|
# Parse stop loss if present
|
|
|
stop_loss_price = None
|
|
|
if len(parts) > 6 and parts[6] == 'sl':
|
|
|
- stop_loss_price = float(parts[7])
|
|
|
+ try:
|
|
|
+ stop_loss_price = float(parts[7])
|
|
|
+ except (ValueError, TypeError):
|
|
|
+ stop_loss_price = None
|
|
|
elif len(parts) > 5 and parts[5] == 'sl':
|
|
|
- stop_loss_price = float(parts[6])
|
|
|
+ try:
|
|
|
+ stop_loss_price = float(parts[6])
|
|
|
+ except (ValueError, TypeError):
|
|
|
+ stop_loss_price = None
|
|
|
|
|
|
await self._execute_short_order(query, token, usdc_amount, price, is_limit, stop_loss_price)
|
|
|
return
|
|
@@ -855,6 +873,19 @@ Tap any button below for instant access to bot functions:
|
|
|
try:
|
|
|
await query.edit_message_text("⏳ Opening long position...")
|
|
|
|
|
|
+ # Validate price
|
|
|
+ if price is None or price <= 0:
|
|
|
+ # Try to get current market price
|
|
|
+ market_data = self.client.get_market_data(symbol)
|
|
|
+ if market_data and market_data.get('ticker'):
|
|
|
+ price = float(market_data['ticker'].get('last', 0))
|
|
|
+ if price <= 0:
|
|
|
+ await query.edit_message_text("❌ Unable to get valid market price. Please try again.")
|
|
|
+ return
|
|
|
+ else:
|
|
|
+ await query.edit_message_text("❌ Unable to fetch market price. Please try again.")
|
|
|
+ return
|
|
|
+
|
|
|
# Calculate token amount based on USDC value and price
|
|
|
token_amount = usdc_amount / price
|
|
|
|
|
@@ -925,6 +956,19 @@ Tap any button below for instant access to bot functions:
|
|
|
try:
|
|
|
await query.edit_message_text("⏳ Opening short position...")
|
|
|
|
|
|
+ # Validate price
|
|
|
+ if price is None or price <= 0:
|
|
|
+ # Try to get current market price
|
|
|
+ market_data = self.client.get_market_data(symbol)
|
|
|
+ if market_data and market_data.get('ticker'):
|
|
|
+ price = float(market_data['ticker'].get('last', 0))
|
|
|
+ if price <= 0:
|
|
|
+ await query.edit_message_text("❌ Unable to get valid market price. Please try again.")
|
|
|
+ return
|
|
|
+ else:
|
|
|
+ await query.edit_message_text("❌ Unable to fetch market price. Please try again.")
|
|
|
+ return
|
|
|
+
|
|
|
# Calculate token amount based on USDC value and price
|
|
|
token_amount = usdc_amount / price
|
|
|
|