This DCA Trading Bot is a Python-based tool designed to execute Dollar-Cost Averaging (DCA) strategies for trading Bitcoin or other cryptocurrencies. The bot integrates with multiple exchanges via the CCXT library, supports advanced configurations, and provides detailed logging and notification mechanisms for efficient and automated trading.
- Implements a Dollar-Cost Averaging strategy:
- Automatically buys more cryptocurrency when prices drop by a configured percentage.
- Sells holdings when the price rises to a defined threshold, locking in profits.
- Calculates metrics such as average buy price, sell thresholds, and potential profits for every order.
- Supports multiple exchanges using the CCXT library.
- Configurable to connect to exchanges like Binance, Coinbase, etc.
- Utilizes indicators such as:
- Exponential Moving Average (EMA)
- Relative Strength Index (RSI)
- Support level detection
- Ensures informed trading decisions based on historical and real-time data.
- Maintains active orders in a JSON file for transparency and persistence.
- Tracks order profitability and the number of completed sales.
- Dynamically adjusts the next buy and sell thresholds.
- Push notifications via Pushover.
- Email notifications via SendGrid.
- Detailed logs for every bot operation, including errors and trading activity.
- Logs are written to both a file and the console for easy monitoring.
The bot uses a config.json
file to load all necessary settings. Below are the configurable parameters:
API_KEY
: Exchange API key.API_SECRET
: Exchange API secret.
SENDGRID_API_KEY
: API key for email notifications via SendGrid.PUSHOVER_TOKEN
: Token for Pushover notifications.PUSHOVER_USER
: User key for Pushover notifications.
PAIR
: Cryptocurrency pair (e.g.,BTC/USDT
).CRYPTO_SYMBOL
: The symbol of the cryptocurrency (e.g.,BTC
).CRYPTO_CURRENCY
: The base currency (e.g.,USDT
).EXCHANGE_NAME
: Name of the exchange (e.g.,binance
).PERCENTAGE_DROP
: Percentage drop in price to trigger a buy order.PERCENTAGE_RISE
: Percentage rise in price to trigger a sell order.TRADE_AMOUNT
: Amount to trade per order.MAX_ORDERS
: Maximum number of active orders at any time.
- Clone the repository.
- Install the required dependencies:
pip install -r requirements.txt
- Place your
config.json
file in the root directory.
Run the bot with the following command:
python dca_bot.py
- Logs are saved to
dca_bot.log
in the/opt/python/dca-bot-bitcoin/
directory. - Monitor notifications for updates on trades and errors.
initialize_exchange()
: Sets up the exchange connection.load_keys()
: Loads API credentials and configurations fromconfig.json
.load_or_initialize_orders()
: Reads or creates the orders file.
fetch_ohlcv()
: Retrieves historical market data.ema(data, period)
: Calculates the Exponential Moving Average.rsi(data, period)
: Calculates the Relative Strength Index.find_support_levels(data, window)
: Identifies support levels.
- Buying: Buys cryptocurrency when the price drops below a certain threshold.
- Selling: Sells cryptocurrency when the price rises above a defined threshold.
- Metrics Calculation: Calculates sell thresholds, profit, and distance to sell for each order.
send_push_notification(message)
: Sends push notifications.
.
├── dca_bot.py # Main bot script
├── config.json # Configuration file
├── orders.json # Stores active orders and meta data
├── requirements.txt # Python dependencies
└── dca_bot.log # Log file
- Python 3.8+
- Libraries:
- ccxt
- pandas
- pushover
- logging
- json
Install dependencies with:
bash
pip install -r requirements.txt
- Ensure your API keys are secured and not exposed in public repositories.
- Backtest the bot with historical data before running it with real funds.
- Monitor the bot regularly to ensure proper operation.
This project is open-source and available under the MIT License.
Contributions are welcome! This is my first attempt at building a project with Python, and I would greatly appreciate any help, feedback, or suggestions to improve the bot. Whether it's optimizing the code, adding new features, or simply pointing out areas of improvement, your input is invaluable. Feel free to submit issues or pull requests to make this project even better.
This bot is provided for educational purposes only. Use it at your own risk. The creator is not responsible for any financial losses incurred.