129 lines
4.4 KiB
Python
Executable File
129 lines
4.4 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
Run market analysis and display results
|
|
"""
|
|
import sys
|
|
import json
|
|
import logging
|
|
from pathlib import Path
|
|
|
|
# Add parent directory to path
|
|
sys.path.insert(0, str(Path(__file__).parent.parent))
|
|
|
|
from analysis.engine import MarketAnalysisEngine
|
|
|
|
|
|
# Setup logging
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
|
)
|
|
|
|
|
|
def print_section(title: str, content: dict, indent: int = 0):
|
|
"""Pretty print a section"""
|
|
indent_str = " " * indent
|
|
print(f"\n{indent_str}{'=' * 60}")
|
|
print(f"{indent_str}{title}")
|
|
print(f"{indent_str}{'=' * 60}")
|
|
|
|
for key, value in content.items():
|
|
if isinstance(value, dict):
|
|
print(f"{indent_str}{key}:")
|
|
for k, v in value.items():
|
|
print(f"{indent_str} {k}: {v}")
|
|
elif isinstance(value, list):
|
|
print(f"{indent_str}{key}: {', '.join(map(str, value)) if value else '[]'}")
|
|
else:
|
|
print(f"{indent_str}{key}: {value}")
|
|
|
|
|
|
def main():
|
|
print("🚀 Starting Market Analysis Engine...")
|
|
|
|
engine = MarketAnalysisEngine()
|
|
|
|
# Check data availability
|
|
print("\n📊 Checking data availability...")
|
|
status = engine.check_data_availability()
|
|
print(json.dumps(status, indent=2, ensure_ascii=False))
|
|
|
|
# Perform analysis
|
|
print("\n🔍 Performing market analysis...")
|
|
analysis = engine.analyze_current_market(timeframe='5m')
|
|
|
|
if 'error' in analysis:
|
|
print(f"❌ Error: {analysis['error']}")
|
|
return
|
|
|
|
# Display results
|
|
print_section("📈 MARKET OVERVIEW", {
|
|
'Symbol': analysis['symbol'],
|
|
'Timeframe': analysis['timeframe'],
|
|
'Current Price': f"${analysis['current_price']:,.2f}",
|
|
'Timestamp': analysis['timestamp'],
|
|
})
|
|
|
|
print_section("📊 TREND ANALYSIS", analysis['trend_analysis'])
|
|
|
|
print_section("💰 SUPPORT & RESISTANCE", {
|
|
'Nearest Support': analysis['support_resistance'].get('nearest_support'),
|
|
'Nearest Resistance': analysis['support_resistance'].get('nearest_resistance'),
|
|
'All Support': analysis['support_resistance'].get('support', []),
|
|
'All Resistance': analysis['support_resistance'].get('resistance', []),
|
|
})
|
|
|
|
print_section("⚡ MOMENTUM", analysis['momentum'])
|
|
|
|
print_section("📉 KEY INDICATORS", {
|
|
'RSI': analysis['indicators']['rsi'],
|
|
'MACD': analysis['indicators']['macd'],
|
|
'MACD Histogram': analysis['indicators']['macd_hist'],
|
|
'ADX': analysis['indicators']['adx'],
|
|
'ATR': analysis['indicators']['atr'],
|
|
'BB Width': analysis['indicators']['bb_width'],
|
|
'Volume Ratio': analysis['indicators']['volume_ratio'],
|
|
})
|
|
|
|
# Order flow if available
|
|
if 'orderflow' in analysis:
|
|
print_section("💸 ORDER FLOW", {
|
|
'Imbalance': f"{analysis['orderflow']['imbalance']['imbalance_pct']}%",
|
|
'Status': analysis['orderflow']['imbalance']['status'],
|
|
'Pressure': analysis['orderflow']['imbalance']['pressure'],
|
|
'Strength': analysis['orderflow']['strength']['strength'],
|
|
'Large Bids': analysis['orderflow']['large_orders']['large_bids_count'],
|
|
'Large Asks': analysis['orderflow']['large_orders']['large_asks_count'],
|
|
})
|
|
|
|
print_section("🏦 LIQUIDITY", {
|
|
'Spread': f"{analysis['orderflow']['liquidity']['spread_pct']:.4f}%",
|
|
'Best Bid': f"${analysis['orderflow']['liquidity']['best_bid']:,.2f}",
|
|
'Best Ask': f"${analysis['orderflow']['liquidity']['best_ask']:,.2f}",
|
|
})
|
|
|
|
# Breakout detection
|
|
if analysis['breakout'].get('has_breakout'):
|
|
print_section("🚨 BREAKOUT DETECTED", analysis['breakout'])
|
|
elif 'approaching' in analysis['breakout']:
|
|
print_section("⚠️ APPROACHING KEY LEVEL", analysis['breakout'])
|
|
|
|
# Multi-timeframe
|
|
print("\n\n🕐 MULTI-TIMEFRAME ANALYSIS")
|
|
print("=" * 60)
|
|
mtf = engine.get_multi_timeframe_analysis()
|
|
for tf, data in mtf.items():
|
|
print(f"\n{tf:>4}: {data['trend']:^6} | Strength: {data['strength']:^8} | RSI: {data['rsi']:>5.1f} | ADX: {data['adx']:>5.1f}")
|
|
|
|
# LLM Context
|
|
print("\n\n🤖 LLM CONTEXT (Simplified)")
|
|
print("=" * 60)
|
|
llm_context = engine.get_llm_context(format='simplified')
|
|
print(json.dumps(llm_context, indent=2, ensure_ascii=False))
|
|
|
|
print("\n✅ Analysis complete!")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|