A CLI tool for placing MARKET and LIMIT orders on the Binance USD-M Futures Testnet.
Built with python-binance and configured for testnet URL https://testnet.binancefuture.com.
trading_bot/
├── bot/
│ ├── client.py # Binance Futures Testnet client
│ ├── orders.py # Market and limit order functions
│ ├── validators.py # Input validation
│ └── logging_config.py # Logging setup
├── cli.py # CLI entrypoint
├── logs/ # Created automatically
│ └── trading_bot.log
├── .env # Your API credentials (not committed)
├── .env.example # Template for API credentials
├── requirements.txt
└── README.md
-
Clone or download this project.
-
Create and activate a virtual environment (recommended):
python3 -m venv venv
source venv/bin/activate # macOS / Linux
# venv\Scripts\activate # Windows- Install dependencies:
pip install -r requirements.txt-
Create a Binance Futures Testnet account and generate API keys at https://testnet.binancefuture.com.
-
Copy the example environment file and add your credentials:
cp .env.example .env.env example:
API_KEY=your_testnet_api_key_here
API_SECRET=your_testnet_api_secret_here- Never commit
.envto version control.
flowchart TD
A[CLI - argparse] --> B[Input Validation]
B --> C{Order Type}
C -->|MARKET| D[Market Order Handler]
C -->|LIMIT| E[Limit Order Handler]
D --> F[Binance Client]
E --> F
F --> G[Binance Futures Testnet API]
D --> H[Logger]
E --> H
H --> I[logs/trading_bot.log]
Run the bot from the project root:
python cli.py [OPTIONS]| Argument | Required | Description |
|---|---|---|
--symbol |
Yes | Trading pair, e.g. BTCUSDT |
--side |
Yes | BUY or SELL |
--type |
Yes | MARKET or LIMIT |
--quantity |
Yes | Order quantity (must be > 0) |
--price |
LIMIT only | Limit price (must be > 0) |
python cli.py \
--symbol BTCUSDT \
--side BUY \
--type MARKET \
--quantity 0.001python cli.py \
--symbol BTCUSDT \
--side SELL \
--type LIMIT \
--quantity 0.001 \
--price 65000--- Request Summary ---
Symbol : BTCUSDT
Side : BUY
Type : MARKET
Quantity : 0.001
--- Order Response ---
orderId : 123456789
status : NEW
executedQty : 0.001
avgPrice : 64500.50
Success: Order placed successfully.
Logs are written to logs/trading_bot.log automatically. Each entry includes:
- Timestamp
- Request details
- Response details
- Errors
API keys and secrets are redacted from log output.
- Testnet only. The bot is configured for
https://testnet.binancefuture.comand is not intended for live trading. - USD-M Futures. Orders are placed via the USD-M Futures API (
futures_create_order). - Credentials via
.env.API_KEYandAPI_SECRETare loaded from a.envfile at the project root usingpython-dotenv. Keys are never hardcoded. - Limit order time-in-force. LIMIT orders use
GTC(Good Till Cancel). - Quantity and price format. Values are passed as strings to match Binance API expectations; validation ensures they are positive numbers.
- Network access required. The bot needs an internet connection to reach the Binance Testnet API.
- Valid symbol. The symbol must exist and be tradable on the Futures Testnet (e.g.
BTCUSDT).
Implemented Enhanced CLI UX.
- Added colored terminal output using
colorama. - Displayed a clean and professional order summary.
- Improved success and error messages for better readability.
- Enhanced order response formatting.
- Console output is now clean, while detailed API requests, responses, and errors are logged to
logs/trading_bot.log.
The bot handles the following without crashing:
| Error type | Behavior |
|---|---|
| Invalid CLI arguments | argparse help message, exit code 2 |
| Validation errors | Descriptive failure message, exit code 1 |
| Missing credentials | Descriptive failure message, exit code 1 |
| Binance API errors | API code and message printed, exit code 1 |
| Network timeouts | User-friendly message, exit code 1 |
| Connection errors | User-friendly message, exit code 1 |
| Unexpected exceptions | Generic failure message, exit code 1 |


