# ๐๏ธ 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! ๐๐ฑ**