Bitget Scalp Trading Bot - Developer
Documentation
Overview
This project is a scalp trading bot designed to operate on the Bitget Spot market using their REST API.
The bot utilizes technical indicators and candlestick pattern detection to make intelligent buy/sell decisions
and manage risk.
Key Features:
• Technical indicators: RSI, MACD, Bollinger Bands, EMA, ATR
• Candlestick pattern detection: Bullish/Bearish Engulfing, Hammer, Doji
• Adaptive position sizing and dynamic exit strategy
• Performance monitoring and logging
• Daily trade limits, risk controls, and emergency stop capability
Project Structure
bitget_scalp_bot.py # Main bot script
.env # API credentials (not included for security)
trading_bot.log # Runtime logs (generated)
trades_YYYYMMDD_HHMMSS.csv # Per-trade logging (generated)
Environment Setup
1. Install Dependencies
pip install pandas requests python-dotenv
2. Create .env File
BITGET_API_KEY=your_api_key
BITGET_API_SECRET=your_api_secret
BITGET_PASSPHRASE=your_passphrase
1
Main Components
1. TechnicalIndicators
A @dataclass to hold values for:
• RSI, MACD, MACD Signal
• Bollinger Bands (upper, middle, lower)
• EMA (fast and slow)
• Volume SMA
• ATR
2. TradeSignal
Encapsulates a trade signal and the logic behind it. Includes:
• signal_type ('BUY', 'SELL', 'HOLD')
• confidence score
• patterns_detected
• reason
3. TechnicalAnalysis
Static methods to compute technical indicators:
• calculate_rsi , calculate_macd , calculate_bollinger_bands
• calculate_ema , calculate_atr
4. PerformanceMonitor
Tracks bot statistics:
• PnL, win/loss streaks, daily trades, drawdown
• Provides summary stats and updates
5. BitgetTradingBot
Main class that:
• Initializes API
• Executes trade cycles
• Analyzes patterns and indicators
• Manages risk and orders
• Monitors positions and exits
2
Key Methods and Logic
Entry Conditions
• Pattern Match: Engulfing, Hammer, Doji
• Indicator Check: RSI < 30, MACD crossover, price at lower Bollinger Band
• Confidence Score: Combination of pattern + indicator weight
Exit Strategy
• Profit target or stop-loss
• Technical conditions: RSI > 80, BB upper breach, bearish patterns
• Time-based fallback to market sell
Order Management
• Limit/market orders with retries
• Cancel unfilled orders after timeout
• Log orders in CSV and runtime log
How to Extend
Add More Indicators:
Add static methods in TechnicalAnalysis and update calculate_technical_indicators() .
Add More Patterns:
Define methods like detect_morning_star() and update detect_patterns() .
Backtesting Module:
Integrate historical candles and simulate trade cycle using generate_trade_signal() logic.
UI Dashboard:
Use Flask or Streamlit to visualize trade logs and live statistics.
Developer Notes
• Ensure API rate limits are respected.
• Error handling and retry logic is crucial for stability.
• Logging helps in debugging failed trades or misbehavior.
3
Future Improvements
• WebSocket integration for real-time execution
• GUI interface or Telegram bot
• Machine Learning-based signal enhancement
Credits
Author: AI Assistant License: MIT
Entry Point
if __name__ == "__main__":
main() # Launches CLI and starts bot
Run it with:
python bitget_scalp_bot.py