A clean, production-structured Python CLI application for placing orders on the Binance USDT-M Futures Testnet.
| Feature | Status |
|---|---|
| Market & Limit orders | β |
| BUY and SELL sides | β |
| Stop-Market orders (bonus) | β |
| Input validation with clear error messages | β |
| Structured logging to file + console | β |
| Full exception handling (API / network / input) | β |
| Layered architecture (client / orders / validators / CLI) | β |
| Account balance and open order listing | β |
trading_bot/
βββ bot/
β βββ __init__.py
β βββ client.py # Binance REST API wrapper (auth, signing, requests)
β βββ orders.py # Order placement orchestration + output formatting
β βββ validators.py # Input validation for all order parameters
β βββ logging_config.py # Rotating file + console logging setup
βββ cli.py # CLI entry point (argparse sub-commands)
βββ logs/
β βββ trading_bot.log # Auto-created; sample log included
βββ requirements.txt
βββ README.md
git clone https://github.com/<your-username>/trading-bot.git
cd trading-botpip install -r requirements.txt- Go to https://testnet.binancefuture.com
- Log in with your GitHub account
- Navigate to API Key β generate a key pair
- Copy the API Key and Secret Key
Add β .env file in the project root:
BINANCE_API_KEY=your_api_key_here
BINANCE_API_SECRET=your_api_secret_here
python cli.py ping# BUY 0.001 BTC at market price
python cli.py place --symbol BTCUSDT --side BUY --type MARKET --quantity 0.001 or py cli.py place --symbol BTCUSDT --side BUY --type MARKET --quantity 0.001 (if oython doesn't work try with py)
# SELL 0.1 ETH at market price
python cli.py place --symbol ETHUSDT --side SELL --type MARKET --quantity 0.1 # SELL 0.001 BTC at $100,000 (resting limit)
python cli.py place --symbol BTCUSDT --side SELL --type LIMIT --quantity 0.001 --price 100000 py cli.py place --symbol BTCUSDT --side SELL --type LIMIT --quantity 0.001 --price 100000
# BUY 0.002 BTC at $55,000 with IOC time-in-force
python cli.py place --symbol BTCUSDT --side BUY --type LIMIT --quantity 0.002 --price 55000 --tif IOC# SELL stop-market at $90,000 trigger
python cli.py place --symbol BTCUSDT --side SELL --type STOP_MARKET --quantity 0.001 --stop-price 90000python cli.py orders
python cli.py orders --symbol BTCUSDTpython cli.py accountpython cli.py --log-level DEBUG place --symbol BTCUSDT --side BUY --type MARKET --quantity 0.001============================================================
ORDER REQUEST SUMMARY
============================================================
Symbol : BTCUSDT
Side : BUY
Type : MARKET
Quantity : 0.001
============================================================
============================================================
ORDER RESPONSE
============================================================
orderId : 4007437269
symbol : BTCUSDT
side : BUY
type : MARKET
origQty : 0.001
executedQty : 0.001
price : 0
avgPrice : 96420.10
status : FILLED
timeInForce : GTC
updateTime : 1746089524182
============================================================
β
Order placed successfully! OrderId: 4007437269
##OUTPUT SCREENSHOTS
1st Screenshot

Logs are written to logs/trading_bot.log (rotating, max 5 MB Γ 3 backups).
Each log entry includes:
- Timestamp (ISO 8601)
- Level (DEBUG / INFO / WARNING / ERROR)
- Module name
- Human-readable message
API errors, network failures, and validation errors are all captured with context.
usage: trading_bot [-h] [--base-url URL] [--log-level {DEBUG,INFO,WARNING,ERROR}]
<command> ...
Commands:
place Place a new order
orders List open orders
account Show account balances
ping Test connectivity
place arguments:
--symbol Trading pair, e.g. BTCUSDT (required)
--side BUY or SELL (required)
--type MARKET | LIMIT | STOP_MARKET | STOP (required)
--quantity Order size in base asset (required)
--price Limit price (required for LIMIT)
--stop-price Trigger price (required for STOP_MARKET / STOP)
--tif Time-in-force: GTC|IOC|FOK|GTX (default: GTC)
--reduce-only Place a reduce-only order
- Testnet only β the default base URL is
https://testnet.binancefuture.com. Pass--base-urlto override. - USDT-M Futures β this bot targets the USD-margined perpetual futures market, not spot.
- No order book validation β symbol precision (tick size, lot size) is not pre-checked; the exchange will reject requests that violate these rules with a clear error message.
- Credentials via env / .env β no credentials are ever stored in source files.
reduce_onlydefaults to False β pass--reduce-onlyto override.
requests>=2.31.0 # HTTP client
python-dotenv>=1.0.0 # .env file loading
Python 3.9+ required.

