A simplified Python Command-Line Interface (CLI) application that places orders on the Binance Futures Testnet (USDT-M). This project features a clean, reusable structure, input validation, robust error handling, and structured logging.
- Order Types: Place
MARKET,LIMIT, andSTOP_MARKET(Bonus) orders. - Enhanced CLI: Uses
TyperandRichfor a colorful, structured, and user-friendly CLI experience. - Validation: Strict input validation before any API requests are made.
- Logging: All API responses and errors are logged to
logs/trading_bot.log. - Reusable Structure: Clear separation of concerns between CLI, validation, API interaction, and logic.
- Python 3.9+
- A Binance Futures Testnet account.
- Testnet API Keys (API Key & Secret).
-
Clone or Extract the Repository: Navigate to the project directory.
-
Create a Virtual Environment (Recommended):
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install Dependencies:
pip install -r requirements.txt
-
Configure Environment Variables: Copy the example environment file and add your credentials:
cp .env.example .env
Open the
.envfile and replace the placeholders with your actual testnetBINANCE_API_KEYandBINANCE_API_SECRET.
Use the cli.py script to interact with the bot.
python cli.py --helpBuy 0.001 BTCUSDT at the current market price:
python cli.py --symbol BTCUSDT --side BUY --type MARKET --quantity 0.001Sell 0.001 BTCUSDT at a specific price (e.g., 90000.0):
python cli.py --symbol BTCUSDT --side SELL --type LIMIT --quantity 0.001 --price 90000.0Place a stop-market order to sell 0.001 BTCUSDT if the price drops to 50000.0:
python cli.py --symbol BTCUSDT --side SELL --type STOP_MARKET --quantity 0.001 --stop-price 50000.0- Testnet Only: The bot is hardcoded to connect to the Binance Futures Testnet (
https://testnet.binancefuture.com). It will not place real orders. - USDT-M Futures: The validation assumes trading pairs ending in
USDT(e.g.,BTCUSDT). It does not support Coin-M futures. - Good Till Cancelled (GTC): All LIMIT orders are placed with a
timeInForceofGTC. - Log Directory: The application expects to be able to create a
logsdirectory in the current working directory to storetrading_bot.log.