File size: 5,048 Bytes
eb27803
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
"""
Test script to verify that tools can be initialized properly.
This is helpful for checking API keys and connections.
"""

import os
from dotenv import load_dotenv
load_dotenv()

from src.crypto_analysis.tools import (
    AlpacaBitcoinDataTool,
    TechnicalIndicatorsTool,
    BitcoinNewsTool,
    BitcoinSentimentTool,
    YahooBitcoinDataTool,
    YahooCryptoMarketTool
)

def test_alpaca_tools():
    """Test Alpaca tools initialization and basic functionality"""
    print("Testing Alpaca Bitcoin Data Tool...")
    
    # Check if API keys are set
    api_key = os.getenv("ALPACA_API_KEY")
    api_secret = os.getenv("ALPACA_API_SECRET")
    
    if not api_key or not api_secret:
        print("⚠️ Alpaca API keys not found in environment variables")
        return
    
    try:
        # Initialize the tool
        tool = AlpacaBitcoinDataTool()
        print("✓ Tool initialized successfully")
        
        # Test a simple data fetch
        print("Fetching data (this might take a few seconds)...")
        result = tool._run(timeframe="5Min", days_back=1)
        
        if "error" in result:
            print(f"⚠️ Error: {result['error']}")
        else:
            print(f"✓ Successfully retrieved {len(result.get('dataframe', []))} data points")
            print(f"✓ Last Bitcoin price: ${result.get('last_price', 'N/A')}")
    
    except Exception as e:
        print(f"⚠️ Exception occurred: {e}")

def test_technical_indicators():
    """Test technical indicators tool"""
    print("\nTesting Technical Indicators Tool...")
    
    try:
        # Initialize the tool
        tool = TechnicalIndicatorsTool()
        print("✓ Tool initialized successfully")
        
        # Test indicators calculation
        print("Calculating indicators (this might take a few seconds)...")
        result = tool._run(timeframe="5Min", days_back=1)
        
        if "error" in result:
            print(f"⚠️ Error: {result['error']}")
        else:
            print(f"✓ Successfully calculated technical indicators")
            print(f"✓ Current RSI: {result.get('indicators', {}).get('rsi', 'N/A')}")
            print(f"✓ Current ADX: {result.get('indicators', {}).get('adx', 'N/A')}")
            print(f"✓ Buy signal: {result.get('signals', {}).get('buy_signal', 'N/A')}")
            print(f"✓ Sell signal: {result.get('signals', {}).get('sell_signal', 'N/A')}")
    
    except Exception as e:
        print(f"⚠️ Exception occurred: {e}")

def test_news_tools():
    """Test news tools initialization and basic functionality using Tavily"""
    print("\nTesting Bitcoin News Tool with Tavily...")
    
    # Check if API key is set
    api_key = os.getenv("TAVILY_API_KEY")
    
    if not api_key:
        print("⚠️ Tavily API key not found in environment variables")
        print("Will try to fetch news using web search as fallback")
    
    try:
        # Initialize the tool
        tool = BitcoinNewsTool()
        print("✓ Tool initialized successfully")
        
        # Test news fetch
        print("Fetching news (this might take a few seconds)...")
        result = tool._run(days_back=1, limit=3)
        
        if "error" in result:
            print(f"⚠️ Error: {result['error']}")
        else:
            articles = result.get("articles", [])
            print(f"✓ Successfully retrieved {len(articles)} news articles")
            
            # Print article titles
            for i, article in enumerate(articles, 1):
                print(f"  {i}. {article.get('title', 'No title')}")
    
    except Exception as e:
        print(f"⚠️ Exception occurred: {e}")

def test_yahoo_tools():
    """Test Yahoo Finance tools"""
    print("\nTesting Yahoo Finance Bitcoin Data Tool...")
    
    try:
        # Initialize the tool
        tool = YahooBitcoinDataTool()
        print("✓ Tool initialized successfully")
        
        # Test data fetch
        print("Fetching data (this might take a few seconds)...")
        result = tool._run(period="1d", interval="1h")
        
        if "error" in result:
            print(f"⚠️ Error: {result['error']}")
        else:
            print(f"✓ Successfully retrieved Bitcoin data from Yahoo Finance")
            print(f"✓ Last price: ${result.get('last_price', 'N/A')}")
            
            # Print metadata
            metadata = result.get("metadata", {})
            print(f"✓ Market cap: {metadata.get('market_cap', 'N/A')}")
            print(f"✓ 24h volume: {metadata.get('volume_24h', 'N/A')}")
    
    except Exception as e:
        print(f"⚠️ Exception occurred: {e}")

if __name__ == "__main__":
    print("=" * 50)
    print("TESTING BITCOIN ANALYSIS TOOLS")
    print("=" * 50)
    
    # Test each tool category
    test_yahoo_tools()  # Start with Yahoo as it doesn't require API keys
    test_alpaca_tools()
    test_news_tools()
    test_technical_indicators()
    
    print("\n" + "=" * 50)
    print("TESTING COMPLETE")
    print("=" * 50)