Skip to content

Repository files navigation

πŸͺ™ CryptoSense

Your personal crypto investment decision assistant.

License: MIT Python 3.10+ React 18 FastAPI Supabase XGBoost Code style: black PRs Welcome

Tells you when to invest, how much, and why β€” using a robust trend-following strategy combined with an AI confidence layer. Includes portfolio logbook, backtesting, and smart notifications.

Not a trading bot. A thoughtful decision support system.


πŸ“Š System Architecture

graph TB
    subgraph Frontend
        UI[React Dashboard]
        Charts[Recharts Visualizations]
        Notifs[Notification Settings]
    end

    subgraph Backend
        API[FastAPI Server]
        Scheduler[Daily Scheduler]
        Signals[Signal Generator]
        Backtest[Backtest Engine]
    end

    subgraph Database
        Supabase[(Supabase PostgreSQL)]
        Users[Users Table]
        Portfolio[Portfolio Table]
        Signals_Hist[Signals History]
        Backtest_Hist[Backtest Results]
    end

    subgraph AI_Engine
        XGB[XGBoost Model]
        MA[50-Day MA Filter]
        Confidence[Confidence Scoring]
    end

    subgraph External
        CG[CoinGecko API]
        Email[SendGrid]
        Telegram[Telegram Bot]
    end

    UI --> API
    API --> Supabase
    API --> XGB
    API --> MA
    XGB --> Confidence
    MA --> Signals
    Confidence --> Signals
    Scheduler --> Signals
    Signals --> Supabase
    API --> Backtest
    Backtest --> Supabase
    API --> Email
    API --> Telegram
    CG --> API
    Users --> Portfolio
    Portfolio --> Signals
    Signals_Hist --> Charts
    Backtest_Hist --> Charts
Loading

🎯 Signal Logic Flow

flowchart TD
    Start([Daily Signal Check]) --> GetPrice[Get Current Price]
    GetPrice --> GetMA[Get 50-Day MA]
    GetMA --> CheckMA{Price > 50-Day MA?}
    
    CheckMA -->|No| SKIP[SKIP: Below Trend]
    SKIP --> UpdateDB1[Log SKIP Signal]
    UpdateDB1 --> Notify1[Send Notification if Enabled]
    Notify1 --> End1([End])
    
    CheckMA -->|Yes| GetXGB[Get XGBoost Prediction]
    GetXGB --> Confidence{Confidence Score}
    
    Confidence -->|High| INVEST[INVEST: Good Entry]
    Confidence -->|Medium| HOLD[HOLD: Wait for Better Entry]
    Confidence -->|Low| SKIP2[SKIP: Low Confidence]
    
    INVEST --> CalcAmount[Calculate Investment Amount]
    CalcAmount --> RiskCheck{Risk Rules OK?}
    RiskCheck -->|Yes| Execute[Generate Buy Signal]
    RiskCheck -->|No| Adjust[Adjust Position Size]
    Adjust --> Execute
    
    HOLD --> Timing[Check SIP Timing]
    Timing -->|Good Window| INVEST
    Timing -->|Bad Window| HOLD
    
    Execute --> UpdateDB2[Log INVEST Signal]
    SKIP2 --> UpdateDB3[Log SKIP Signal]
    
    UpdateDB2 --> Notify2[Send Notification if Enabled]
    UpdateDB3 --> Notify3[Send Notification if Enabled]
    Notify2 --> End2([End])
    Notify3 --> End3([End])
Loading

πŸ“ˆ Performance Dashboard

pie title Portfolio Allocation
    "Bitcoin (BTC)" : 40
    "Ethereum (ETH)" : 25
    "Solana (SOL)" : 15
    "Polygon (MATIC)" : 10
    "Others" : 10
Loading
xychart-beta
    title "Portfolio Performance Over Time"
    x-axis [Jan, Feb, Mar, Apr, May, Jun]
    y-axis "Portfolio Value ($)" 0 --> 15000
    line [10000, 10500, 10200, 11200, 11800, 12500]
    line [10000, 10200, 9800, 10500, 11000, 11500]
Loading

✨ Features

Core Features

Feature Description Status
Daily Signals INVEST / HOLD / SKIP for your chosen assets βœ… Live
AI Confidence XGBoost model with confidence scoring βœ… Live
Smart SIP Timing Best entry window detection βœ… Live
Portfolio Logbook Track all investments with P&L βœ… Live
Backtesting Engine Historical performance with realistic fees βœ… Live
Google OAuth Secure login with Google βœ… Live
Email Notifications SendGrid integration βœ… Live
Telegram Alerts Real-time Telegram bot notifications βœ… Live
Risk Management Max 4 assets, -8% stop-loss βœ… Live
Open Source Fully self-hostable βœ… Live

Coming Soon

Feature Priority Status
Mobile App Medium 🚧 Planned
Multi-Asset Support High 🚧 In Progress
Advanced Analytics Medium πŸ“‹ Planned
Social Features Low πŸ“‹ Planned
API for Developers Low πŸ“‹ Planned

πŸ› οΈ Tech Stack

mindmap
  root((CryptoSense))
    Frontend
      React 18
      Vite
      TailwindCSS
      Recharts
      React Router
      Axios
    Backend
      FastAPI
      Python 3.10+
      Pydantic
      SQLAlchemy
      Celery
    AI & ML
      XGBoost
      Pandas
      NumPy
      Scikit-learn
    Database
      Supabase
      PostgreSQL
      Redis
    External APIs
      CoinGecko
      SendGrid
      Telegram Bot API
    DevOps
      Docker
      GitHub Actions
      Railway/Render
      Prometheus
Loading

πŸ“¦ Project Structure

graph LR
    subgraph Root
        README[README.md]
        LICENSE[LICENSE]
        CONTRIBUTING[CONTRIBUTING.md]
        plan[plan.md]
    end

    subgraph Backend
        main[main.py]
        api[api/]
        models[models/]
        schemas[schemas/]
        services[services/]
        scripts[scripts/]
        tests[tests/]
        requirements[requirements.txt]
    end

    subgraph Frontend
        src[src/]
        components[components/]
        pages[pages/]
        hooks[hooks/]
        utils[utils/]
        styles[styles/]
        package[package.json]
        vite[vite.config.js]
    end

    Backend --> Root
    Frontend --> Root
Loading

Detailed Backend Structure

backend/
β”œβ”€β”€ main.py                 # FastAPI entry point
β”œβ”€β”€ api/
β”‚   β”œβ”€β”€ auth.py            # Google OAuth
β”‚   β”œβ”€β”€ signals.py         # Daily signal endpoints
β”‚   β”œβ”€β”€ portfolio.py       # Portfolio management
β”‚   β”œβ”€β”€ backtest.py        # Backtest engine
β”‚   └── notifications.py   # Email/Telegram
β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ user.py
β”‚   β”œβ”€β”€ asset.py
β”‚   β”œβ”€β”€ signal.py
β”‚   β”œβ”€β”€ portfolio.py
β”‚   └── backtest.py
β”œβ”€β”€ schemas/
β”‚   β”œβ”€β”€ request.py         # Pydantic request models
β”‚   └── response.py        # Pydantic response models
β”œβ”€β”€ services/
β”‚   β”œβ”€β”€ xgb_model.py       # XGBoost training & prediction
β”‚   β”œβ”€β”€ ma_filter.py       # 50-day moving average
β”‚   β”œβ”€β”€ signal_generator.py # Combined signal logic
β”‚   β”œβ”€β”€ sip_timing.py      # Smart SIP timing
β”‚   β”œβ”€β”€ coingecko.py       # CoinGecko API wrapper
β”‚   β”œβ”€β”€ email.py           # SendGrid integration
β”‚   └── telegram.py        # Telegram bot
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ seed_historical_data.py
β”‚   └── train_model.py
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ test_signals.py
β”‚   β”œβ”€β”€ test_backtest.py
β”‚   └── test_models.py
└── requirements.txt

Detailed Frontend Structure

frontend/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ App.jsx
β”‚   β”œβ”€β”€ main.jsx
β”‚   β”œβ”€β”€ api/
β”‚   β”‚   └── client.js
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”œβ”€β”€ Dashboard/
β”‚   β”‚   β”œβ”€β”€ Signals/
β”‚   β”‚   β”œβ”€β”€ Portfolio/
β”‚   β”‚   β”œβ”€β”€ Backtest/
β”‚   β”‚   β”œβ”€β”€ Settings/
β”‚   β”‚   └── Common/
β”‚   β”œβ”€β”€ pages/
β”‚   β”‚   β”œβ”€β”€ Dashboard.jsx
β”‚   β”‚   β”œβ”€β”€ Signals.jsx
β”‚   β”‚   β”œβ”€β”€ Portfolio.jsx
β”‚   β”‚   β”œβ”€β”€ Backtest.jsx
β”‚   β”‚   β”œβ”€β”€ Settings.jsx
β”‚   β”‚   └── Login.jsx
β”‚   β”œβ”€β”€ hooks/
β”‚   β”‚   β”œβ”€β”€ useAuth.js
β”‚   β”‚   β”œβ”€β”€ useSignals.js
β”‚   β”‚   └── usePortfolio.js
β”‚   β”œβ”€β”€ utils/
β”‚   β”‚   β”œβ”€β”€ formatters.js
β”‚   β”‚   └── validators.js
β”‚   β”œβ”€β”€ styles/
β”‚   β”‚   └── index.css
β”‚   └── config/
β”‚       └── constants.js
β”œβ”€β”€ package.json
β”œβ”€β”€ vite.config.js
└── tailwind.config.js

πŸš€ Quick Start (Local Development)

Prerequisites

  • Python 3.10+
  • Node.js 18+
  • Supabase account (free tier)
  • SendGrid account (optional for emails)
  • Telegram Bot (optional)

Step-by-Step Setup

flowchart LR
    Clone[Clone Repository] --> Backend[Setup Backend]
    Backend --> Frontend[Setup Frontend]
    Frontend --> Supabase[Configure Supabase]
    Supabase --> Seed[Seed Data]
    Seed --> Run[Run Application]
Loading

1. Clone Repository

git clone https://github.com/yourusername/cryptosense.git
cd cryptosense

2. Backend Setup

cd backend
cp .env.example .env
# Fill in your Supabase & API keys

pip install -r requirements.txt
uvicorn main:app --reload

3. Frontend Setup

cd frontend
npm install
npm run dev

4. Database Setup

  1. Create a new Supabase project
  2. Run the SQL schema (from plan.md or backend scripts)
  3. Enable Google OAuth in Auth settings

5. Seed Historical Data

cd backend
python scripts/seed_historical_data.py

Environment Variables

# Supabase
SUPABASE_URL=your_supabase_url
SUPABASE_KEY=your_supabase_key

# Google OAuth
GOOGLE_CLIENT_ID=your_client_id
GOOGLE_CLIENT_SECRET=your_client_secret

# CoinGecko
COINGECKO_API_KEY=your_api_key

# SendGrid (Optional)
SENDGRID_API_KEY=your_sendgrid_key
EMAIL_FROM=your_email

# Telegram (Optional)
TELEGRAM_BOT_TOKEN=your_bot_token

# XGBoost Model Path
MODEL_PATH=./models/xgb_model.pkl

🧠 Core Concepts

Signal Logic

stateDiagram-v2
    [*] --> CheckPrice: Daily Check
    CheckPrice --> CheckMA: Price Retrieved
    
    CheckMA --> SKIP: Below 50-day MA
    CheckMA --> GetConfidence: Above 50-day MA
    
    GetConfidence --> INVEST: High Confidence
    GetConfidence --> HOLD: Medium Confidence
    GetConfidence --> SKIP2: Low Confidence
    
    INVEST --> RiskCheck: Apply Risk Rules
    RiskCheck --> Execute: PASS
    RiskCheck --> Adjust: FAIL
    
    Adjust --> Execute: Adjusted Size
    Execute --> [*]
Loading

Signal Types

Signal Condition Action
INVEST Price > 50-day MA & High Confidence Buy signal with calculated amount
HOLD Price > 50-day MA & Low Confidence Wait for better entry point
SKIP Price < 50-day MA No action, wait for trend reversal

SIP Timing Strategy

flowchart TD
    Start[Start of Month] --> CheckBalance{Check Balance}
    CheckBalance -->|Insufficient| SkipMonth[Skip This Month]
    CheckBalance -->|Sufficient| FindWindow[Find Best Entry Window]
    
    FindWindow --> CheckMA{Dip Below MA?}
    CheckMA -->|Yes| Double[Double Capital Investment]
    CheckMA -->|No| Normal[Normal Investment]
    
    Double --> Record[Record Investment]
    Normal --> Record
    SkipMonth --> RecordSkip[Record Skip]
    
    Record --> NextMonth[Wait for Next Month]
    RecordSkip --> NextMonth
    NextMonth --> Start
Loading

Risk Management Rules

Rule Value Description
Max Assets 4 Maximum concurrent positions
Stop Loss -8% Automatic stop-loss alert
Fees 0.1% Trading fee (configurable)
Slippage 0.5% Slippage for order execution
Position Size Variable Based on confidence & risk

πŸ”„ Development Phases

gantt
    title CryptoSense Development Roadmap
    dateFormat  YYYY-MM-DD
    section Phase 1
    Data Collection           :a1, 2026-06-01, 7d
    MA Filter Implementation  :a2, after a1, 3d
    XGBoost Training          :a3, after a2, 5d
    section Phase 2
    Signal Logic              :b1, after a3, 5d
    SIP Timing                :b2, after b1, 3d
    Risk Management           :b3, after b2, 3d
    section Phase 3
    API Development           :c1, after b3, 7d
    Database Integration      :c2, after c1, 5d
    Testing & Validation      :c3, after c2, 5d
    section Phase 4
    Frontend UI               :d1, after c3, 10d
    Dashboard & Charts        :d2, after d1, 5d
    Notifications             :d3, after d2, 3d
    section Phase 5
    Backtesting               :e1, after d3, 5d
    Deployment                :e2, after e1, 3d
    Beta Release              :milestone, after e2, 0d
Loading

Current Phase Status

Phase Status Progress
Phase 1: Data + Strategy βœ… Complete 100%
Phase 2: Signal Generation βœ… Complete 100%
Phase 3: Backend API 🚧 In Progress 75%
Phase 4: Frontend UI 🚧 In Progress 60%
Phase 5: Notifications πŸ“‹ Planned 0%

πŸ“Š API Endpoints

graph LR
    subgraph Auth
        Login[POST /auth/login]
        Logout[POST /auth/logout]
        Me[GET /auth/me]
    end

    subgraph Signals
        Daily[GET /signals/daily]
        History[GET /signals/history]
        Asset["GET /signals/asset/{id}"]
    end

    subgraph Portfolio
        PortfolioOverview[GET /portfolio]
        Add[POST /portfolio/add]
        Remove["DELETE /portfolio/{id}"]
        PnL[GET /portfolio/pnl]
    end

    subgraph Backtest
        Run[POST /backtest/run]
        Results[GET /backtest/results]
        Compare[GET /backtest/compare]
    end

    subgraph Notifications
        Settings[GET /notifications/settings]
        Update[PUT /notifications/settings]
        Test[POST /notifications/test]
    end
Loading

🚒 Deployment

Docker Deployment

flowchart LR
    Build[Build Docker Image] --> Push[Push to Registry]
    Push --> Deploy[Deploy to Server]
    Deploy --> Config[Configure Env Vars]
    Config --> Run[Run Container]
    Run --> Check{Check Health}
    Check -->|OK| Live[Application Live]
    Check -->|Fail| Rollback[Rollback]
Loading

Quick Deploy

# Build Docker image
docker build -t cryptosense .

# Run container
docker run -d \
  -p 8000:8000 \
  -p 3000:3000 \
  --env-file .env \
  --name cryptosense \
  cryptosense

Production Deployment (Railway)

# railway.json
{
  "build": {
    "builder": "DOCKERFILE",
    "dockerfile": "Dockerfile"
  },
  "deploy": {
    "healthcheck": {
      "path": "/health",
      "interval": 30
    },
    "restart": {
      "policy": "always"
    }
  }
}

Environment Variables for Production

ENVIRONMENT=production
DEBUG=False
LOG_LEVEL=INFO
CORS_ORIGINS=https://cryptosense.app

🀝 Contributing

flowchart TD
    Fork[Fork Repository] --> Clone[Clone Locally]
    Clone --> Branch[Create Feature Branch]
    Branch --> Code[Write Code]
    Code --> Test[Run Tests]
    Test --> Pass{Tests Pass?}
    Pass -->|No| Code
    Pass -->|Yes| Commit[Commit & Push]
    Commit --> PR[Create Pull Request]
    PR --> Review[Code Review]
    Review --> Merge[Merge to Main]
Loading

Contribution Guidelines

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Follow backend/frontend structure
  4. Write tests for new features
  5. Ensure all tests pass
  6. Commit with meaningful messages
  7. Submit pull request

Code Standards

Aspect Standard
Python PEP 8 + Black
JavaScript ESLint + Prettier
Commits Conventional Commits
Testing pytest + Jest
Docs Docstrings + JSDoc

πŸ“Š Monitoring & Analytics

graph LR
    subgraph Metrics
        Accuracy[Prediction Accuracy]
        Confidence[Model Confidence]
        Performance[Portfolio Performance]
        Latency[API Latency]
    end

    subgraph Alerts
        Error[Error Rate]
        API[API Limits]
        DB[Database Connections]
        Model[Model Drift]
    end

    subgraph Dashboard
        Grafana[Grafana Dashboard]
        Logs[ELK Stack]
        Metrics[Prometheus]
    end

    Metrics --> Dashboard
    Alerts --> Dashboard
Loading

Key Metrics to Track

Metric Actual (backtested) Alert Threshold
Accuracy ~50% avg; top stocks ~65-70% <45%
Confidence >0.7 <0.5
Return >10% <0%
API Latency <500ms >2000ms
Error Rate <1% >5%

Note on accuracy: The ~50% average is across all 340 backtested models. Individual high-signal assets (Cotton, TRX, several mid/smallcap stocks) reach 65–70% on held-out test sets. See Data/Model_Results/model_performance_report.txt for per-asset numbers. Treat all predictions as probabilistic signals.


πŸ”’ Security

Security Features

mindmap
  root((Security))
    Authentication
      Google OAuth 2.0
      JWT Tokens
      Session Management
      Rate Limiting
    Data Protection
      HTTPS Everywhere
      Environment Variables
      SQL Injection Prevention
      XSS Protection
    API Security
      CORS Configuration
      API Key Validation
      Request Validation
      Input Sanitization
    Best Practices
      Regular Updates
      Security Headers
      Audit Logging
      Backup Strategy
Loading

Environment Variables Security

# NEVER commit sensitive data
# Use environment variables or .env files

# .env.example (commit this)
DATABASE_URL=postgresql://user:password@localhost/db  # Replace with actual
API_KEY=your_api_key_here  # Replace with actual

# .env (gitignored)
DATABASE_URL=postgresql://actual_user:actual_password@prod_db:5432/db
API_KEY=sk_live_actual_key

πŸ“‹ License & Disclaimer

graph TD
    A[Open Source] --> B[MIT License]
    A --> C[Commercial Use Allowed]
    A --> D[Modification Allowed]
    A --> E[Distribution Allowed]
    A --> F[No Warranty]
    A --> G[Educational Purpose]
Loading

Disclaimer

⚠️ NOT FINANCIAL ADVICE

This project is for educational and personal use only.
Crypto is high risk. Past performance β‰  future results.
Always do your own research. The system provides suggestions only.

You are responsible for your own investment decisions.


πŸ™ Acknowledgments

flowchart LR
    CoinGecko[CoinGecko API] --> Data[Market Data]
    Supabase[Supabase] --> DB[Database]
    XGBoost[XGBoost] --> ML[AI Model]
    FastAPI[FastAPI] --> API[Backend API]
    React[React] --> UI[Frontend UI]
    OSS[Open Source Community] --> Everything
Loading

Libraries & Services

Service/Library Purpose
CoinGecko API Real-time crypto data
Supabase Database & Authentication
XGBoost AI/ML predictions
FastAPI Backend API framework
React Frontend UI
TailwindCSS Styling
Recharts Charts & Visualizations

πŸ“ Changelog

timeline
    title CryptoSense Development Timeline
    June 2026 : Initial Release
             : Backend Complete
             : Frontend Beta
    July 2026 : Notifications Added
             : Backtesting Complete
             : UI Polish
    August 2026 : Mobile Support
               : Advanced Analytics
               : Community Features
Loading

Version History

Version Date Changes
v1.0.0 June 2026 Initial release
v1.1.0 July 2026 Notifications added
v1.2.0 July 2026 Backtesting complete
v1.3.0 August 2026 Mobile support

Built with β˜• for disciplined crypto investors.

Last updated: June 2026

About

Tells you when to invest, how much, and why using a robust trend-following strategy combined with an Al confidence layer. Includes portfolio logbook, backtesting, and smart notifications.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages