
A sophisticated, AI-powered cryptocurrency trading bot that leverages natural language processing and NFT-based access control to provide automated trading strategies across multiple blockchain networks.
- Overview
- Features
- Architecture
- Installation
- Configuration
- Usage
- API Documentation
- Deployment
- Testing
- Contributing
- Security
- License
The NFT-Gated AI Trading Bot is an advanced cryptocurrency trading system that combines artificial intelligence, natural language processing, and blockchain technology to provide automated trading capabilities. The system uses NFT ownership as a gating mechanism, ensuring that only verified NFT holders can access the trading functionality.
- Natural Language Trading: Convert plain English instructions into executable trades using advanced LLM integration
- Multi-Chain Support: Trade across Ethereum, Skale, and Beam networks
- NFT-Based Access Control: Secure access through NFT ownership verification
- Automated Strategies: Pluggable trading strategies including momentum, mean reversion, and custom algorithms
- Real-Time Market Data: Integration with CoinGecko and other market data providers
- Social Media Integration: Automated notifications and updates via Twitter
- Comprehensive Monitoring: Health checks, metrics, and performance tracking
- Multi-Exchange Support: Integrated with Uniswap V2/V3 for decentralized trading
- Strategy Framework: Extensible strategy system supporting custom trading algorithms
- Risk Management: Built-in position sizing, stop-loss, and risk limit controls
- Portfolio Management: Real-time portfolio tracking and rebalancing
- Gas Optimization: Intelligent gas price management and transaction optimization
- Multi-LLM Support: Compatible with Anthropic Claude, OpenAI GPT, Google Gemini, and Venice AI
- Prompt Engineering: Advanced prompt parsing for complex trading instructions
- Confidence Scoring: AI-driven confidence assessment for trade recommendations
- Natural Language Queries: Support for conversational trading commands
- NFT Gating: Ethereum-based NFT ownership verification
- Wallet Integration: Secure wallet connection and transaction signing
- Rate Limiting: API rate limiting and abuse prevention
- Audit Logging: Comprehensive logging of all trading activities
- Microservices Architecture: Scalable, containerized deployment
- Background Processing: Celery-based task queue for async operations
- Caching Layer: Redis-based caching for performance optimization
- Database Management: PostgreSQL with migration support
- Monitoring and Alerting: Prometheus metrics and Grafana dashboards
The system follows a microservices architecture with clear separation of concerns:
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Frontend UI │ │ API Gateway │ │ Load Balancer │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│ │ │
└───────────────────────┼───────────────────────┘
│
┌───────────────────────┼───────────────────────┐
│ │ │
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Auth Service │ │ Trading Service │ │ Strategy Engine │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│ │ │
└───────────────────────┼───────────────────────┘
│
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ NFT Gateway │ │ LLM Processor │ │ Market Data API │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│ │ │
└───────────────────────┼───────────────────────┘
│
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ PostgreSQL │ │ Redis │ │ Message Queue │
└─────────────────┘ └─────────────────┘ └─────────────────┘
- API Layer: FastAPI-based REST API with automatic documentation
- Core Engine: Trading logic, strategy execution, and risk management
- Integration Layer: External service integrations (exchanges, data providers, social media)
- Data Layer: PostgreSQL for persistent storage, Redis for caching and sessions
- Background Processing: Celery workers for async task execution
- Python 3.11+
- Docker and Docker Compose
- PostgreSQL 15+
- Redis 7+
- Node.js 18+ (for frontend development)
-
Clone the repository:
git clone https://github.com/your-org/nft-trading-bot.git cd nft-trading-bot
-
Set up Python environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate pip install -r requirements.txt
-
Configure environment variables:
cp .env.example .env # Edit .env with your configuration
-
Start services with Docker Compose:
docker-compose up -d
-
Run database migrations:
python -m alembic upgrade head
-
Start the development server:
uvicorn api.main:app --reload --host 0.0.0.0 --port 8000
-
Build and run with Docker Compose:
docker-compose up --build
-
Access the application:
- API: http://localhost:8000
- API Documentation: http://localhost:8000/docs
- Flower (Celery monitoring): http://localhost:5555
The application uses environment variables for configuration. Key variables include:
DEBUG
: Enable debug mode (default: false)BYPASS_NFT_GATE
: Bypass NFT verification for testing (default: false)REAL_DATA_MODE
: Use real market data vs. mock data (default: true)SECRET_KEY
: Application secret key for JWT tokens
DATABASE_URL
: PostgreSQL connection stringREDIS_URL
: Redis connection string
ETHEREUM_RPC_URL
: Ethereum RPC endpointSKALE_RPC_URL
: Skale network RPC endpointBEAM_RPC_URL
: Beam network RPC endpointPRIVATE_KEY
: Trading wallet private key
ANTHROPIC_API_KEY
: Anthropic Claude API keyOPENAI_API_KEY
: OpenAI GPT API keyGEMINI_API_KEY
: Google Gemini API keyCOINGECKO_API_KEY
: CoinGecko API key for market data
MAX_GAS_PRICE
: Maximum gas price in gweiDEFAULT_SLIPPAGE
: Default slippage tolerance (%)MIN_TRADE_AMOUNT
: Minimum trade amountMAX_TRADE_AMOUNT
: Maximum trade amount
.env.development
: Development environment settings.env.production.template
: Production environment templateconfig.py
: Application configuration management
The bot supports natural language trading commands through the API:
# Buy ETH with USDC
curl -X POST "http://localhost:8000/trade/prompt" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"prompt": "Buy 1 ETH with USDC", "dry_run": false}'
# Sell half of WBTC position
curl -X POST "http://localhost:8000/trade/prompt" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"prompt": "Sell 50% of my #BTC position", "dry_run": false}'
# List available strategies
curl -X GET "http://localhost:8000/trade/strategies" \
-H "Authorization: Bearer YOUR_TOKEN"
# Get strategy performance
curl -X GET "http://localhost:8000/trade/strategies/momentum_1/performance" \
-H "Authorization: Bearer YOUR_TOKEN"
# Get current portfolio
curl -X GET "http://localhost:8000/trade/portfolio" \
-H "Authorization: Bearer YOUR_TOKEN"
# Get trade history
curl -X GET "http://localhost:8000/trade/history?limit=50" \
-H "Authorization: Bearer YOUR_TOKEN"
The API is fully documented using OpenAPI/Swagger. Access the interactive documentation at:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
- OpenAPI JSON: http://localhost:8000/openapi.json
The API uses JWT-based authentication with NFT ownership verification:
-
Verify NFT ownership:
curl -X POST "http://localhost:8000/auth/verify-nft" \ -H "Content-Type: application/json" \ -d '{"wallet_address": "0x..."}'
-
Use the returned token in subsequent requests:
curl -H "Authorization: Bearer YOUR_JWT_TOKEN" \ "http://localhost:8000/trade/portfolio"
The API implements rate limiting to prevent abuse:
- Development: 100 requests/minute, 1000 requests/hour
- Production: 60 requests/minute, 500 requests/hour
-
Build production image:
docker build -t nft-trading-bot:latest .
-
Deploy with Docker Compose:
docker-compose -f docker-compose.prod.yml up -d
-
Apply Kubernetes manifests:
kubectl apply -f k8s/
-
Configure secrets:
kubectl create secret generic nft-trading-bot-secrets \ --from-env-file=.env.production
-
Deploy to Heroku:
git push heroku main
-
Configure environment variables:
heroku config:set DATABASE_URL=postgresql://... heroku config:set REDIS_URL=redis://...
Use the provided deployment script for automated deployments:
# Development deployment
./scripts/deploy.sh development
# Production deployment with image build
./scripts/deploy.sh production --build --tag v1.0.0 --run-tests
# Run all tests
pytest
# Run unit tests only
pytest tests/unit/
# Run integration tests
pytest tests/integration/
# Run with coverage
pytest --cov=api --cov=core --cov=integrations --cov-report=html
- Unit Tests: Test individual components in isolation
- Integration Tests: Test component interactions
- External Tests: Test external service integrations (requires API keys)
- End-to-End Tests: Test complete user workflows
Tests use pytest with the following markers:
@pytest.mark.unit
: Unit tests@pytest.mark.integration
: Integration tests@pytest.mark.external
: Tests requiring external services@pytest.mark.slow
: Long-running tests
- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature
- Make changes and add tests
- Run the test suite:
pytest
- Submit a pull request
- Python: Follow PEP 8 style guidelines
- Type Hints: Use type hints for all function signatures
- Documentation: Document all public APIs and complex logic
- Testing: Maintain >80% test coverage
Install pre-commit hooks to ensure code quality:
pip install pre-commit
pre-commit install
- Private Key Management: Never commit private keys to version control
- API Key Security: Use environment variables for all API keys
- Rate Limiting: Implement rate limiting to prevent abuse
- Input Validation: Validate all user inputs and API parameters
- Audit Logging: Log all trading activities for audit purposes
- Use strong, unique passwords for all accounts
- Enable two-factor authentication where available
- Regularly rotate API keys and access tokens
- Monitor for unusual trading activity
- Keep dependencies updated to patch security vulnerabilities
Report security vulnerabilities to: [email protected]
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- Documentation: Check this README and API docs
- Issues: Create a GitHub issue
- Discord: Join our Discord community
- Email: [email protected]
Disclaimer: This software is for educational and research purposes. Cryptocurrency trading involves significant risk. Use at your own risk and never trade with funds you cannot afford to lose.