A real-time, asynchronous cryptocurrency trading platform built with ReactPHP. It supports event-driven market polling, modular strategy signals, risk-managed order execution, paper trading, a REST API, and a React.js dashboard.
- Asynchronous Execution: Built using ReactPHP for real-time, non-blocking operations.
- Customizable Strategies: Strategy registry with Bollinger RSI, moving-average crossover, MACD, RSI mean reversion, breakout, and volume spike strategies.
- Risk Controls: Configurable risk per trade, max position size, max leverage, take profit, stop loss, trailing stop value, cooldown, and daily loss limit settings.
- Paper Trading Mode: Enabled by default so signals can be reviewed before live order placement.
- React Dashboard: Frontend controls for bot state, selected strategy, symbol, interval, risk settings, and event feed.
- REST API: ReactPHP API server for dashboard and operational integrations.
- 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)
- Node.js 20+ for the React dashboard
- 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_secret
BINANCE_SECRET_KEY=your_api_secret
BINANCE_API_URL=https://fapi.binance.com
PRICE_FETCH_INTERVAL=5
COOL_DOWN_PERIOD=30
PAPER_TRADING=trueStart the bot with the following command:
php index.php --symbol=BTCUSDT --leverage=5 --strategy=bollinger-rsi --paper=trueThe bot will begin executing the configured strategy. Paper trading is enabled by default.
composer apiThe API runs at http://127.0.0.1:8080 by default.
cd frontend
npm install
npm run devThe dashboard runs at http://127.0.0.1:5173.
bollinger-rsima-crossovermacdrsi-mean-reversionbreakoutvolume-spike
To add new strategies, create a class in src/Core/Trades/Strategy, implement StrategyInterface, and register it in config/strategies.php.
GET /api/statusGET /api/strategiesGET /api/configGET /api/eventsPOST /api/bot/startPOST /api/bot/stop
The API stores runtime state in storage/trading-state.json.
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:
composer testLive cryptocurrency trading can lose money quickly. Keep PAPER_TRADING=true until strategy behavior, sizing, and exchange credentials are verified. Use low leverage and testnet credentials before enabling live execution.
Feel 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.