Skip to content

itsdevansh5/CryptoTradingBot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Binance Futures Testnet Trading Bot

Overview

This project is a CLI-based Python application that places BUY/SELL futures orders (MARKET and LIMIT) on Binance USDT-M Futures Testnet.

The goal of the project is to demonstrate:

  • Correct usage of Binance Futures Testnet APIs
  • Clean CLI design
  • Proper input validation
  • Robust logging and error handling
  • Production-style project structure

This bot is intentionally simple and does not include any trading strategy, indicators, or automation loop.


Features

  • Futures trading only (USDT-M)
  • Order types supported:
    • MARKET
    • LIMIT
  • Order sides:
    • BUY
    • SELL
  • CLI-based input using Typer
  • Input validation before API calls
  • File-based rotating logs
  • Clear, readable console output

Tech Stack

  • Python 3.12
  • python-binance
  • typer
  • python-dotenv
  • logging (standard library)

Prerequisites

  • Python 3.9+ (tested on Python 3.12)
  • Binance Futures Testnet account
  • Binance Futures Testnet API Key & Secret

Setup Instructions

1. Clone the repository

git clone <your-repo-url>
cd CryptoTradingBot

2. Create and activate virtual environment

python -m venv venv
source venv/bin/activate   # Linux / macOS
# OR
venv\Scripts\activate      # Windows

3. Install dependencies

pip install -r requirements.txt

4. Environment variables

Create a .env file in the project root:

BINANCE_API_KEY=your_testnet_api_key
BINANCE_API_SECRET=your_testnet_secret_key

⚠️ Never commit your .env file. Use .env.example for reference.


How to Get Binance Futures Testnet API Keys

  1. Go to Binance Futures Testnet
  2. Create / login to your testnet account
  3. Generate Futures API Key and Secret
  4. Enable Futures permissions

How to Run

Show CLI Help

python cli.py --help

Place a MARKET Order (Example)

python cli.py \
  --symbol BTCUSDT \
  --side BUY \
  --order-type MARKET \
  --quantity 0.002

Expected output:

Order placed successfully
Order ID: <id>
Status: FILLED
Executed Qty: 0.002
Avg Price: <price>

Place a LIMIT Order (Example)

python cli.py \
  --symbol BTCUSDT \
  --side BUY \
  --order-type LIMIT \
  --quantity 0.002 \
  --price 30000

Expected output:

Order placed successfully
Order ID: <id>
Status: NEW
Executed Qty: 0
Avg Price: N/A

Logging

  • Logs are written to logs/bot.log
  • Uses RotatingFileHandler
  • Max size: ~1MB
  • Keeps last 3 log files

Logged information includes:

  • Order request parameters
  • Order responses
  • API errors
  • Network errors

Sensitive data (API secrets) are never logged.


Project Structure

CryptoTradingBot/
│
├── services/
│   ├── client.py          # Binance Futures client wrapper
│   ├── orders.py          # Order placement logic
│   ├── validators.py     # Input validation
│   └── logging_config.py # Logging configuration
│
├── cli.py                 # CLI entry point
├── requirements.txt
├── README.md
├── .env.example
└── logs/
    └── logging.log

Assumptions & Limitations

  • Futures trading only (no spot trading)
  • Testnet environment only
  • No position management (close/cancel not implemented)
  • No trading strategy or automation loop
  • No leverage configuration

Notes

  • Binance Futures enforces a minimum notional value (e.g. 100 USDT)
  • Orders below this threshold will be rejected by Binance
  • Such errors are expected and handled gracefully

License

This project is for educational and evaluation purposes only.

About

A crypto trading bot to place orders on Binance Future

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages