Trading Bot CLI is a lightweight Python-based command-line application that simulates and executes trading orders on Binance Futures Testnet.
The project is designed to demonstrate clean backend architecture, robust input validation, structured logging, and resilient API handling.
It supports MARKET, LIMIT, and STOP-LIMIT orders with a modular and production-style design.
- CLI-based trading execution tool
- Supports:
- MARKET orders
- LIMIT orders
- STOP-LIMIT orders (trigger + limit)
- Handles BUY and SELL operations
- Modular architecture with clear separation of concerns:
- CLI layer (input/output)
- Validation layer
- Order execution layer (with retry logic)
- API client layer (mock + real support)
- Provides structured JSON outputs
- Logs all operations to file
Execute trades directly from terminal using structured arguments.
Ensures correctness of:
- symbol
- side (BUY/SELL)
- order type
- quantity
- price and stop price
Supports:
- MARKET
- LIMIT
- STOP-LIMIT (with stop trigger)
- Default: Mock mode (safe execution)
- Optional: Real Binance Futures Testnet integration
Retries failed order execution automatically.
Logs all inputs, outputs, and errors to logs/app.log.
Returns clean, structured responses for both success and failure cases.
- Python 3.11
- argparse (CLI parsing)
- logging (built-in)
- python-binance (API integration, optional)
- pytest (basic testing)
trading_bot/
│
├── bot/
│ ├── client.py # Binance client (mock + real support)
│ ├── orders.py # Order execution + retry logic
│ ├── validators.py # Input validation
│ ├── logging_config.py # Logging setup
│ └── cli.py # CLI entry point
│
├── logs/
│ └── app.log
│
├── tests/
│ └── test_validators.py
│
├── requirements.txt
└── README.md
git clone <your-repo-link>
cd trading_botpython3.11 -m venv venv
venv\Scripts\activatepip install -r requirements.txtpython bot/cli.py --symbol BTCUSDT --side BUY --type MARKET --qty 0.01python bot/cli.py --symbol BTCUSDT --side SELL --type LIMIT --qty 0.01 --price 60000python bot/cli.py --symbol BTCUSDT --side BUY --type STOP_LIMIT --qty 0.01 --price 60000 --stop-price 60500{
"success": true,
"data": {
"symbol": "BTCUSDT",
"status": "FILLED",
"orderId": 12345,
"executedQty": 0.01
}
}{
"success": false,
"error": "stop_price is required for STOP_LIMIT"
}Logs are stored in:
logs/app.log
Includes:
- input parameters
- execution results
- errors and retries
- No API keys required
- Safe simulation of order execution
To enable real Binance Futures Testnet:
- Generate API keys
- Update client initialization:
BinanceClient(api_key, api_secret, use_mock=False)Due to Binance testnet API key generation restrictions (KYC enforcement in some cases), the application runs in mock mode by default.
The real API integration is fully implemented and can be enabled when valid credentials are available.
Run tests:
pytest