Building Trading bot using Binance RestApi
This project implements a simple trading bot for the Binance Futures Testnet (USDT-M). It can place MARKET, LIMIT, and STOP-LIMIT orders via the official REST API.
- Binance Futures Testnet REST API integration
- Place BUY/SELL Market and Limit orders
- Basic Stop-Limit order type supported
- Command-line interface with input validation
- Logging (console + rotating file)
- Error handling with response logging
- Unit tests for validation logic
-
Clone the repository:
git clone https://github.com/yourusername/trading-bot.git cd trading-bot -
Install dependencies:
pip install -r requirements.txt
-
Configure API keys:
-
Register on Binance Futures Testnet
-
Generate API keys
-
Copy
.env.exampleto.envand fill in your keys:BINANCE_API_KEY=your_api_key BINANCE_API_SECRET=your_api_secret
-
python binance_futures_bot.py --symbol BTCUSDT --side BUY --type MARKET --quantity 0.001python binance_futures_bot.py --symbol BTCUSDT --side SELL --type LIMIT --quantity 0.001 --price 30000python binance_futures_bot.py --symbol BTCUSDT --side BUY --type STOP --quantity 0.001 --stop-price 29500 --price 29600-
Logs are written to:
- Console
logs/binance_bot.log
Run basic tests:
pytest tests/- This bot works only on Binance Futures Testnet.
- Never use real funds with this script.