cryptofunk

module
v0.0.0-...-6deb405 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2026 License: MIT

README

CryptoFunk - AI-Powered Crypto Trading Platform

Multi-Agent Trading System Orchestrated by Model Context Protocol (MCP)

CI Go Version MCP License Status Test Coverage Code Quality

DocumentationQuick StartArchitectureContributing


Overview

CryptoFunk is a state-of-the-art cryptocurrency trading platform that leverages:

  • LLM-Powered Intelligence: Claude/GPT-4 agents via Bifrost gateway for sophisticated reasoning
  • Multi-Agent Architecture: Specialized AI agents for analysis, strategy, and risk management
  • Model Context Protocol (MCP): Official Go SDK for standardized agent orchestration
  • Unified LLM Gateway: Bifrost for automatic failover, semantic caching, and 12+ provider support
  • Real-Time Trading: WebSocket connections via CCXT to 100+ exchanges
  • Advanced Risk Controls: Multi-layered protection with circuit breakers
  • Production Ready: Containerized, cloud-native, and observable with explainable decisions
Key Features
  • LLM-Powered Agents: Claude/GPT-4 for intelligent decision-making with natural language explanations
  • Bifrost Gateway: Unified API for 12+ LLM providers with automatic failover and semantic caching
  • Multiple specialized trading agents working in concert
  • MCP-based tool and resource sharing
  • Consensus-based decision making with weighted voting
  • Real-time market data via CCXT (100+ exchanges)
  • Technical analysis using cinar/indicator (RSI, MACD, Bollinger Bands, 60+ indicators)
  • Risk management with LLM-powered position sizing and approval
  • Paper trading mode for safe testing
  • REST API and WebSocket for monitoring
  • Prometheus metrics and Grafana dashboards
  • Explainable AI: Every decision includes reasoning and confidence scores

Architecture

High-Level Design
┌──────────────────────────────────────────────────────────┐
│                    MCP Orchestrator                      │
│               (Coordination & Consensus)                 │
└────────────────┬─────────────────────────────────────────┘
                 │
      ┌──────────┼──────────┐
      │          │          │
  ┌───▼───┐  ┌──▼───┐  ┌──▼────┐
  │Analysis│  │Strategy│ │ Risk  │
  │ Agents │  │ Agents │ │ Agent │
  │ (LLM)  │  │ (LLM)  │ │ (LLM) │
  └───┬───┘  └──┬───┘  └──┬────┘
      │         │         │
      └─────────┼─────────┘
                │
    ┌───────────▼────────────┐
    │   Bifrost LLM Gateway  │
    │  ┌──────────────────┐  │
    │  │ Claude (Primary) │  │
    │  │ GPT-4 (Fallback) │  │
    │  │ Gemini (Backup)  │  │
    │  └──────────────────┘  │
    │  Semantic Caching 90%  │
    └────────────────────────┘
                │
    ┌───────────▼────────────┐
    │      MCP Servers       │
    │  - Market Data (CCXT)  │
    │  - Tech Indicators     │
    │  - Risk Analyzer       │
    │  - Order Executor      │
    └────────────────────────┘
Agent Types (LLM-Powered)

All agents use LLM reasoning via Bifrost gateway for sophisticated decision-making:

  1. Analysis Agents - LLM analyzes market data with context

    • Technical Analysis Agent: LLM interprets RSI, MACD, patterns with reasoning
    • Order Book Agent: LLM evaluates depth, liquidity, imbalance
    • Sentiment Agent: LLM analyzes news and social media (future)
  2. Strategy Agents - LLM generates trading decisions

    • Trend Following Agent: LLM evaluates trend strength and timing
    • Mean Reversion Agent: LLM identifies reversion opportunities
    • Arbitrage Agent: LLM spots arbitrage opportunities (future)
  3. Risk Agent - LLM provides final approval with reasoning

    • Portfolio risk assessment with natural language explanation
    • Position sizing with confidence scores
    • Circuit breakers with detailed alerts
  4. Execution Agent - Order placement and tracking

    • Integrated with CCXT for multi-exchange support
Technology Stack
Component Technology Version
Language Go 1.25+
LLM Gateway Bifrost Latest (Claude, GPT-4, Gemini)
AI/ML Claude Sonnet 4 (primary), GPT-4 Turbo (fallback) API
MCP SDK modelcontextprotocol/go-sdk v1.0.0
Exchange API CCXT Latest (100+ exchanges)
Technical Indicators cinar/indicator v2.1.22 (60+ indicators)
Database PostgreSQL + TimescaleDB 15+
Vector Search pgvector Latest (PostgreSQL extension)
Cache Redis 7+
Message Queue NATS 2.10+
Containers Docker + Kubernetes Latest
Monitoring Prometheus + Grafana Latest
CI/CD GitHub Actions Native
Code Quality golangci-lint v2.6.1 (30+ linters)

Quick Start

Prerequisites
  • Go 1.25 or higher (required for generics support in cinar/indicator v2)
  • Task (build automation tool)
  • Docker and Docker Compose (for local development)
  • Kubernetes (optional, for production deployment)
  • LLM API Keys: Anthropic (Claude) or OpenAI (GPT-4)
  • Binance account (testnet for development)
  • PostgreSQL 15+ with TimescaleDB and pgvector extensions
Install Task
# macOS
brew install go-task/tap/go-task

# Linux
brew install go-task/tap/go-task
# or
sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d

# Windows
winget install Task.Task

Why Task instead of Make? See docs/TASK_VS_MAKE.md for detailed comparison.

Installation
# Clone the repository
git clone https://github.com/ajitpratap0/cryptofunk.git
cd cryptofunk

# Copy environment template
cp .env.example .env

# Edit .env with your API keys (REQUIRED)
nano .env
# Add:
#   ANTHROPIC_API_KEY=your_claude_key
#   OPENAI_API_KEY=your_gpt4_key (optional, for fallback)
#   BINANCE_API_KEY=your_binance_key
#   BINANCE_SECRET_KEY=your_binance_secret

# Start infrastructure services (includes Bifrost)
docker-compose up -d

# Bifrost will be available at http://localhost:8080
# Verify: curl http://localhost:8080/health

# Run database migrations
task db-migrate

# Build all services
task build

# Start the orchestrator
./bin/orchestrator

# In separate terminals, start LLM-powered agents
./bin/technical-agent
./bin/trend-agent
./bin/risk-agent
Quick Test with Paper Trading
# Start in paper trading mode
task run-paper

# Monitor via API
curl http://localhost:8080/api/v1/status

# Watch real-time updates via WebSocket
websocat ws://localhost:8080/api/v1/ws

Production Deployment

Docker Deployment (Local/Staging)
# Start all services with Docker Compose
docker-compose up -d

# Check service status
docker-compose ps

# View logs
docker-compose logs -f orchestrator

# Stop all services
docker-compose down
Kubernetes Deployment (Production)
# Create namespace
kubectl apply -f deployments/k8s/namespace.yaml

# Create secrets (use your actual values)
kubectl create secret generic cryptofunk-secrets \
  --from-literal=database-url="postgresql://user:pass@host:5432/cryptofunk" \
  --from-literal=anthropic-api-key="your-claude-key" \
  --from-literal=binance-api-key="your-binance-key" \
  --from-literal=binance-secret="your-binance-secret" \
  -n cryptofunk

# Deploy all components
kubectl apply -f deployments/k8s/

# Check deployment status
kubectl get pods -n cryptofunk
kubectl get services -n cryptofunk

# Access Grafana dashboard
kubectl port-forward svc/grafana 3000:3000 -n cryptofunk
# Open http://localhost:3000 (admin/admin)

# View orchestrator logs
kubectl logs -f deployment/orchestrator -n cryptofunk
Monitoring
  • Prometheus: Metrics collection at http://localhost:9090
  • Grafana: Visualization dashboards at http://localhost:3000
  • Health Checks: All services expose /health endpoints
  • Alerts: Configured for critical conditions (high error rate, circuit breakers)

See docs/DEPLOYMENT.md for detailed deployment instructions.


Documentation

Getting Started
Architecture & Design
Development
Operations & Deployment
Security

Project Structure

cryptofunk/
├── cmd/                        # Main applications
│   ├── orchestrator/           # MCP orchestrator
│   ├── mcp-servers/            # MCP tool/resource servers
│   │   ├── market-data/
│   │   ├── technical-indicators/
│   │   ├── risk-analyzer/
│   │   └── order-executor/
│   ├── agents/                 # Trading agents (MCP clients)
│   │   ├── technical-agent/
│   │   ├── orderbook-agent/
│   │   ├── sentiment-agent/
│   │   ├── trend-agent/
│   │   ├── reversion-agent/
│   │   └── risk-agent/
│   └── api/                    # REST/WebSocket API
│
├── internal/                   # Private application code
│   ├── orchestrator/           # Orchestration logic
│   ├── mcpserver/              # MCP server helpers
│   ├── mcpclient/              # MCP client helpers
│   ├── agents/                 # Agent business logic
│   ├── indicators/             # Technical indicators
│   ├── exchange/               # Exchange integrations
│   ├── models/                 # Data models
│   └── config/                 # Configuration
│
├── pkg/                        # Public libraries
│   ├── events/                 # Event definitions
│   └── utils/                  # Utilities
│
├── configs/                    # Configuration files
│   ├── config.yaml
│   ├── agents.yaml
│   └── mcp-servers.yaml
│
├── deployments/                # Deployment configs
│   ├── docker/
│   │   └── Dockerfile.*
│   ├── k8s/
│   └── docker-compose.yml
│
├── scripts/                    # Utility scripts
├── migrations/                 # Database migrations
├── docs/                       # Documentation
└── test/                       # E2E tests

Configuration

Main Configuration

Edit configs/config.yaml:

# LLM Configuration
llm:
  gateway: "bifrost"         # Bifrost LLM gateway
  endpoint: "http://localhost:8080/v1/chat/completions"
  primary_model: "claude-sonnet-4-20250514"
  fallback_model: "gpt-4-turbo"
  temperature: 0.7
  max_tokens: 2000
  enable_caching: true       # Semantic caching (90% cost reduction)

trading:
  mode: "paper"              # paper | live
  symbols:
    - "BTCUSDT"
    - "ETHUSDT"
  exchange: "binance"        # via CCXT

risk:
  max_position_size_percent: 10
  max_portfolio_risk_percent: 2
  max_drawdown_percent: 20
  llm_approval_required: true # Risk agent LLM approval

orchestrator:
  pattern: "concurrent"      # sequential | concurrent | event_driven
  voting:
    min_threshold: 0.7
    min_agents: 2
  llm_consensus: true        # Use LLM for consensus resolution
Environment Variables

Set in .env:

# LLM API Keys (REQUIRED)
ANTHROPIC_API_KEY=your_claude_key
OPENAI_API_KEY=your_gpt4_key     # Optional, for fallback
GOOGLE_API_KEY=your_gemini_key   # Optional, for backup

# Exchange API
BINANCE_API_KEY=your_key
BINANCE_SECRET_KEY=your_secret

# Database
POSTGRES_PASSWORD=your_password
REDIS_PASSWORD=your_password

Development

Building
# Build all services
task build

# Build specific service
task build-orchestrator
task build-agent-technical

# Run tests
task test

# Run with race detector (included in task test)
task test

# Generate coverage report
task test-coverage
Running Locally
# Start infrastructure
docker-compose up -d

# Run orchestrator
task run-orchestrator

# Run agents (in separate terminals)
task run-agent-technical
task run-agent-trend
task run-agent-risk

# View Docker logs
docker-compose logs -f

# Or use task shortcuts
task docker-logs
Testing
# Unit tests
task test-unit

# All tests with coverage
task test

# Integration tests
task test-integration

# Watch and test on changes
task test-watch

# Backtesting
./bin/backtest -symbol BTCUSDT -from 2024-01-01 -to 2024-06-01

Monitoring

Prometheus Metrics

Access at http://localhost:9090

Key metrics:

  • cryptofunk_sessions_active - Active trading sessions
  • cryptofunk_decisions_total - Total decisions by action
  • cryptofunk_agent_latency_seconds - Agent processing time
  • cryptofunk_position_pnl - Current position P&L
Grafana Dashboards

Access at http://localhost:3000 (admin/admin)

Pre-configured dashboards:

  • System Overview
  • Trading Performance
  • Agent Performance
  • Risk Metrics
REST API
# System status
curl http://localhost:8080/api/v1/status

# Current positions
curl http://localhost:8080/api/v1/positions

# Agent health
curl http://localhost:8080/api/v1/agents

# Metrics
curl http://localhost:8080/api/v1/metrics
WebSocket
const ws = new WebSocket('ws://localhost:8080/api/v1/ws');

ws.onmessage = (event) => {
  const data = JSON.parse(event.data);
  console.log('Update:', data);
};

Deployment

Docker Compose (Development)
# Start all services
docker-compose up -d

# View logs
docker-compose logs -f

# Stop all services
docker-compose down
Kubernetes (Production)
# Create namespace
kubectl create namespace cryptofunk

# Apply configurations
kubectl apply -f deployments/k8s/

# Check status
kubectl get pods -n cryptofunk

# View logs
kubectl logs -f deployment/orchestrator -n cryptofunk
CI/CD

GitHub Actions pipeline automatically:

  • Runs tests on PR
  • Builds Docker images on merge
  • Deploys to staging/production

Backtesting

Run historical strategy validation:

# Basic backtest
./bin/backtest \
  -symbol BTCUSDT \
  -from 2024-01-01 \
  -to 2024-06-01 \
  -strategy trend

# With optimization
./bin/backtest \
  -symbol BTCUSDT \
  -from 2024-01-01 \
  -to 2024-06-01 \
  -optimize \
  -params configs/backtest-params.yaml

# Generate report
./bin/backtest -symbol BTCUSDT -report report.html

Results include:

  • Total return
  • Sharpe ratio
  • Maximum drawdown
  • Win rate
  • Equity curve
  • Trade distribution

Security

Best Practices
  • Store API keys in environment variables (never in code)
  • Use testnet for development
  • Start with paper trading
  • Enable circuit breakers
  • Set strict position limits
  • Monitor all trades
  • Regular security audits
API Key Management
# Use environment variables
export BINANCE_API_KEY="your_key"

# Or use secrets management (production)
kubectl create secret generic cryptofunk-secrets \
  --from-literal=binance-api-key=your_key \
  --from-literal=binance-secret-key=your_secret

Performance

Benchmarks
Operation Latency
Market data ingestion <10ms
Technical indicator calculation <5ms
Agent decision <50ms
Full trading cycle <200ms
Order placement <100ms
Scalability
  • Horizontal scaling: Multiple orchestrator instances
  • Agent isolation: Each agent runs independently
  • Database sharding: TimescaleDB chunks
  • Cache layer: Redis for hot data

Roadmap

MVP - LLM-Powered Trading (9.5 weeks)
  • Project structure and MCP foundation
  • Bifrost LLM gateway deployment
  • Core MCP servers (Market Data via CCXT, Technical Indicators via cinar/indicator)
  • LLM-powered agents (technical, trend, risk) using Claude/GPT-4
  • Orchestrator with consensus voting
  • Paper trading mode
  • REST API and monitoring
  • Explainability dashboard (view LLM reasoning for all decisions)
Post-MVP Enhancements
  • Data collection and performance analysis
  • Custom RL model training using collected trading data
  • Hybrid approach: LLM strategy + RL execution optimization
  • Multi-exchange support via CCXT
  • Advanced strategies (arbitrage, market making)
  • Sentiment analysis agent (news, social media)
  • Web dashboard
  • Mobile app
Future (Phase 10+)
  • Multi-model ensemble (Claude + GPT-4 + custom models)
  • Advanced backtesting with walk-forward optimization
  • High-frequency trading capabilities
  • Options and derivatives support

Troubleshooting

Common Issues

Agent won't connect to MCP server

# Check if server is running
ps aux | grep market-data-server

# Check logs
tail -f /var/log/cryptofunk/market-data-server.log

Database connection error

# Verify PostgreSQL is running
docker-compose ps postgres

# Test connection
psql -h localhost -U postgres -d cryptofunk

Orders not executing

# Check if in paper trading mode
grep "mode:" configs/config.yaml

# Verify exchange API keys
./bin/orchestrator --verify-keys
Debug Mode
# Run with debug logging
LOG_LEVEL=debug ./bin/orchestrator

# Enable MCP message tracing
MCP_TRACE=1 ./bin/technical-agent

Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

Development Workflow
  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make changes and add tests
  4. Ensure tests pass (task test)
  5. Commit with conventional commits (git commit -m 'feat: add amazing feature')
  6. Push to branch (git push origin feature/amazing-feature)
  7. Open a Pull Request
Code Style
  • Follow Effective Go
  • Run gofmt before committing
  • Add tests for new features
  • Update documentation

License

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


Acknowledgments


Support


Disclaimer

IMPORTANT: This software is for educational and research purposes only.

  • Cryptocurrency trading involves substantial risk of loss
  • Past performance does not guarantee future results
  • Always start with paper trading
  • Never trade with money you cannot afford to lose
  • Consult a financial advisor before live trading
  • The authors assume no liability for your trading decisions

Built with ❤️ using Go and the Model Context Protocol

⬆ Back to Top

Directories

Path Synopsis
cmd
agents/arbitrage-agent command
Arbitrage Agent Detects and exploits price differences across multiple exchanges
Arbitrage Agent Detects and exploits price differences across multiple exchanges
agents/orderbook-agent command
Order Book Analysis Agent Generates market insights from order book depth and imbalances
Order Book Analysis Agent Generates market insights from order book depth and imbalances
agents/polymarket-agent command
Polymarket Trading Agent Analyzes prediction markets on Polymarket and generates trading signals using LLM-based analysis for information edge detection
Polymarket Trading Agent Analyzes prediction markets on Polymarket and generates trading signals using LLM-based analysis for information edge detection
agents/reversion-agent command
Mean Reversion Agent Generates trading signals when price deviates from mean (Bollinger Bands + RSI extremes)
Mean Reversion Agent Generates trading signals when price deviates from mean (Bollinger Bands + RSI extremes)
agents/risk-agent command
Risk Management Agent Monitors portfolio risk and has veto power over trades
Risk Management Agent Monitors portfolio risk and has veto power over trades
agents/sentiment-agent command
Sentiment Analysis Agent Generates trading signals based on news sentiment and Fear & Greed Index
Sentiment Analysis Agent Generates trading signals based on news sentiment and Fear & Greed Index
agents/technical-agent command
Technical Analysis Agent Generates market insights using technical indicators
Technical Analysis Agent Generates market insights using technical indicators
agents/trend-agent command
Trend Following Agent Generates trading signals using EMA crossover and trend strength (ADX)
Trend Following Agent Generates trading signals using EMA crossover and trend strength (ADX)
api command
backtest command
Backtest Runner CLI Runs trading strategies on historical data to evaluate performance
Backtest Runner CLI Runs trading strategies on historical data to evaluate performance
migrate command
Database migration CLI tool
Database migration CLI tool
orchestrator command
polymarket-analyzer command
polymarket-analyzer runs LLM analysis on a Polymarket market.
polymarket-analyzer runs LLM analysis on a Polymarket market.
polymarket-paper command
polymarket-paper is an interactive CLI for paper trading on Polymarket.
polymarket-paper is an interactive CLI for paper trading on Polymarket.
polymarket-scanner command
polymarket-scanner fetches and filters active Polymarket markets.
polymarket-scanner fetches and filters active Polymarket markets.
telegram-bot command
test-mcp-client command
internal
agents
Package agents provides base infrastructure for AI trading agents
Package agents provides base infrastructure for AI trading agents
agents/testing
Package testing provides utilities for testing trading agents
Package testing provides utilities for testing trading agents
api
Package api provides HTTP API handlers and middleware for the CryptoFunk trading system.
Package api provides HTTP API handlers and middleware for the CryptoFunk trading system.
circuitbreaker
Package circuitbreaker provides a centralized circuit breaker registry that loads configuration from configs/circuit_breakers.yaml.
Package circuitbreaker provides a centralized circuit breaker registry that loads configuration from configs/circuit_breakers.yaml.
config
Package config provides configuration management for CryptoFunk.
Package config provides configuration management for CryptoFunk.
db
Package db provides database utilities including migration runner
Package db provides database utilities including migration runner
deps
Package deps imports all required dependencies to ensure they are included in go.mod This file should be removed once actual code imports these packages
Package deps imports all required dependencies to ensure they are included in go.mod This file should be removed once actual code imports these packages
llm
mcp
Package mcpserver provides a shared MCP server base that supports Streamable HTTP transport.
Package mcpserver provides a shared MCP server base that supports Streamable HTTP transport.
metrics
Package metrics provides HTTP server for exposing Prometheus metrics
Package metrics provides HTTP server for exposing Prometheus metrics
models
Package models provides unified, platform-agnostic types for positions, trades, and portfolio views across Binance and Polymarket.
Package models provides unified, platform-agnostic types for positions, trades, and portfolio views across Binance and Polymarket.
orchestrator
Package orchestrator coordinates multiple trading agents via weighted voting and consensus
Package orchestrator coordinates multiple trading agents via weighted voting and consensus
polymarket/analyzer
Package analyzer provides LLM-based market analysis for Polymarket.
Package analyzer provides LLM-based market analysis for Polymarket.
polymarket/gamma
Package gamma provides a client for the Polymarket Gamma API.
Package gamma provides a client for the Polymarket Gamma API.
polymarket/news
Package news fetches relevant news articles for market analysis.
Package news fetches relevant news articles for market analysis.
polymarket/paper
Package paper provides a paper trading engine for Polymarket.
Package paper provides a paper trading engine for Polymarket.
polymarket/resolver
Package resolver checks Polymarket markets for resolution and updates predictions.
Package resolver checks Polymarket markets for resolution and updates predictions.
strategy
Package strategy provides strategy configuration import/export functionality.
Package strategy provides strategy configuration import/export functionality.
testhelpers
Package testhelpers provides shared test utilities for CryptoFunk test files.
Package testhelpers provides shared test utilities for CryptoFunk test files.
vault
Package vault provides a client for HashiCorp Vault integration.
Package vault provides a client for HashiCorp Vault integration.
pkg
backtest
Agent replay mode for backtesting with trading agents
Agent replay mode for backtesting with trading agents
tests
e2e
Shared helper functions for E2E tests
Shared helper functions for E2E tests

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL