Complete directory structure and file organization for the Hyperliquid Trading Bot
trader_hyperliquid/
โโโ ๐ src/ # Source code (modular architecture)
โ โโโ ๐ backup/ # Archive
โ โ โโโ ๐ telegram_bot.py # Original 4,627-line monolithic file
โ โโโ ๐ bot/ # Core bot functionality
โ โ โโโ ๐ค core.py # Core bot setup & authentication (264 lines)
โ โโโ ๐ clients/ # Exchange connections
โ โ โโโ ๐ __init__.py # Module init
โ โ โโโ ๐ hyperliquid_client.py # Exchange client (528 lines)
โ โโโ ๐ commands/ # Command handlers
โ โ โโโ ๐ __init__.py # Module init
โ โ โโโ ๐ info_commands.py # Balance, positions, stats (347 lines)
โ โ โโโ โ๏ธ management_commands.py # Monitoring, logs, debug (466 lines)
โ โ โโโ ๐ trading_commands.py # Trading operations (719 lines)
โ โโโ ๐ config/ # Configuration
โ โ โโโ ๐ __init__.py # Module init
โ โ โโโ โ๏ธ config.py # Main configuration (141 lines)
โ โ โโโ ๐ logging_config.py # Logging setup (240 lines)
โ โโโ ๐ monitoring/ # Market monitoring
โ โ โโโ ๐ __init__.py # Module init
โ โ โโโ ๐ alarm_manager.py # Price alarms
โ โ โโโ ๐ market_monitor.py # External trades & monitoring (374 lines)
โ โโโ ๐ notifications/ # Telegram notifications
โ โ โโโ ๐ __init__.py # Module init
โ โ โโโ ๐ฑ notification_manager.py # Rich notifications (343 lines)
โ โโโ ๐ trading/ # Trading logic
โ โ โโโ ๐ trading_engine.py # Order execution (419 lines)
โ โ โโโ ๐ trading_stats.py # Statistics tracking (1,161 lines)
โ โโโ ๐ __init__.py # Root module init
โโโ ๐ 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
The bot has been refactored from a monolithic 4,627-line file into a professional modular architecture with single responsibility principle and clear separation of concerns.
Core bot functionality and authentication (264 lines)
Key Classes:
TelegramTradingBot
- Core bot orchestratorKey Responsibilities:
All trading operations and confirmations (719 lines)
Key Classes:
TradingCommands
- Trading command handlersKey Methods:
long_command()
- Long positions with validationshort_command()
- Short positions with validationexit_command()
- Position closuresl_command()
- Manual stop loss orderstp_command()
- Take profit orderscoo_command()
- Cancel all ordersbutton_callback()
- Confirmation handlingInformation and data display commands (347 lines)
Key Classes:
InfoCommands
- Information command handlersKey Methods:
balance_command()
- Account balance with performancepositions_command()
- Open positions with enhanced P&Lorders_command()
- Active orders grouped by symbolstats_command()
- Comprehensive trading statisticstrades_command()
- Recent trade historymarket_command()
- Market data and orderbookprice_command()
- Quick price checksSystem management and monitoring (466 lines)
Key Classes:
ManagementCommands
- Management command handlersKey Methods:
monitoring_command()
- System status overviewalarm_command()
- Price alert managementlogs_command()
- Log file management and cleanupdebug_command()
- System debugging informationversion_command()
- Version and system infoOrder execution and position tracking (419 lines)
Key Classes:
TradingEngine
- Core trading operationsKey Methods:
execute_long_order()
- Long position executionexecute_short_order()
- Short position executionexecute_exit_order()
- Position closureexecute_stop_loss_order()
- Stop loss placementexecute_take_profit_order()
- Take profit placementfind_position()
- Position detectionget_position_direction()
- CCXT position analysisTrading statistics and performance tracking (1,161 lines)
Key Classes:
TradingStats
- Statistics managerKey Methods:
record_trade_with_enhanced_tracking()
- Enhanced trade loggingget_basic_stats()
- Core performance metricsformat_stats_message()
- Telegram-formatted reportsget_recent_trades()
- Trade historycleanup_old_trades()
- Data maintenanceHyperliquid API client using CCXT (528 lines)
Key Classes:
HyperliquidClient
- Exchange API wrapperKey Methods:
get_balance()
- Account balance with alternative methodsget_positions()
- Open positionsget_open_orders()
- Active ordersplace_market_order()
- Market order executionplace_limit_order()
- Limit order placementget_recent_fills()
- External trade detectionExternal trade monitoring and market events (374 lines)
Key Classes:
MarketMonitor
- Market event monitorKey Methods:
start()
- Initialize monitoring loop_check_order_fills()
- Order execution detection_check_price_alarms()
- Price alert monitoring_check_external_trades()
- External trade detection_process_external_trade()
- External trade integrationRich Telegram notifications (343 lines)
Key Classes:
NotificationManager
- Notification orchestratorKey Methods:
send_long_success_notification()
- Long position confirmationssend_short_success_notification()
- Short position confirmationssend_exit_success_notification()
- Position closure confirmationssend_alarm_triggered_notification()
- Price alert notificationssend_external_trade_notification()
- External trade alertsConfiguration management (141 lines)
Key Classes:
Config
- Configuration managerKey Methods:
validate()
- Settings validationget_hyperliquid_config()
- CCXT configurationCentralized logging configuration (240 lines)
Key Classes:
LoggingManager
- Logging orchestratorKey Functions:
setup_logging()
- Initialize logging systemcleanup_logs()
- Remove old log filesget_log_stats()
- Log file statisticsTest runner for all test modules
Documentation index and navigation
Complete command reference
Quick setup guide
This file - complete project organization
Production deployment guide
Environment variable template
# 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
# Main bot (recommended)
python trading_bot.py
# Direct module execution
python -m src.bot.core
# All tests
python tests/run_all_tests.py
# Individual tests
python tests/test_config.py
python tests/test_balance.py
python tests/test_perps_commands.py
# New modular imports
from src.config.config import Config
from src.bot.core import TelegramTradingBot
from src.trading.trading_engine import TradingEngine
from src.trading.trading_stats import TradingStats
from src.clients.hyperliquid_client import HyperliquidClient
ccxt>=4.2.0
python-telegram-bot>=20.0
python-dotenv>=1.0.0
requests>=2.31.0
hyperliquid>=0.1.0
python -m venv venv
source venv/bin/activate # Linux/Mac
venv\Scripts\activate # Windows
pip install -r requirements.txt
.env
docs/setup.md
tests/run_all_tests.py
src/*/
docs/
docs/deployment.md
Happy coding with the new modular architecture! ๐๐ฑ๐๏ธ