|
@@ -21,12 +21,12 @@ class OrdersCommands(InfoCommandsBase):
|
|
|
|
|
|
# Get pending stop loss orders from the database
|
|
|
stats = self.trading_engine.get_stats()
|
|
|
- pending_sl_orders = []
|
|
|
+ pending_sl_lifecycles = []
|
|
|
if stats:
|
|
|
- pending_sl_orders = stats.get_orders_by_status('pending_trigger')
|
|
|
+ pending_sl_lifecycles = stats.get_pending_stop_losses_from_lifecycles()
|
|
|
|
|
|
# Combine both lists
|
|
|
- all_orders = open_orders + pending_sl_orders
|
|
|
+ all_orders = open_orders + pending_sl_lifecycles
|
|
|
|
|
|
if not all_orders:
|
|
|
await self._reply(update, "📭 No open or pending orders")
|
|
@@ -37,19 +37,22 @@ class OrdersCommands(InfoCommandsBase):
|
|
|
|
|
|
for order in all_orders:
|
|
|
try:
|
|
|
- is_pending_sl = order.get('status') == 'pending_trigger'
|
|
|
-
|
|
|
+ is_pending_sl = 'trade_lifecycle_id' in order and order.get('stop_loss_price') is not None
|
|
|
+
|
|
|
symbol = order.get('symbol', 'unknown')
|
|
|
base_asset = symbol.split('/')[0] if '/' in symbol else symbol.split(':')[0]
|
|
|
|
|
|
if is_pending_sl:
|
|
|
+ # This is a pending SL from a trade lifecycle
|
|
|
+ entry_side = order.get('side', 'unknown').upper()
|
|
|
order_type = "STOP (PENDING)"
|
|
|
- side = order.get('side', 'unknown').upper()
|
|
|
- price = float(order.get('price', 0)) # This is the trigger price for pending SL
|
|
|
- amount = float(order.get('amount_requested', 0))
|
|
|
- status = "PENDING TRIGGER"
|
|
|
- order_id = order.get('bot_order_ref_id', 'unknown')
|
|
|
+ side = "SELL" if entry_side == "BUY" else "BUY"
|
|
|
+ price = float(order.get('stop_loss_price', 0))
|
|
|
+ amount = float(order.get('amount', 0)) # Amount from the entry order
|
|
|
+ status = f"Awaiting {order.get('status', '').upper()} Entry" # e.g. Awaiting PENDING Entry
|
|
|
+ order_id = order.get('trade_lifecycle_id', 'unknown')
|
|
|
else:
|
|
|
+ # This is a regular exchange order
|
|
|
order_type = order.get('type', 'unknown').upper()
|
|
|
side = order.get('side', 'unknown').upper()
|
|
|
price = float(order.get('price', 0))
|
|
@@ -60,20 +63,20 @@ class OrdersCommands(InfoCommandsBase):
|
|
|
order_id = order.get('id', 'unknown')
|
|
|
|
|
|
# Skip fully filled orders
|
|
|
- if amount <= 0:
|
|
|
+ if amount <= 0 and not is_pending_sl:
|
|
|
continue
|
|
|
|
|
|
# Format order details
|
|
|
formatter = self._get_formatter()
|
|
|
price_str = await formatter.format_price_with_symbol(price, base_asset)
|
|
|
- amount_str = await formatter.format_amount(amount, base_asset)
|
|
|
+ amount_str = await formatter.format_amount(amount, base_asset) if amount > 0 else "N/A"
|
|
|
|
|
|
# Order header
|
|
|
side_emoji = "🟢" if side == "BUY" else "🔴"
|
|
|
orders_text += f"{side_emoji} <b>{base_asset} {side} {order_type}</b>\n"
|
|
|
- orders_text += f" Status: {status}\n"
|
|
|
- orders_text += f" 📏 Amount: {amount_str} {base_asset}\n"
|
|
|
- orders_text += f" 💰 {'Trigger Price' if is_pending_sl else 'Price'}: {price_str}\n"
|
|
|
+ orders_text += f" Status: {status.replace('_', ' ')}\n"
|
|
|
+ orders_text += f" 📏 Amount: {amount_str}\n"
|
|
|
+ orders_text += f" 💰 {'Trigger Price' if 'STOP' in order_type else 'Price'}: {price_str}\n"
|
|
|
|
|
|
# Add order type specific info for exchange orders
|
|
|
if not is_pending_sl and (order_type == "STOP_LOSS" or order_type == "TAKE_PROFIT"):
|
|
@@ -83,8 +86,8 @@ class OrdersCommands(InfoCommandsBase):
|
|
|
orders_text += f" 🎯 Trigger: {trigger_price_str}\n"
|
|
|
|
|
|
# Add order ID
|
|
|
- id_label = "Bot Ref ID" if is_pending_sl else "Order ID"
|
|
|
- orders_text += f" 🆔 {id_label}: {order_id[:12]}\n\n"
|
|
|
+ id_label = "Lifecycle ID" if is_pending_sl else "Order ID"
|
|
|
+ orders_text += f" 🆔 {id_label}: {str(order_id)[:12]}\n\n"
|
|
|
|
|
|
except Exception as e:
|
|
|
logger.error(f"Error processing order {order.get('symbol', 'unknown')}: {e}", exc_info=True)
|