cryptic / README.md
vlbandara's picture
Upload folder using huggingface_hub
eb27803 verified

A newer version of the Gradio SDK is available: 6.13.0

Upgrade
metadata
title: cryptic
app_file: src/ui/app.py
sdk: gradio
sdk_version: 5.23.1

CrypticAI - Bitcoin Sentiment Analysis

An AI agentic workflow for Bitcoin price sentiment analysis that combines technical analysis strategies, news sentiment, and market context to provide trading recommendations with confidence scores.

Overview

CrypticAI uses a four-stage agentic workflow to analyze Bitcoin's market conditions:

  1. Technical Strategy Agent - Implements a 5-minute timeframe RSI + Bollinger Bands trading strategy to generate precise buy/sell signals
  2. Initial Analysis Agent - Examines the technical strategy signal alongside broader market indicators, news sentiment, and cryptocurrency market context
  3. Reflection Agent - Critically evaluates both the technical strategy and initial analysis to identify potential blind spots
  4. Final Synthesis Agent - Produces a final recommendation with confidence score and portfolio allocation percentage, and executes trades via Alpaca

Features

  • Technical trading strategy using RSI and Bollinger Bands indicators
  • Broader technical analysis using RSI, ADX, and Bollinger Bands across multiple timeframes
  • News and social media sentiment analysis of Bitcoin and crypto markets
  • Comprehensive cryptocurrency market context analysis including:
    • BTC dominance metrics
    • Market-wide trends across top cryptocurrencies
    • Comparative performance data between Bitcoin and other major coins
  • Multiple data sources including Alpaca and Yahoo Finance APIs
  • Structured trading recommendations with confidence scores and portfolio allocation percentages
  • Automatic trade execution through the Alpaca Crypto API
  • Option to run in monitoring mode for continuous analysis
  • Interactive Gradio UI for strategy tuning and order monitoring
  • Enhanced error handling with exponential backoff retry mechanism
  • Data validation and graceful degradation when data sources are unavailable
  • Comprehensive logging for improved traceability
  • Intelligent caching system to reduce API calls and handle temporary outages

Setup

Prerequisites

  • Python 3.10 or higher
  • API keys for:
    • Alpaca (for Bitcoin price data and trade execution)
    • OpenAI (for the LLM agents)

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/crypticai.git
    cd crypticai
    
  2. Create and activate a virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows, use: venv\Scripts\activate
    
  3. Install dependencies:

    pip install -r requirements.txt
    
  4. Create a .env file with your API keys:

    ALPACA_API_KEY=your_alpaca_api_key
    ALPACA_API_SECRET=your_alpaca_api_secret
    NEWS_API_KEY=your_newsapi_key
    OPENAI_API_KEY=your_openai_api_key
    

Usage

Single Analysis

To run a one-time analysis:

python main.py

Monitoring Mode

To run in monitoring mode (analysis every 4 hours):

python -m src.crypto_analysis.main monitor

Press Ctrl+C to exit monitoring mode.

Trading Dashboard UI

To launch the interactive trading dashboard UI:

python run_ui.py

The UI provides:

  1. Strategy Configuration - Adjust RSI thresholds and Bollinger Bands parameters
  2. Trading - Execute manual trades and view account information
  3. Monitoring - Track active positions and order history
  4. Automated Analysis - Run the strategy in the background (every 5 minutes)

Training Mode

To train the crew (experimental feature for improved performance):

python -m src.crypto_analysis.main train 5  # Run 5 training iterations

Output

The analysis produces a trading recommendation with:

  • Signal: BUY, SELL, or HOLD
  • Confidence: Confidence score as percentage (0-100%)
  • Allocation: Suggested portfolio allocation percentage
  • Reasoning: Concise explanation for the recommendation
  • Tool Error Assessment: Information about any data retrieval issues
  • Data Reliability: Assessment of the reliability of the data used

Results are displayed in the console and saved as JSON files in the results directory. Detailed logs are also saved to the logs directory.

Technical Strategies

5-Minute RSI + Bollinger Bands Strategy

The technical analysis agent implements a structured 5-minute timeframe strategy:

Buy Signal (Long)

  1. RSI falls below 40 (mildly oversold condition)
  2. Price touches or approaches the lower Bollinger Band
  3. Optimal entry when price starts bouncing up from the lower band

Sell Signal (Short)

  1. RSI rises above 60 (mildly overbought condition)
  2. Price touches or approaches the upper Bollinger Band
  3. Optimal entry when price starts reversing down from the upper band

Broader Technical Analysis

The system also evaluates:

  1. Market ranging/trending conditions using ADX
  2. RSI values across multiple timeframes
  3. Price positions relative to Bollinger Bands
  4. Support/resistance levels and trend lines

Market Context Analysis

The YahooCryptoMarketTool enhances analysis by providing:

  1. Market-wide cryptocurrency trends (bullish/bearish)
  2. Bitcoin dominance percentage of total market cap
  3. Comparative performance data for top 10 cryptocurrencies
  4. Day-over-day and week-over-week price changes across the market

Data Tools

The system leverages several specialized data tools:

  1. YahooBitcoinDataTool - Fetches Bitcoin price data from Yahoo Finance
  2. YahooCryptoMarketTool - Provides broader cryptocurrency market context
  3. RealBitcoinNewsTool - Gathers latest Bitcoin news and sentiment
  4. TechnicalAnalysisStrategy - Applies technical indicators to generate signals
  5. AlpacaCryptoOrderTool - Executes trade orders based on final recommendations

Reliability Features

Error Handling and Retry Logic

All API calls include robust error handling with configurable retry mechanisms:

  1. Exponential Backoff - Automatic retry with increasing wait times between attempts
  2. Alternative Data Sources - Fallback to alternative ticker symbols when primary ones fail
  3. Data Validation - Verification of data completeness and format before proceeding
  4. Graceful Degradation - The system continues to function with reduced confidence when some data sources are unavailable

Caching System

An intelligent caching system reduces API calls and improves reliability:

  1. Time-Based Caching - Results are cached for configurable time periods
  2. Cache Validation - Automatic detection of when cached data is stale
  3. Memory-Efficient Storage - Optimized storage of cached data to prevent memory issues

Comprehensive Logging

Enhanced logging provides traceability and debugging capabilities:

  1. Structured Logs - All system activities are logged with timestamps and contextual information
  2. Log Rotation - Daily log files to prevent excessive file sizes
  3. Error Tracebacks - Full error traces captured for debugging
  4. Status Monitoring - Tool state tracking throughout the analysis process

Extending the System

The system is designed to be modular and extensible:

  1. Add new tools in the src/crypto_analysis/tools directory
  2. Modify agent configurations in src/crypto_analysis/config/agents.yaml
  3. Adjust task descriptions in src/crypto_analysis/config/tasks.yaml
  4. Add new technical strategies in src/crypto_analysis/tools/technical_tools.py
  5. Customize error handling in the src/crypto_analysis/utils/api_helpers.py file

License

This project is licensed under the MIT License - see the LICENSE file for details.