Files
uniswap_auto_clp/tools/test_telegram_monitor.py
DiTus b22fdcf741 refactor: Standardize CLP Manager and Hedger modules & cleanup
- **clp_manager.py**: Renamed from 'uniswap_manager.py'. Standardized logic for Uniswap V3 liquidity provision.
- **clp_hedger.py**: Renamed from 'unified_hedger.py'. Consolidated hedging logic including Delta Calculation fixes, EAC (Edge Avoidance), and Fishing order implementation.
- **Cleanup**: Removed legacy 'aerodrome' folder and tools.
- **Monitoring**: Added Telegram monitoring scripts.
- **Config**: Updated gitignore to exclude market data CSVs.
2025-12-31 11:09:33 +01:00

105 lines
2.7 KiB
Python
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""
Test script for Telegram Monitor functionality
Validates JSON parsing and message formatting
"""
import sys
import os
# Add the tools directory to the path
current_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.append(current_dir)
from telegram_monitor import TelegramNotifier, PositionMonitor
def test_json_parsing():
"""Test JSON parsing from hedge_status.json"""
print("Testing JSON parsing...")
monitor = PositionMonitor("../hedge_status.json", "test_state.json")
data = monitor.safe_read_json()
if not data:
print("❌ Failed to read JSON data")
return False
print(f"✅ Successfully read {len(data)} positions")
# Find open and closed positions
last_closed, current_open = monitor.extract_notification_data(data)
if current_open:
print(f"✅ Found open position: Token ID {current_open.get('token_id')}")
else:
print(" No open position found")
if last_closed:
print(f"✅ Found last closed: Token ID {last_closed.get('token_id')}")
else:
print(" No closed positions found")
return True
def test_message_formatting():
"""Test message formatting"""
print("\n🧪 Testing message formatting...")
# Create test data
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
}
notifier = TelegramNotifier("test_token", "test_chat")
message = notifier.format_position_message(last_closed, current_open)
print("📱 Sample message:")
print("-" * 40)
print(message)
print("-" * 40)
return True
def main():
print("Telegram Monitor Test Suite")
print("=" * 50)
success = True
try:
if not test_json_parsing():
success = False
if not test_message_formatting():
success = False
except Exception as e:
print(f"❌ Test failed with error: {e}")
success = False
if success:
print("\n✅ All tests passed! Telegram monitor is ready.")
else:
print("\n❌ Some tests failed. Check the errors above.")
return 0 if success else 1
if __name__ == "__main__":
sys.exit(main())