Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Binance Futures Testnet Trading Bot CLI

A clean, modular Python-based Command Line Interface (CLI) for placing orders on the Binance Futures Testnet (USDT-M).

Features

  • 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.

Project Structure

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)

Prerequisites

Installation

  1. Clone or copy the project files to your machine.
  2. Navigate to the trading_bot directory:
    cd trading_bot
  3. Create a virtual environment (optional but recommended):
    python -m venv venv
    source venv/bin/activate  # On Windows use `venv\Scripts\activate`
  4. Install dependencies:
    pip install -r requirements.txt

Configuration

  1. Create a .env file in the trading_bot directory:
    cp .env.example .env
  2. Open .env and 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

Usage

Place a MARKET Order

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.002

Place a LIMIT Order

python cli.py --symbol BTCUSDT --side SELL --type LIMIT --quantity 0.002 --price 65000

View Help

python cli.py --help

Validation & Error Handling

  • Missing Required Args: The bot will notify you if required arguments are missing.
  • Invalid Side/Type: Only BUY/SELL and MARKET/LIMIT are accepted (case-insensitive).
  • Price Requirement: For LIMIT orders, the --price argument is mandatory.
  • Logging: All events, including API errors and connection issues, are logged to app.log.

Troubleshooting

Error: Timestamp for this request was ahead of the server's time (Code: -1021)

The bot now handles this automatically by synchronizing your local system time offset with the Binance server.

Error: Order's notional must be no smaller than 100 (Code: -4164)

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.

License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages