Download src/crypto_analysis/test_tools.py from vlbandara/cryptic: direct link, hf CLI and curl.
- Browser
- Download file 5.05 kB
-
https://huggingface.co/spaces/vlbandara/cryptic/resolve/main/src/crypto_analysis/test_tools.py
- Command line
-
hf download hf://spaces/vlbandara/cryptic/src/crypto_analysis/test_tools.py
-
curl -L -o test_tools.py https://huggingface.co/spaces/vlbandara/cryptic/resolve/main/src/crypto_analysis/test_tools.py
5.05 kB
| """ | |
| 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) |