123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- #!/usr/bin/env python3
- """
- Test script to verify that the bot configuration and format string fixes work correctly.
- """
- import sys
- import os
- sys.path.append(os.path.join(os.path.dirname(__file__), 'src'))
- from config import Config
- def test_config_fixes():
- """Test that the configuration changes work correctly."""
- print("🔧 Configuration Fixes Test")
- print("=" * 50)
-
- # Test that the new configuration variables exist
- try:
- token = Config.DEFAULT_TRADING_TOKEN
- risk_enabled = Config.RISK_MANAGEMENT_ENABLED
- stop_loss = Config.STOP_LOSS_PERCENTAGE
- heartbeat = Config.BOT_HEARTBEAT_SECONDS
-
- print(f"✅ DEFAULT_TRADING_TOKEN: {token}")
- print(f"✅ RISK_MANAGEMENT_ENABLED: {risk_enabled}")
- print(f"✅ STOP_LOSS_PERCENTAGE: {stop_loss}%")
- print(f"✅ BOT_HEARTBEAT_SECONDS: {heartbeat}")
-
- # Test that old variables are gone
- try:
- amount = Config.DEFAULT_TRADE_AMOUNT
- print(f"❌ DEFAULT_TRADE_AMOUNT still exists: {amount}")
- except AttributeError:
- print("✅ DEFAULT_TRADE_AMOUNT properly removed")
-
- try:
- symbol = Config.DEFAULT_TRADING_SYMBOL
- print(f"❌ DEFAULT_TRADING_SYMBOL still exists: {symbol}")
- except AttributeError:
- print("✅ DEFAULT_TRADING_SYMBOL properly removed")
-
- except AttributeError as e:
- print(f"❌ Configuration error: {e}")
- return False
-
- return True
- def test_format_strings():
- """Test that format strings work correctly."""
- print("\n📝 Format String Test")
- print("=" * 50)
-
- try:
- # Test the format parameters that would be used in telegram bot
- symbol = Config.DEFAULT_TRADING_TOKEN
- network = "Testnet" if Config.HYPERLIQUID_TESTNET else "Mainnet"
- risk_enabled = Config.RISK_MANAGEMENT_ENABLED
- stop_loss = Config.STOP_LOSS_PERCENTAGE
- heartbeat = Config.BOT_HEARTBEAT_SECONDS
-
- # Test format string similar to what's used in the bot
- test_format = """
- ⚙️ Configuration:
- • Default Token: {symbol}
- • Network: {network}
- • Risk Management: {risk_enabled}
- • Stop Loss: {stop_loss}%
- • Monitoring: Every {heartbeat} seconds
- """.format(
- symbol=symbol,
- network=network,
- risk_enabled=risk_enabled,
- stop_loss=stop_loss,
- heartbeat=heartbeat
- )
-
- print("✅ Format string test successful:")
- print(test_format.strip())
-
- except KeyError as e:
- print(f"❌ Format string error: {e}")
- return False
- except Exception as e:
- print(f"❌ Unexpected error: {e}")
- return False
-
- return True
- def test_timestamp_handling():
- """Test timestamp handling for external trades."""
- print("\n⏰ Timestamp Handling Test")
- print("=" * 50)
-
- from datetime import datetime, timedelta
-
- try:
- # Test different timestamp formats
- test_timestamps = [
- 1733155660, # Unix timestamp (seconds)
- 1733155660000, # Unix timestamp (milliseconds)
- "2024-12-02T15:47:40", # ISO format
- "2024-12-02T15:47:40.123Z", # ISO with Z
- ]
-
- base_time = (datetime.now() - timedelta(hours=1)).isoformat()
-
- for ts in test_timestamps:
- try:
- # Test the conversion logic from the bot
- if isinstance(ts, (int, float)):
- # Assume it's a unix timestamp
- ts_str = datetime.fromtimestamp(ts / 1000 if ts > 1e10 else ts).isoformat()
- else:
- ts_str = str(ts)
-
- # Test comparison
- comparison_result = ts_str > base_time
- print(f"✅ Timestamp {ts} -> {ts_str} (comparison: {comparison_result})")
-
- except Exception as e:
- print(f"❌ Error processing timestamp {ts}: {e}")
- return False
-
- print("✅ All timestamp formats handled correctly")
-
- except Exception as e:
- print(f"❌ Timestamp handling error: {e}")
- return False
-
- return True
- if __name__ == "__main__":
- print("🚀 Bot Fixes Verification Test")
- print("=" * 60)
-
- # Run all tests
- tests = [
- test_config_fixes,
- test_format_strings,
- test_timestamp_handling
- ]
-
- results = []
- for test in tests:
- try:
- result = test()
- results.append(result)
- except Exception as e:
- print(f"❌ Test failed with exception: {e}")
- results.append(False)
-
- print("\n" + "=" * 60)
-
- if all(results):
- print("🎉 All tests passed! Bot fixes are working correctly.")
- print("✅ Configuration cleanup successful")
- print("✅ Format string errors fixed")
- print("✅ Timestamp comparison issues resolved")
- else:
- print("⚠️ Some tests failed. Please check the issues above.")
- failed_count = len([r for r in results if not r])
- print(f"❌ {failed_count}/{len(results)} tests failed")
|