Carles Sentis 0cfca41a25 Refactor data management and update file structure for trading bot - Modified the .gitignore to include new data directories for persistent trading data and logs. Updated reset_data.sh to reflect changes in file paths and improved user prompts. Enhanced trading_stats.py and alarm_manager.py to ensure data is stored in the new structure, improving organization and maintainability. Added demo_stats.json for testing purposes. 3 days ago
..
README.md 5b76ad1144 Enhance documentation and update .gitignore - Add comprehensive command reference and project structure documentation, improve README for clarity, and update .gitignore to include test artifacts and temporary files. 4 days ago
__init__.py 5b76ad1144 Enhance documentation and update .gitignore - Add comprehensive command reference and project structure documentation, improve README for clarity, and update .gitignore to include test artifacts and temporary files. 4 days ago
debug_stats.py 7e3f3b7a7b Enhance trading statistics reporting - Add completed trades metric to TradingStats class and update message formatting to display performance metrics based on completed trades. Improve error handling in stats message and provide informative messages for open positions, enhancing user experience in trading analysis. 4 days ago
demo_stats.json 0cfca41a25 Refactor data management and update file structure for trading bot - Modified the .gitignore to include new data directories for persistent trading data and logs. Updated reset_data.sh to reflect changes in file paths and improved user prompts. Enhanced trading_stats.py and alarm_manager.py to ensure data is stored in the new structure, improving organization and maintainability. Added demo_stats.json for testing purposes. 3 days ago
demo_stats.py f8db740389 Remove Telegram bot implementation - The telegram_bot.py file has been deleted as part of a refactor to streamline the codebase. This change eliminates the previous bot implementation, paving the way for a new architecture. 4 days ago
run_all_tests.py 5b76ad1144 Enhance documentation and update .gitignore - Add comprehensive command reference and project structure documentation, improve README for clarity, and update .gitignore to include test artifacts and temporary files. 4 days ago
test_alarm_system.py 01b6eed4d8 Add price alarm system and logging enhancements - Introduce a comprehensive price alarm manager with functionality for creating, triggering, and managing alarms. Implement logging configuration with rotation and cleanup support, and integrate alarm checks into the Telegram bot for real-time notifications. Add tests for alarm management and ensure persistence across sessions. 4 days ago
test_balance.py 5b76ad1144 Enhance documentation and update .gitignore - Add comprehensive command reference and project structure documentation, improve README for clarity, and update .gitignore to include test artifacts and temporary files. 4 days ago
test_bot_fixes.py f8db740389 Remove Telegram bot implementation - The telegram_bot.py file has been deleted as part of a refactor to streamline the codebase. This change eliminates the previous bot implementation, paving the way for a new architecture. 4 days ago
test_config.py 5b76ad1144 Enhance documentation and update .gitignore - Add comprehensive command reference and project structure documentation, improve README for clarity, and update .gitignore to include test artifacts and temporary files. 4 days ago
test_exit_command.py 5b76ad1144 Enhance documentation and update .gitignore - Add comprehensive command reference and project structure documentation, improve README for clarity, and update .gitignore to include test artifacts and temporary files. 4 days ago
test_heartbeat_config.py f8db740389 Remove Telegram bot implementation - The telegram_bot.py file has been deleted as part of a refactor to streamline the codebase. This change eliminates the previous bot implementation, paving the way for a new architecture. 4 days ago
test_integrated_tracking.py 9eccf900ad Enhance trading infrastructure and position tracking - Update README with key features of the trading system, including multi-platform support and advanced position tracking. Introduce a new reset_data.sh script for clearing trading data, and add SYSTEM_INTEGRATION.md to document the integration of TradingStats for unified position management. Refactor telegram_bot.py to utilize enhanced tracking methods and improve notification messaging for trade actions. Add tests for integrated position tracking to ensure functionality across multi-entry/exit scenarios. 4 days ago
test_logging_system.py f8db740389 Remove Telegram bot implementation - The telegram_bot.py file has been deleted as part of a refactor to streamline the codebase. This change eliminates the previous bot implementation, paving the way for a new architecture. 4 days ago
test_order_management.py 5b76ad1144 Enhance documentation and update .gitignore - Add comprehensive command reference and project structure documentation, improve README for clarity, and update .gitignore to include test artifacts and temporary files. 4 days ago
test_order_monitoring.py 5b76ad1144 Enhance documentation and update .gitignore - Add comprehensive command reference and project structure documentation, improve README for clarity, and update .gitignore to include test artifacts and temporary files. 4 days ago
test_performance_command.py f8db740389 Remove Telegram bot implementation - The telegram_bot.py file has been deleted as part of a refactor to streamline the codebase. This change eliminates the previous bot implementation, paving the way for a new architecture. 4 days ago
test_period_commands.py f8db740389 Remove Telegram bot implementation - The telegram_bot.py file has been deleted as part of a refactor to streamline the codebase. This change eliminates the previous bot implementation, paving the way for a new architecture. 4 days ago
test_period_stats_consistency.py 81afc9a92a Enhance trading statistics reporting in Telegram bot - Update daily, weekly, and monthly statistics to include performance metrics for days, weeks, and months with no trades. Refactor message formatting to ensure consistent display of trading activity, including summaries for periods without trades. Add tests to verify period stats consistency across different trading scenarios. 4 days ago
test_perps_commands.py 5b76ad1144 Enhance documentation and update .gitignore - Add comprehensive command reference and project structure documentation, improve README for clarity, and update .gitignore to include test artifacts and temporary files. 4 days ago
test_positions_display.py f8db740389 Remove Telegram bot implementation - The telegram_bot.py file has been deleted as part of a refactor to streamline the codebase. This change eliminates the previous bot implementation, paving the way for a new architecture. 4 days ago
test_risk_management.py 5b76ad1144 Enhance documentation and update .gitignore - Add comprehensive command reference and project structure documentation, improve README for clarity, and update .gitignore to include test artifacts and temporary files. 4 days ago
test_stats_fix.py 05f44ba672 Enhance trading statistics functionality - Add new performance metrics including total wins, total losses, and expectancy. Improve error handling in stats message formatting to ensure robustness when no trades are recorded. Introduce a test script to verify the correctness of the stats command functionality. 4 days ago
test_stop_loss_config.py f8db740389 Remove Telegram bot implementation - The telegram_bot.py file has been deleted as part of a refactor to streamline the codebase. This change eliminates the previous bot implementation, paving the way for a new architecture. 4 days ago

README.md

🧪 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

cd tests
python run_all_tests.py

Run Individual Tests

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

python tests/run_all_tests.py   # All tests
python tests/test_config.py     # Individual test

📊 Test Structure

Each test file follows the same pattern:

#!/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_<feature_name>.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:

# 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! 🧪🚀