project-structure.md 7.5 KB

๐Ÿ—๏ธ 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
โ”œโ”€โ”€ ๐Ÿ“‚ 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
โ”œโ”€โ”€ ๐Ÿ“‚ config/                  # Configuration files
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ .env.example        # Environment template
โ”œโ”€โ”€ ๐Ÿ“‚ logs/                    # Log files
โ”œโ”€โ”€ ๐Ÿ“‚ utils/                   # Utility scripts
โ”œโ”€โ”€ ๐Ÿ“‚ __pycache__/            # Python cache
โ”œโ”€โ”€ ๐Ÿ“‚ venv/                   # Virtual environment
โ”œโ”€โ”€ ๐Ÿ“„ README.md               # Main project README
โ”œโ”€โ”€ ๐Ÿ“„ requirements.txt        # Python dependencies
โ”œโ”€โ”€ ๐Ÿ“„ .gitignore             # Git ignore rules
โ”œโ”€โ”€ ๐Ÿ telegram_bot.py         # Bot entry point (legacy)
โ”œโ”€โ”€ ๐Ÿ trading_bot.py          # Trading bot (legacy)
โ””โ”€โ”€ ๐Ÿ“Š demo_stats.py           # Demo statistics

๐Ÿ“ 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
  • short_command() - Short position
  • exit_command() - Close positions
  • orders_command() - Order management
  • coo_command() - Cancel orders

๐Ÿ”— 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

๐Ÿงช 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

# 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

๐Ÿ“Š Data Files

๐Ÿ“Š demo_stats.py

Demo statistics generator for testing

๐Ÿ“Š demo_stats.json

Sample statistics data

๐Ÿ“‚ logs/

Application log files (created at runtime)

๐Ÿ”„ Legacy Files

๐Ÿ telegram_bot.py (root)

Legacy bot entry point - use src/telegram_bot.py instead

๐Ÿ trading_bot.py (root)

Legacy trading bot - functionality moved to src/

๐Ÿš€ Running the Project

From Source Directory

# Main bot
python src/telegram_bot.py

# Tests
python tests/run_all_tests.py

From Project Root

# 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

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! ๐Ÿš€๐Ÿ“ฑ