|
|
""" |
|
|
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...") |
|
|
|
|
|
|
|
|
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: |
|
|
|
|
|
tool = AlpacaBitcoinDataTool() |
|
|
print("β Tool initialized successfully") |
|
|
|
|
|
|
|
|
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: |
|
|
|
|
|
tool = TechnicalIndicatorsTool() |
|
|
print("β Tool initialized successfully") |
|
|
|
|
|
|
|
|
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...") |
|
|
|
|
|
|
|
|
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: |
|
|
|
|
|
tool = BitcoinNewsTool() |
|
|
print("β Tool initialized successfully") |
|
|
|
|
|
|
|
|
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") |
|
|
|
|
|
|
|
|
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: |
|
|
|
|
|
tool = YahooBitcoinDataTool() |
|
|
print("β Tool initialized successfully") |
|
|
|
|
|
|
|
|
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')}") |
|
|
|
|
|
|
|
|
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_yahoo_tools() |
|
|
test_alpaca_tools() |
|
|
test_news_tools() |
|
|
test_technical_indicators() |
|
|
|
|
|
print("\n" + "=" * 50) |
|
|
print("TESTING COMPLETE") |
|
|
print("=" * 50) |