12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- #!/usr/bin/env python3
- """
- Test script for new perps trading commands
- """
- 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_perps_commands():
- """Test the perps trading functionality."""
- print("🧪 Testing Perps Trading Commands")
- 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 token symbol conversion
- tokens_to_test = ['BTC', 'ETH', 'SOL']
-
- for token in tokens_to_test:
- print(f"📊 Testing {token}...")
-
- # Convert to full symbol
- symbol = f"{token}/USDC:USDC"
- print(f" Symbol: {token} → {symbol}")
-
- # Test market data fetching
- market_data = client.get_market_data(symbol)
-
- if market_data:
- price = float(market_data['ticker'].get('last', 0))
- print(f" ✅ Current price: ${price:,.2f}")
-
- # Test calculation
- usdc_amount = 100
- token_amount = usdc_amount / price
- print(f" 📈 Long ${usdc_amount} USDC = {token_amount:.6f} {token}")
- print(f" 📉 Short ${usdc_amount} USDC = {token_amount:.6f} {token}")
-
- else:
- print(f" ❌ Could not fetch price for {token}")
-
- print()
-
- 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_perps_commands()
-
- if success:
- print("🎉 Perps commands test PASSED!")
- print("\n📱 Ready to test on Telegram:")
- print(" /long BTC 100")
- print(" /short ETH 50")
- sys.exit(0)
- else:
- print("💥 Perps commands test FAILED!")
- sys.exit(1)
|