A lightweight Python CLI application to place Market and Limit orders on the Binance Futures Testnet. Built with clean separation of concerns, structured logging, and robust input validation.
trading_bot/
├── bot/
│ ├── __pycache__/
│ ├── __init__.py
│ ├── client.py # Binance client wrapper (auth + init)
│ ├── logging_config.py # File + console logger setup
│ ├── orders.py # Market and Limit order logic
│ └── validators.py # CLI input validation
├── logs/
│ ├── trading_bot_YYYYMMDD.log # Auto-generated daily log
│ ├── market_order_sample.log # Sample MARKET order log
│ └── limit_order_sample.log # Sample LIMIT order log
├── .env.example # Template for API credentials
├── cli.py # CLI entry point (argparse)
├── README.md
└── requirements.txt
- Go to https://testnet.binancefuture.com
- Log in using "Log In with GitHub" (no separate registration needed).
- On the dashboard, scroll to the API Key section and click Generate.
- Copy your API Key and Secret Key.
⚠️ This is a separate site from binance.com. Real Binance credentials will not work here.
git clone https://github.com/GithubSohamSaha/Trading-bot.git
cd Trading-botpython -m venv venv
# Windows
venv\Scripts\activate
# macOS / Linux
source venv/bin/activatepip install -r requirements.txtCreate a .env file in the project root:
BINANCE_TESTNET_API_KEY=your_api_key_here
BINANCE_TESTNET_API_SECRET=your_api_secret_here
The app uses
python-dotenvto load these automatically. Never commit your.envfile.
python cli.py --ping[OK] Binance Futures Testnet is reachable.
python cli.py --symbol BTCUSDT --side BUY --type MARKET --quantity 0.001Actual Output:
───────────────────────────────────────────────────────
ORDER REQUEST SUMMARY
───────────────────────────────────────────────────────
Symbol : BTCUSDT
Side : BUY
Type : MARKET
Quantity : 0.001
───────────────────────────────────────────────────────
2026-04-22 13:45:01 | INFO | trading_bot.orders | Placing MARKET order | symbol=BTCUSDT | side=BUY | qty=0.001
2026-04-22 13:45:02 | INFO | trading_bot.orders | MARKET order placed successfully
───────────────────────────────────────────────────────
ORDER RESPONSE
───────────────────────────────────────────────────────
Order ID : 13060665209
Symbol : BTCUSDT
Side : BUY
Type : MARKET
Orig Qty : 0.0010
Exec Qty : 0.0000
Avg Price : 0.00
Price : 0.00
Status : NEW
TIF : GTC
───────────────────────────────────────────────────────
[SUCCESS] MARKET BUY order placed successfully!
python cli.py --symbol BTCUSDT --side SELL --type MARKET --quantity 0.001python cli.py --symbol BTCUSDT --side BUY --type LIMIT --quantity 0.001 --price 50000Actual Output:
───────────────────────────────────────────────────────
ORDER REQUEST SUMMARY
───────────────────────────────────────────────────────
Symbol : BTCUSDT
Side : BUY
Type : LIMIT
Quantity : 0.001
Price : 50000.0
───────────────────────────────────────────────────────
2026-04-22 13:46:43 | INFO | trading_bot.orders | Placing LIMIT order | symbol=BTCUSDT | side=BUY | qty=0.001 | price=50000.0
2026-04-22 13:46:43 | INFO | trading_bot.orders | LIMIT order placed successfully
───────────────────────────────────────────────────────
ORDER RESPONSE
───────────────────────────────────────────────────────
Order ID : 13060669540
Symbol : BTCUSDT
Side : BUY
Type : LIMIT
Orig Qty : 0.0010
Exec Qty : 0.0000
Avg Price : 0.00
Price : 50000.00
Status : NEW
TIF : GTC
───────────────────────────────────────────────────────
[SUCCESS] LIMIT BUY order placed successfully!
python cli.py --symbol BTCUSDT --side SELL --type LIMIT --quantity 0.001 --price 95000Actual Output:
───────────────────────────────────────────────────────
ORDER REQUEST SUMMARY
───────────────────────────────────────────────────────
Symbol : BTCUSDT
Side : SELL
Type : LIMIT
Quantity : 0.001
Price : 95000.0
───────────────────────────────────────────────────────
2026-04-22 13:49:26 | INFO | trading_bot.orders | Placing LIMIT order | symbol=BTCUSDT | side=SELL | qty=0.001 | price=95000.0
2026-04-22 13:49:27 | INFO | trading_bot.orders | LIMIT order placed successfully
───────────────────────────────────────────────────────
ORDER RESPONSE
───────────────────────────────────────────────────────
Order ID : 13060669541
Symbol : BTCUSDT
Side : SELL
Type : LIMIT
Orig Qty : 0.0010
Exec Qty : 0.0000
Avg Price : 0.00
Price : 95000.00
Status : NEW
TIF : GTC
───────────────────────────────────────────────────────
[SUCCESS] LIMIT SELL order placed successfully!
| Argument | Required | Description |
|---|---|---|
--symbol / -s |
✅ | Trading pair (e.g. BTCUSDT, ETHUSDT) |
--side |
✅ | BUY or SELL |
--type / -t |
✅ | MARKET or LIMIT |
--quantity / -q |
✅ | Order size in base asset units |
--price / -p |
For LIMIT only | Limit price |
--ping |
— | Test connectivity and exit |
All logs are written to logs/trading_bot_YYYYMMDD.log (one file per day).
| Handler | Level | Purpose |
|---|---|---|
| File | DEBUG |
Full API request params + raw responses |
| Console | INFO |
Key events only (order placed, errors) |
| Scenario | Behaviour |
|---|---|
Missing API credentials in .env |
Clear error message + exit code 1 |
| Invalid symbol format | Validation error before any API call |
| Invalid side or order type | Validation error before any API call |
Missing --price for LIMIT order |
Validation error before any API call |
| Quantity or price ≤ 0 | Validation error before any API call |
| Binance API error (4xx) | Error logged with code + message, failure printed |
| Network / connectivity failure | Error logged, failure printed |
- Testnet only — hardcoded to
https://testnet.binancefuture.com. To use mainnet, settestnet=Falseinclient.py. - USDT-M Futures — only USD-margined perpetual futures are supported.
- Time-in-Force for LIMIT orders defaults to
GTC(Good Till Cancelled). - Quantity precision must match Binance Futures symbol rules (e.g. BTCUSDT: 3 decimal places). Adjust if you get a precision error.
- Credentials are loaded from a
.envfile in the project root viapython-dotenv.
- Python 3.8+
python-binance==1.0.19python-dotenvrequests>=2.31.0