# ๐Ÿ—๏ธ Project Structure **Complete directory structure and file organization for the Hyperliquid Trading Bot** ## ๐Ÿ“ Directory Overview ``` trader_hyperliquid/ โ”œโ”€โ”€ ๐Ÿ“‚ src/ # Source code โ”‚ โ”œโ”€โ”€ ๐Ÿ telegram_bot.py # Main Telegram bot โ”‚ โ”œโ”€โ”€ ๐Ÿ”— hyperliquid_client.py # Hyperliquid API client โ”‚ โ”œโ”€โ”€ โš™๏ธ config.py # Configuration management โ”‚ โ”œโ”€โ”€ ๐Ÿ“Š trading_stats.py # Statistics tracking โ”‚ โ”œโ”€โ”€ ๐Ÿ”” alarm_manager.py # Price alarm management โ”‚ โ””โ”€โ”€ ๐Ÿ“ logging_config.py # Logging configuration โ”œโ”€โ”€ ๐Ÿ“‚ tests/ # Test suite โ”‚ โ”œโ”€โ”€ ๐Ÿ“‹ README.md # Test documentation โ”‚ โ”œโ”€โ”€ ๐Ÿƒ run_all_tests.py # Test runner โ”‚ โ”œโ”€โ”€ ๐Ÿงช test_config.py # Configuration tests โ”‚ โ”œโ”€โ”€ ๐Ÿ’ฐ test_balance.py # Balance tests โ”‚ โ”œโ”€โ”€ ๐Ÿ“ˆ test_perps_commands.py # Trading tests โ”‚ โ”œโ”€โ”€ ๐Ÿšช test_exit_command.py # Exit command tests โ”‚ โ””โ”€โ”€ ๐Ÿ“‹ test_order_management.py # Order management tests โ”œโ”€โ”€ ๐Ÿ“‚ docs/ # Documentation โ”‚ โ”œโ”€โ”€ ๐Ÿ“š README.md # Documentation index โ”‚ โ”œโ”€โ”€ ๐Ÿ“ commands.md # Command reference โ”‚ โ”œโ”€โ”€ ๐Ÿš€ setup.md # Setup guide โ”‚ โ”œโ”€โ”€ ๐Ÿ—๏ธ project-structure.md # This file โ”‚ โ”œโ”€โ”€ ๐Ÿš€ deployment.md # Deployment guide โ”‚ โ””โ”€โ”€ ๐Ÿ”ง SYSTEM_INTEGRATION.md # System integration โ”œโ”€โ”€ ๐Ÿ“‚ config/ # Configuration files โ”‚ โ””โ”€โ”€ ๐Ÿ“„ .env.example # Environment template โ”œโ”€โ”€ ๐Ÿ“‚ logs/ # Log files (auto-created) โ”œโ”€โ”€ ๐Ÿ“‚ utils/ # Utility scripts โ”‚ โ”œโ”€โ”€ ๐Ÿ” get_telegram_chat_id.py # Chat ID finder โ”‚ โ”œโ”€โ”€ ๐Ÿ” simple_chat_id.py # Alternative chat ID finder โ”‚ โ””โ”€โ”€ ๐Ÿ“Š demo_stats.py # Demo statistics โ”œโ”€โ”€ ๐Ÿ“‚ __pycache__/ # Python cache (auto-created) โ”œโ”€โ”€ ๐Ÿ“‚ venv/ # Virtual environment โ”œโ”€โ”€ ๐Ÿ“„ README.md # Main project README โ”œโ”€โ”€ ๐Ÿ“„ requirements.txt # Python dependencies โ”œโ”€โ”€ ๐Ÿ“„ .gitignore # Git ignore rules โ”œโ”€โ”€ ๐Ÿ“„ .env # Environment configuration โ”œโ”€โ”€ ๐Ÿ“Š trading_stats.json # Persistent statistics data โ””โ”€โ”€ ๐Ÿš€ trading_bot.py # Main entry point ``` ## ๐Ÿ“ Core Source Files ### **๐Ÿ src/telegram_bot.py** **Main Telegram bot implementation** - Telegram bot interface - Command handlers (/start, /balance, /long, /short, etc.) - Callback query handling - Message formatting - Safety confirmations - Mobile-optimized interface **Key Classes:** - `TelegramTradingBot` - Main bot class **Key Methods:** - `start_command()` - Bot startup - `long_command()` - Long position with stop loss support - `short_command()` - Short position with stop loss support - `exit_command()` - Close positions - `orders_command()` - Order management - `coo_command()` - Cancel orders - `sl_command()` - Manual stop loss - `tp_command()` - Take profit orders - `alarm_command()` - Price alerts - `monitoring_command()` - System status - `performance_command()` - Token performance - `risk_command()` - Risk metrics - `version_command()` - System info - `logs_command()` - Log management - `balance_adjustments_command()` - Deposit/withdrawal history ### **๐Ÿ”— src/hyperliquid_client.py** **Hyperliquid API client using CCXT** - Exchange connectivity - Order management - Balance fetching - Position tracking - Market data - Error handling **Key Classes:** - `HyperliquidClient` - API wrapper **Key Methods:** - `get_balance()` - Fetch account balance - `get_positions()` - Get open positions - `get_open_orders()` - Fetch orders - `place_market_order()` - Market orders - `place_limit_order()` - Limit orders - `cancel_order()` - Cancel orders ### **โš™๏ธ src/config.py** **Configuration management** - Environment variable loading - Validation - Default settings - Security handling **Key Classes:** - `Config` - Configuration manager **Key Methods:** - `validate()` - Validate settings - `get_hyperliquid_config()` - CCXT config ### **๐Ÿ“Š src/trading_stats.py** **Trading statistics and performance tracking** - Trade logging - Performance metrics - Risk analysis - JSON persistence **Key Classes:** - `TradingStats` - Statistics manager **Key Methods:** - `record_trade()` - Log trades - `get_basic_stats()` - Basic metrics - `format_stats_message()` - Telegram formatting ### **๐Ÿ”” src/alarm_manager.py** **Price alarm management system** - Price alert creation and monitoring - Trigger detection - Alarm persistence - Multi-token support **Key Classes:** - `AlarmManager` - Alarm management **Key Methods:** - `create_alarm()` - Create price alert - `check_alarms()` - Monitor prices - `remove_alarm()` - Delete alarm - `get_statistics()` - Alarm stats ### **๐Ÿ“ src/logging_config.py** **Centralized logging configuration** - Log level management - File rotation - Format standardization - Cleanup utilities **Key Functions:** - `setup_logging()` - Initialize logging - `cleanup_logs()` - Remove old logs - `format_log_stats()` - Log statistics ## ๐Ÿงช Test Suite ### **๐Ÿƒ tests/run_all_tests.py** **Test runner for all test modules** - Auto-discovery of test files - Progress tracking - Summary reporting - Pass/fail statistics ### **Individual Test Files** #### **๐Ÿงช test_config.py** - Environment variable validation - Configuration loading - CCXT format verification - Security checks #### **๐Ÿ’ฐ test_balance.py** - Balance fetching - CCXT integration - Error handling - Alternative methods #### **๐Ÿ“ˆ test_perps_commands.py** - Trading logic - Symbol conversion - Amount calculations - Market data fetching #### **๐Ÿšช test_exit_command.py** - Position detection - Exit logic - Market order placement - Token parsing #### **๐Ÿ“‹ test_order_management.py** - Order filtering - Bulk cancellation - Token extraction - API integration ## ๐Ÿ“š Documentation ### **๐Ÿ“š docs/README.md** **Documentation index and navigation** - Quick links to all guides - Time estimates - Feature overview ### **๐Ÿ“ docs/commands.md** **Complete command reference** - All commands with examples - Expected responses - Pro tips and workflows - Mobile optimization notes ### **๐Ÿš€ docs/setup.md** **Quick setup guide** - 5-minute installation - Environment configuration - First run instructions ### **๐Ÿ—๏ธ docs/project-structure.md** **This file - complete project organization** ### **๐Ÿš€ docs/deployment.md** **Production deployment guide** - Server setup - Process management - Monitoring - Security ## โš™๏ธ Configuration ### **๐Ÿ“„ config/.env.example** **Environment variable template** ```bash # Hyperliquid API HYPERLIQUID_PRIVATE_KEY=0x... HYPERLIQUID_TESTNET=true # Telegram Bot TELEGRAM_BOT_TOKEN=... TELEGRAM_CHAT_ID=... TELEGRAM_ENABLED=true # Trading Settings DEFAULT_TRADING_SYMBOL=BTC/USDC:USDC DEFAULT_TRADE_AMOUNT=100 LOG_LEVEL=INFO ``` ## ๐Ÿ”„ Running the Project ### **From Source Directory** ```bash # Main bot python src/telegram_bot.py # Tests python tests/run_all_tests.py ``` ### **From Project Root** ```bash # Main bot python -m src.telegram_bot # Individual tests python tests/test_config.py ``` ## ๐Ÿ“ฆ Dependencies ### **๐Ÿ“„ requirements.txt** ``` ccxt>=4.2.0 python-telegram-bot>=20.0 python-dotenv>=1.0.0 requests>=2.31.0 ``` ### **Virtual Environment** ```bash python -m venv venv source venv/bin/activate # Linux/Mac venv\Scripts\activate # Windows pip install -r requirements.txt ``` ## ๐Ÿ” Security ### **Environment Variables** - All sensitive data in `.env` - Never commit API keys - Use testnet for development ### **API Key Handling** - Masked in logs - Validation before use - Secure storage ## ๐Ÿ“ฑ Mobile Optimization ### **Telegram Interface** - Quick action buttons - Clean formatting - Emoji indicators - One-tap commands ### **Response Design** - Mobile-friendly layout - Concise information - Visual hierarchy - Touch-optimized buttons ## ๐Ÿ”„ Development Workflow 1. **Setup**: Follow `docs/setup.md` 2. **Test**: Run `tests/run_all_tests.py` 3. **Develop**: Edit files in `src/` 4. **Document**: Update `docs/` 5. **Test Again**: Verify all tests pass 6. **Deploy**: Follow `docs/deployment.md` ## ๐ŸŽฏ Key Design Principles ### **Modularity** - Separate concerns - Clear interfaces - Testable components ### **Safety** - Confirmation dialogs - Error handling - Testnet default ### **User Experience** - Mobile-first design - Clear feedback - Professional interface ### **Maintainability** - Comprehensive tests - Clear documentation - Consistent structure **Happy coding! ๐Ÿš€๐Ÿ“ฑ**