#!/usr/bin/env python3 """ Simple test for Telegram Monitor functionality """ import sys import os # Add tools directory to path current_dir = os.path.dirname(os.path.abspath(__file__)) sys.path.append(current_dir) try: from telegram_monitor import TelegramNotifier, PositionMonitor print("Testing Telegram Monitor components...") # Test with sample data notifier = TelegramNotifier("test_token", "test_chat") last_closed = { "token_id": 1234567, "entry_price": 3000.0, "target_value": 2000.0, "hedge_pnl_realized": -15.50, "hedge_fees_paid": 2.25, "timestamp_open": 1766328197, "timestamp_close": 1766331797 } current_open = { "token_id": 1234568, "entry_price": 2980.0, "target_value": 1950.0, "range_lower": 2900.0, "range_upper": 3060.0, "amount0_initial": 0.3, "amount1_initial": 900.0, "timestamp_open": 1766335400 } message = notifier.format_position_message(last_closed, current_open) print("Message formatting test PASSED") print("Sample message:") print("-" * 40) print(message) print("-" * 40) # Test JSON reading if file exists if os.path.exists("../hedge_status.json"): monitor = PositionMonitor("../hedge_status.json", "test_state.json") data = monitor.safe_read_json() if data: print(f"JSON reading test PASSED - found {len(data)} positions") else: print("JSON reading test FAILED") print("All tests completed successfully!") except ImportError as e: print(f"Import error: {e}") print("Make sure telegram_monitor.py is in the same directory") except Exception as e: print(f"Test error: {e}")