# ๐Ÿงช Tests Directory **Test suite for the Hyperliquid Manual Trading Bot** ## ๐Ÿ“‹ Available Tests ### **๐Ÿ”ง Core Tests** - **`test_config.py`** - Validates configuration and environment setup - **`test_balance.py`** - Tests balance fetching with CCXT integration ### **๐Ÿ’ฐ Trading Tests** - **`test_perps_commands.py`** - Tests perps trading logic (/long, /short) - **`test_exit_command.py`** - Tests position closing functionality (/exit) - **`test_order_management.py`** - Tests enhanced order management (/orders, /coo) - **`test_risk_management.py`** - Tests stop loss and take profit commands (/sl, /tp) - **`test_order_monitoring.py`** - Tests automatic order monitoring and notifications ## ๐Ÿš€ Running Tests ### **Run All Tests** ```bash cd tests python run_all_tests.py ``` ### **Run Individual Tests** ```bash cd tests python test_config.py # Test configuration python test_balance.py # Test balance fetching python test_perps_commands.py # Test trading commands python test_exit_command.py # Test exit functionality python test_order_management.py # Test order management python test_risk_management.py # Test risk management ``` ### **Run from Project Root** ```bash python tests/run_all_tests.py # All tests python tests/test_config.py # Individual test ``` ## ๐Ÿ“Š Test Structure Each test file follows the same pattern: ```python #!/usr/bin/env python3 """ Test description """ import sys from pathlib import Path # Add project paths project_root = Path(__file__).parent.parent sys.path.insert(0, str(project_root)) sys.path.insert(0, str(project_root / 'src')) # Import modules to test from hyperliquid_client import HyperliquidClient from config import Config def test_function_name(): """Main test function.""" # Test implementation return True # or False if __name__ == "__main__": success = test_function_name() sys.exit(0 if success else 1) ``` ## โœ… Test Coverage ### **Configuration & Setup** - โœ… Environment variable validation - โœ… CCXT configuration format - โœ… Network settings (testnet/mainnet) - โœ… API key validation ### **Hyperliquid Client** - โœ… Client initialization - โœ… Balance fetching (CCXT format) - โœ… Position fetching - โœ… Order fetching - โœ… Market data retrieval ### **Trading Commands** - โœ… Long/short command logic - โœ… Market vs limit order detection - โœ… Token amount calculations - โœ… Symbol format conversion - โœ… Price validation ### **Order Management** - โœ… Order filtering by token - โœ… Bulk order cancellation logic - โœ… Token extraction and validation ### **Position Management** - โœ… Position detection - โœ… Exit order logic - โœ… Direction determination (long/short) ### **Risk Management** - โœ… Stop loss validation (price direction) - โœ… Take profit validation (price direction) - โœ… Position requirement checking - โœ… P&L calculation at SL/TP levels ### **Order Monitoring** - โœ… Order fill detection logic - โœ… Position change tracking - โœ… P&L calculation accuracy - โœ… Notification triggering - โœ… 30-second monitoring cycle ## ๐Ÿ” What Tests Check ### **Integration Tests** - Real API connectivity (testnet) - Data format validation - Error handling - Network timeouts ### **Logic Tests** - Command parsing - Calculation accuracy - Symbol conversions - Filter operations ### **Safety Tests** - Configuration validation - API key security - Network isolation (testnet) ## ๐Ÿ“ Test Output Each test provides: - **โœ… PASS/โŒ FAIL** status - **Detailed progress** with emojis - **Error messages** with stack traces - **Configuration summary** - **Ready-to-use commands** for testing Example output: ``` ๐Ÿงช Testing Configuration Setup ================================================== โœ… Configuration valid ๐ŸŒ Network: Testnet ๐Ÿ”‘ Private Key: 0x1234567890... ๐ŸŽ‰ Config test PASSED! ``` ## ๐Ÿš€ Adding New Tests 1. **Create test file**: `test_new_feature.py` 2. **Follow naming convention**: `test_.py` 3. **Use standard structure** (see above) 4. **Add to this README** 5. **Test runner** will auto-discover it ## ๐Ÿ›ก๏ธ Test Safety - **All tests use testnet** by default - **No real money** at risk - **Read-only operations** (except explicitly noted) - **API key masking** in outputs - **Network isolation** validation ## ๐Ÿ“ฑ Mobile Testing After tests pass, verify on Telegram: ```bash # Start bot python src/telegram_bot.py # Test commands /start /balance /long BTC 10 /sl BTC 9000 /tp BTC 11000 /orders /coo BTC ``` **Happy testing! ๐Ÿงช๐Ÿš€**