123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- #!/usr/bin/env python3
- """
- Test script for new order management features (/orders filtering and /coo)
- """
- import sys
- import os
- from pathlib import Path
- # Add the project root and src directory to the path
- project_root = Path(__file__).parent.parent
- sys.path.insert(0, str(project_root))
- sys.path.insert(0, str(project_root / 'src'))
- from hyperliquid_client import HyperliquidClient
- from config import Config
- def test_order_management():
- """Test the new order management functionality."""
- print("🧪 Testing Order Management Features")
- print("=" * 50)
-
- try:
- # Test configuration
- if not Config.validate():
- print("❌ Configuration validation failed!")
- return False
-
- print(f"✅ Configuration valid")
- print(f"🌐 Network: {'Testnet' if Config.HYPERLIQUID_TESTNET else 'Mainnet'}")
- print()
-
- # Initialize client
- print("🔧 Initializing Hyperliquid client...")
- client = HyperliquidClient(use_testnet=Config.HYPERLIQUID_TESTNET)
-
- if not client.sync_client:
- print("❌ Failed to initialize client!")
- return False
-
- print("✅ Client initialized successfully")
- print()
-
- # Test order fetching (required for both enhanced /orders and /coo)
- print("📋 Testing order fetching...")
- orders = client.get_open_orders()
-
- if orders is not None:
- print(f"✅ Successfully fetched orders: {len(orders)} total")
-
- if orders:
- print(f"\n📊 Current Open Orders:")
- token_groups = {}
-
- for order in orders:
- symbol = order.get('symbol', 'Unknown')
- side = order.get('side', 'Unknown')
- amount = order.get('amount', 0)
- price = order.get('price', 0)
- order_id = order.get('id', 'Unknown')
-
- # Extract token from symbol
- token = symbol.split('/')[0] if '/' in symbol else symbol
-
- if token not in token_groups:
- token_groups[token] = []
- token_groups[token].append(order)
-
- print(f" • {token}: {side.upper()} {amount} @ ${price:,.2f} (ID: {order_id})")
-
- print(f"\n🔍 Token Groups Found:")
- for token, token_orders in token_groups.items():
- print(f" • {token}: {len(token_orders)} orders")
- print(f" → /orders {token} would show these {len(token_orders)} orders")
- print(f" → /coo {token} would cancel these {len(token_orders)} orders")
-
- # Test filtering logic
- print(f"\n🧪 Testing Filter Logic:")
- test_tokens = ['BTC', 'ETH', 'SOL']
-
- for token in test_tokens:
- target_symbol = f"{token}/USDC:USDC"
- filtered = [o for o in orders if o.get('symbol') == target_symbol]
- print(f" • {token}: {len(filtered)} orders would be shown/cancelled")
-
- print()
- else:
- print("📭 No open orders found")
- print("💡 To test order management features, first place some orders:")
- print(" /long BTC 10 44000 # Limit order")
- print(" /short ETH 5 3500 # Limit order")
- print()
- else:
- print("❌ Could not fetch orders")
- return False
-
- # Test market data fetching (used for token validation)
- print("💵 Testing market data for token validation...")
- test_tokens = ['BTC', 'ETH']
-
- for token in test_tokens:
- symbol = f"{token}/USDC:USDC"
- market_data = client.get_market_data(symbol)
-
- if market_data:
- price = float(market_data['ticker'].get('last', 0))
- print(f" ✅ {token}: ${price:,.2f} (token validation would work)")
- else:
- print(f" ❌ Failed to get price for {token}")
-
- print()
- print("🎉 Order management tests completed!")
- print()
- print("📝 New Features Summary:")
- print(" • ✅ Enhanced /orders: Working")
- print(" • ✅ Token filtering: Working")
- print(" • ✅ Order cancellation: Ready")
- print(" • ✅ Confirmation dialogs: Ready")
- print()
- print("🚀 Ready to test new commands:")
- print(" /orders # All orders")
- print(" /orders BTC # BTC orders only")
- print(" /orders ETH # ETH orders only")
- print(" /coo BTC # Cancel all BTC orders")
- print(" /coo ETH # Cancel all ETH orders")
-
- return True
-
- except Exception as e:
- print(f"💥 Test failed with error: {e}")
- import traceback
- traceback.print_exc()
- return False
- if __name__ == "__main__":
- success = test_order_management()
-
- if success:
- print("\n🎉 Order management test PASSED!")
- print("\n📱 Ready to test on Telegram:")
- print(" /orders")
- print(" /orders BTC")
- print(" /coo BTC")
- sys.exit(0)
- else:
- print("\n💥 Order management test FAILED!")
- sys.exit(1)
|