A real-time, asynchronous cryptocurrency trading bot built with ReactPHP. This bot integrates with Binance Futures to automate trading strategies like Bollinger Bands and RSI. The bot supports high-performance, non-blocking operations for optimal trading execution.
- Asynchronous Execution: Built using ReactPHP for real-time, non-blocking operations.
- Customizable Strategies: Implement and modify trading strategies easily, such as Bollinger Bands and RSI.
- Order and Position Management: Ensures no duplicate orders or positions by checking the current state of orders and positions for a trading pair.
- Logger Integration: All activities are logged for transparency and tracking.
- Binance Futures API: Supports automated trading through the Binance Futures API.
- Testing: Unit and feature tests to ensure the correctness and stability of the bot.
- PHP 8.2 or higher
- Composer (dependency manager)
- Binance Futures API Key and Secret
- ReactPHP (installed via Composer)
- Basic knowledge of cryptocurrency trading and APIs
Clone the project repository:
git clone https://github.com/YourUsername/reactphp-trading-bot.git
cd reactphp-trading-botRun the following command to install the required dependencies:
composer installCreate a .env file in the root directory and add your Binance API keys:
BINANCE_API_KEY=your_api_key
BINANCE_API_SECRET=your_api_secretStart the bot with the following command:
php index.phpThe bot will begin executing the configured strategy using the Binance Futures API.
This bot uses the Bollinger Bands strategy by default. It places buy orders when the price is near the lower band and sell orders near the upper band.
To add new strategies, create a new class in the src/Core/Trades/Strategy directory, implement the strategy logic, and integrate it into the bot's execution flow.
The bot checks both open orders and open positions to ensure that no duplicate trades are executed for a specific trading pair:
- Open Orders: Before placing a new order, it verifies if any orders are already open for the pair.
- Open Positions: If an open position exists for the pair, the bot will refrain from placing additional orders until the position is closed.
All activities, such as order placements and errors, are logged in the storage/logs/app.log file. You can change the logging behavior in src/Core/Logger.php.
This bot includes unit and feature tests located in the tests directory. To run the tests, use PHPUnit:
php vendor/bin/phpunitFeel free to fork the repository and submit pull requests. When contributing:
- Ensure your code adheres to the existing coding standards.
- Write tests for new features or bug fixes.
- Provide clear commit messages and pull request descriptions.