Advanced Cryptocurrency Trading Bot with Time-Based Straddling Strategy
The Time-Based Straddling Strategy is a sophisticated cryptocurrency trading system that employs advanced algorithmic trading techniques to capture market volatility through strategic position placement. The system utilizes multiple timeframes and dynamic volatility analysis to optimize entry and exit points.
- π Automated Straddle Trading: Executes both long and short positions simultaneously
- β° Multi-Timeframe Analysis: Short (5m), Medium (1h), and Long (4h) timeframe strategies
- π Dynamic Volatility Calculation: Adaptive entry levels based on real-time market conditions
- ποΈ Smart Position Management: Intelligent TP/SL calculation with 1:3 buy/sell ratios
- π± Telegram Integration: Real-time notifications and trading updates
- π Auto-Swap Functionality: Automatic conversion between crypto and stablecoins
- π Portfolio Management: Comprehensive portfolio tracking and analysis
- π₯οΈ Modern Web Interface: Real-time dashboard with live market data
- π Paper Trading Mode: Safe testing environment before live trading
Time-Based Straddling Strategy/
βββ backend/ # FastAPI Backend
β βββ app/ # Main application
β β βββ api/v1/ # API routes
β β βββ models/ # Database models
β β βββ services/ # Business logic
β β βββ crud/ # Database operations
β β βββ core/ # Configuration & database
β βββ alembic/ # Database migrations
β βββ scripts/ # Utility scripts
βββ frontent/ [sic] # React/TypeScript Frontend
β βββ src/
β β βββ components/ # React components
β β βββ services/ # API services
β β βββ hooks/ # Custom React hooks
β β βββ types/ # TypeScript definitions
β βββ ...
βββ crypto_scheduler/ # Background job scheduler
- Python 3.8+
- Node.js 16+
- PostgreSQL 12+
- Git
git clone <repository-url>
cd "Time-Based Straddling Strategy"# Navigate to backend
cd backend
# Create virtual environment
python -m venv venv
# Activate virtual environment
# Windows:
venv\Scripts\activate
# Linux/Mac:
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Set up environment variables
cp .env.example .env
# Edit .env with your configuration# Create PostgreSQL database
createdb crypto_trading
# Run migrations
alembic upgrade head
# Optional: Sync crypto data
python scripts/sync_crypto.py# Navigate to frontend
cd frontent
# Install dependencies
npm install
# Set up environment variables
cp .env.example .env
# Edit .env with your configurationBackend:
cd backend
python run.pyFrontend:
cd frontent
npm run devScheduler (Optional):
cd backend/crypto_scheduler
python start.py# Database
POSTGRES_USER=postgres
POSTGRES_PASSWORD=your_password
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_DB=crypto_trading
# Trading Settings
PAPER_TRADING=true
STRATEGY=SHORT # SHORT, MEDIUM, LONG
DEFAULT_TRADING_PAIR=BTC/USDT
# Exchange API Keys
BINANCE_API_KEY=your_binance_api_key
BINANCE_SECRET_KEY=your_binance_secret_key
# Telegram (Optional)
TELEGRAM_BOT_TOKEN=your_bot_token
TELEGRAM_CHAT_ID=your_chat_id
# 1inch API (For Swaps)
ONEINCH_API_KEY=your_oneinch_api_key
WALLET_ADDRESS=your_wallet_address
PRIVATE_KEY=your_private_keyVITE_API_URL=http://localhost:8000/api/v1
VITE_DEV_MODE=true
VITE_AUTO_REFRESH_INTERVAL=30000
VITE_ENABLE_MOCK_FALLBACK=trueThe Time-Based Straddling Strategy implements a sophisticated approach to cryptocurrency trading:
- Volatility Analysis: Calculates volatility across multiple timeframes
- Dynamic Entry Levels: Adjusts entry points based on market conditions
- Risk Management: Implements 1:3 buy/sell ratios with intelligent stop-loss
- Auto-Rebalancing: Automatically closes and reopens positions based on profit targets
| Parameter | Short Strategy | Medium Strategy | Long Strategy |
|---|---|---|---|
| Timeframe | 5 minutes | 1 hour | 4 hours |
| Take Profit | 0.8% | 3.0% | 6.0% |
| Stop Loss | 0.5% | 2.0% | 4.0% |
| Buy:Sell Ratio | 1:3 | 1:3 | 1:3 |
GET /api/v1/live/health- System health checkGET /api/v1/live/tokens- Real-time token pricesGET /api/v1/live/signals- Trading signalsGET /api/v1/live/market-overview- Market summary
POST /api/v1/straddle/create- Create straddle positionGET /api/v1/straddle/status/{symbol}- Get position statusPOST /api/v1/straddle/close/{symbol}- Close position
GET /api/v1/portfolio/summary- Portfolio overviewGET /api/v1/portfolio/history- Trading historyGET /api/v1/portfolio/performance- Performance metrics
The system can automatically swap between cryptocurrencies and stablecoins based on:
- Market trend analysis
- Profit thresholds
- Risk management rules
- Intraday pattern recognition
- Binance: Primary exchange for trading
- 1inch: DEX aggregator for optimal swap rates
- Extensible: Easy to add new exchange integrations
Get real-time notifications for:
- Trade executions
- Profit/Loss updates
- System alerts
- Market opportunities
- Real-time P&L tracking
- Win/loss ratios
- Drawdown analysis
- Performance attribution
- Risk metrics
- Comprehensive logging system
- Health check endpoints
- Performance metrics collection
- Error tracking and alerting
cd backend
pytest app/tests/ -v# Test environment setup
node frontent/test-env.js
# Test API service
node frontent/test-api-service.js- API Key Management: Secure storage of exchange credentials
- Paper Trading Mode: Safe testing environment
- Input Validation: Comprehensive parameter validation
- Rate Limiting: Protection against API abuse
- Secure Communications: HTTPS and encrypted connections
- Private keys are encrypted and never logged
- Multi-signature support ready
- Hardware wallet integration possible
- π API Setup Guide
- π Frontend Setup Guide
- π§ Troubleshooting Guide
- πΊ Video Tutorial
Once the backend is running, access the interactive API documentation at:
- Swagger UI:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
This software is for educational and research purposes only. Cryptocurrency trading involves substantial risk of loss and is not suitable for every investor. Past performance does not guarantee future results. Always conduct your own research and consider consulting with a financial advisor before making investment decisions.
- πΊ Video Tutorial: YouTube
- π§ Issues: Create an issue on GitHub
- π¬ Discussions: Use GitHub Discussions for questions
β If you find this project helpful, please consider giving it a star!