cryptic / main.py
vlbandara's picture
Upload folder using huggingface_hub
eb27803 verified
#!/usr/bin/env python3
"""
Bitcoin Analysis Project - Main Script
This script runs the Bitcoin analysis crew to generate investment recommendations
integrating technical analysis, news sentiment, and market context.
"""
import os
import json
import time
from datetime import datetime
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
# Check for required API keys
if not os.getenv("OPENAI_API_KEY"):
print("Error: OPENAI_API_KEY not found in environment variables")
print("Please set up your .env file with the required API keys")
exit(1)
if not os.getenv("ALPACA_API_KEY") or not os.getenv("ALPACA_API_SECRET"):
print("Error: ALPACA_API_KEY or ALPACA_API_SECRET not found in environment variables")
print("Please set up your .env file with the required Alpaca API keys")
exit(1)
# Import the BitcoinAnalysisCrew
from src.crypto_analysis.crew import BitcoinAnalysisCrew
def main():
"""Run the Bitcoin analysis project"""
print("=" * 80)
print("BITCOIN ANALYSIS PROJECT")
print("=" * 80)
print(f"Run started at: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
print("Initializing Bitcoin Analysis Crew...")
# Create the crew
try:
crew = BitcoinAnalysisCrew()
print("Crew initialized successfully")
print("Starting Bitcoin analysis...")
# Run the analysis
result = crew.run_analysis()
# Print the results
print("\n" + "=" * 40)
print("ANALYSIS RESULTS")
print("=" * 40)
print(f"Signal: {result.get('signal', 'unknown').upper()}")
print(f"Confidence: {result.get('confidence', 0)}%")
print(f"Allocation: {result.get('allocation_percentage', 0)}%")
if 'reasoning' in result:
print("\nReasoning:")
print(result['reasoning'])
# Save the results to a file
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
results_dir = "results"
os.makedirs(results_dir, exist_ok=True)
results_file = os.path.join(results_dir, f"bitcoin_analysis_{timestamp}.json")
with open(results_file, "w") as f:
json.dump(result, f, indent=2)
print(f"\nResults saved to {results_file}")
print("=" * 80)
# Check if order execution happened
if 'order_execution' in result:
print("\nORDER EXECUTION RESULTS:")
print("-" * 40)
order_result = result['order_execution']
if isinstance(order_result, dict):
if order_result.get('success', False):
print(f"Order {order_result.get('order_id', 'unknown')} executed successfully!")
print(f"Side: {order_result.get('side', 'unknown').upper()}")
print(f"Symbol: {order_result.get('symbol', 'unknown')}")
print(f"Quantity: {order_result.get('quantity', 'unknown')}")
print(f"Status: {order_result.get('status', 'unknown')}")
print(f"Current price: ${order_result.get('current_price', 'unknown')}")
else:
print(f"Order execution failed: {order_result.get('error', 'Unknown error')}")
else:
print(f"Account check completed: {order_result}")
return 0
except Exception as e:
print(f"Error in analysis: {str(e)}")
import traceback
traceback.print_exc()
return 1
if __name__ == "__main__":
main()