84 lines
2.3 KiB
Python
84 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|||
|
|
"""
|
||
|
|
🔗 NEWS FILTER INTEGRATION
|
||
|
|
Wrapper für execute_trade_v2_adaptive mit News Filter
|
||
|
|
|
||
|
|
USAGE IN NOTEBOOK:
|
||
|
|
from news_filter_integration import create_news_filter_wrapper
|
||
|
|
|
||
|
|
# Wrap execute_trade
|
||
|
|
if '_original_execute_trade_before_news' not in dir():
|
||
|
|
_original_execute_trade_before_news = execute_trade_v2_adaptive
|
||
|
|
|
||
|
|
execute_trade_v2_adaptive = create_news_filter_wrapper(
|
||
|
|
_original_execute_trade_before_news
|
||
|
|
)
|
||
|
|
"""
|
||
|
|
|
||
|
|
from news_filter_simple import is_news_upcoming
|
||
|
|
|
||
|
|
|
||
|
|
def create_news_filter_wrapper(execute_trade_func):
|
||
|
|
"""
|
||
|
|
Erstellt gefilterte Version von execute_trade_v2_adaptive
|
||
|
|
|
||
|
|
Args:
|
||
|
|
execute_trade_func: Original execute_trade_v2_adaptive Funktion
|
||
|
|
|
||
|
|
Returns:
|
||
|
|
Gefilterte Funktion mit News-Check
|
||
|
|
"""
|
||
|
|
|
||
|
|
def execute_trade_with_news_filter(*args, **kwargs):
|
||
|
|
"""
|
||
|
|
Wrapper der News-Events prüft vor Trade-Execution
|
||
|
|
|
||
|
|
Blockiert Trading 30min vor/nach High-Impact News
|
||
|
|
"""
|
||
|
|
|
||
|
|
# Check for upcoming news
|
||
|
|
if is_news_upcoming(minutes_ahead=30, minutes_after=30):
|
||
|
|
print("⏸️ Trading SKIP: High-Impact News Event detected")
|
||
|
|
print(" Reason: News Filter Protection")
|
||
|
|
print(" Action: Waiting for news event to pass")
|
||
|
|
return
|
||
|
|
|
||
|
|
# No news upcoming - execute trade
|
||
|
|
return execute_trade_func(*args, **kwargs)
|
||
|
|
|
||
|
|
return execute_trade_with_news_filter
|
||
|
|
|
||
|
|
|
||
|
|
# ==========================================
|
||
|
|
# TESTING
|
||
|
|
# ==========================================
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
print("="*70)
|
||
|
|
print("🔗 NEWS FILTER INTEGRATION - TEST")
|
||
|
|
print("="*70)
|
||
|
|
print()
|
||
|
|
|
||
|
|
# Mock execute_trade function
|
||
|
|
def mock_execute_trade(symbol="XAUUSD", **kwargs):
|
||
|
|
print(f"✅ Trade executed on {symbol}")
|
||
|
|
return True
|
||
|
|
|
||
|
|
# Create wrapper
|
||
|
|
filtered_execute_trade = create_news_filter_wrapper(mock_execute_trade)
|
||
|
|
|
||
|
|
# Test 1: No news
|
||
|
|
print("Test 1: No news upcoming")
|
||
|
|
result = filtered_execute_trade("XAUUSD")
|
||
|
|
print()
|
||
|
|
|
||
|
|
# Test 2: With news (would block if events configured)
|
||
|
|
print("Test 2: News filter active")
|
||
|
|
print(" (Add events to news_events_manual.json to test blocking)")
|
||
|
|
result = filtered_execute_trade("XAUUSD")
|
||
|
|
|
||
|
|
print()
|
||
|
|
print("="*70)
|
||
|
|
print("✅ INTEGRATION TEST COMPLETE")
|
||
|
|
print("="*70)
|