A clean, modular Python-based Command Line Interface (CLI) for placing orders on the Binance Futures Testnet (USDT-M).
- Place MARKET and LIMIT orders.
- Supports both BUY and SELL sides.
- Automatic Time Synchronization: Handles local clock drift with the Binance server.
- Clean CLI output with order summaries.
- Validates inputs (symbol, side, type, price, quantity).
- Logs API requests, responses, and errors to
app.log.
trading_bot/
bot/
__init__.py
client.py # Binance client wrapper (Testnet)
orders.py # Order placement logic
validators.py # Argument and input validation
logging_config.py # Centralized logging configuration
cli.py # Application entry point
requirements.txt # Python dependencies
.env.example # Environment variables template
app.log # Log file (generated at runtime)
- Python 3.7+
- Binance Futures Testnet API Key and Secret (Get them at testnet.binancefuture.com)
- Clone or copy the project files to your machine.
- Navigate to the
trading_botdirectory:cd trading_bot - Create a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
- Install dependencies:
pip install -r requirements.txt
- Create a
.envfile in thetrading_botdirectory:cp .env.example .env
- Open
.envand enter your Binance Futures Testnet API Key and Secret:BINANCE_API_KEY=your_testnet_api_key_here BINANCE_API_SECRET=your_testnet_api_secret_here
Note: For BTCUSDT, Binance requires a minimum "notional" value of 100 USDT. At a price of $60,000, use a quantity of at least 0.002.
python cli.py --symbol BTCUSDT --side BUY --type MARKET --quantity 0.002python cli.py --symbol BTCUSDT --side SELL --type LIMIT --quantity 0.002 --price 65000python cli.py --help- Missing Required Args: The bot will notify you if required arguments are missing.
- Invalid Side/Type: Only
BUY/SELLandMARKET/LIMITare accepted (case-insensitive). - Price Requirement: For
LIMITorders, the--priceargument is mandatory. - Logging: All events, including API errors and connection issues, are logged to
app.log.
The bot now handles this automatically by synchronizing your local system time offset with the Binance server.
This occurs when the total value of your order (Price * Quantity) is below the exchange minimum (usually 100 USDT for BTC). Increase your --quantity to fix this.
MIT