Skip to content

A secure, production-ready CLI trading bot for Binance USDT-M Futures featuring a custom HMAC-signed API client, support for market and limit orders, and an advanced TWAP algorithm for low-impact trade execution.

Notifications You must be signed in to change notification settings

vendotha/TradeForge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

7 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš€ TradeForge - Binance Futures Order Bot

A production-ready, secure CLI trading bot for Binance USDT-M Futures with advanced algorithmic trading capabilities

Python License Security

Author: Buvananand Vendotha
Date: November 20, 2025


๐Ÿ“‹ Table of Contents


๐ŸŽฏ Overview

This project implements a command-line trading bot for Binance USDT-M Futures, built from the ground up with enterprise-grade security and scalability in mind. Unlike wrapper-dependent solutions, this bot features a custom API client that provides full control over request signing, error handling, and execution flow.

The bot supports both standard order types (Market, Limit) and advanced algorithmic strategies (TWAP), making it suitable for both manual trading and automated execution systems.


โœจ Key Features

Core Functionality

  • โœ… Market Orders - Instant execution at current market price
  • โœ… Limit Orders - Precision entry/exit at specified price levels
  • โœ… TWAP Strategy - Time-Weighted Average Price execution to minimize market impact

Technical Highlights

  • ๐Ÿ” Custom Security Implementation - HMAC SHA256 signature generation without third-party dependencies
  • ๐Ÿ—๏ธ Modular Architecture - Separation of concerns enabling easy scalability
  • ๐Ÿ“Š Centralized Logging - Dual-output system (console + file) for real-time monitoring and auditing
  • ๐Ÿ›ก๏ธ Robust Error Handling - Comprehensive validation and API error management
  • ๐Ÿ”‘ Environment-Based Credentials - Zero hardcoded secrets, production-safe configuration

๐Ÿ›๏ธ Architecture

The project follows a modular design pattern to ensure maintainability and extensibility:

binance-futures-bot/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ client.py          # Custom API wrapper with HMAC signing
โ”‚   โ”œโ”€โ”€ logger.py          # Centralized logging system
โ”‚   โ”œโ”€โ”€ main.py            # CLI entry point with argparse routing
โ”‚   โ””โ”€โ”€ advanced/          # Advanced trading algorithms
โ”‚       โ””โ”€โ”€ twap.py        # Time-Weighted Average Price strategy
โ”œโ”€โ”€ .env                   # API credentials (gitignored)
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ requirements.txt
โ””โ”€โ”€ README.md

Design Principles

Separation of Concerns: Each module has a single, well-defined responsibility
Extensibility: New strategies (Grid, OCO, DCA) can be added without modifying core logic
Zero Dependencies: Custom API client eliminates reliance on potentially abandoned libraries
Auditability: Every trade action is logged with timestamps and full context


๐Ÿ”’ Security

Security is the cornerstone of this implementation:

1. Credential Management

  • API keys loaded from .env file using python-dotenv
  • .env excluded from version control via .gitignore
  • No secrets in code, logs, or commit history

2. Request Signing

  • Custom HMAC SHA256 implementation in client.py
  • Ensures requests cannot be intercepted or tampered with
  • Compliant with Binance API security requirements

3. Input Validation

  • Strict type checking on all user inputs
  • Symbol validation against Binance exchange info
  • Quantity and price bounds verification

๐Ÿ“ฆ Installation

Prerequisites

  • Python 3.8 or higher
  • Binance Futures Testnet or Live API keys

Setup

  1. Clone the repository
git clone https://github.com/vendotha/Buvananand-binance-bot.git
cd Buvananand-binance-bot
  1. Install dependencies
pip install -r requirements.txt
  1. Configure API credentials Create a .env file in the root directory:
BINANCE_API_KEY=your_api_key_here
BINANCE_API_SECRET=your_api_secret_here
BINANCE_BASE_URL=https://testnet.binancefuture.com  # Use testnet for testing
  1. Verify installation
python src/main.py --help

๐ŸŽฎ Usage

Market Order

Execute immediate buy/sell at current market price:

python src/main.py market <SYMBOL> <SIDE> <QUANTITY>

# Example: Buy 0.01 BTC at market price
python src/main.py market BTCUSDT BUY 0.01

Limit Order

Place order at specific price (Good Till Cancel):

python src/main.py limit <SYMBOL> <SIDE> <QUANTITY> <PRICE>

# Example: Buy 0.01 BTC at $45,000
python src/main.py limit BTCUSDT BUY 0.01 45000

TWAP Strategy

Execute large order gradually to minimize market impact:

python src/main.py twap <SYMBOL> <SIDE> <TOTAL_QUANTITY> <DURATION_MINUTES> <SLICES>

# Example: Buy 0.05 BTC over 1 minute, split into 5 orders
python src/main.py twap BTCUSDT BUY 0.05 1 5

TWAP Algorithm Logic

Quantity per Slice = Total Quantity / Number of Slices
Delay (seconds) = (Duration in Minutes ร— 60) / Number of Slices

For each slice:
  1. Execute Market Order for calculated quantity
  2. Log execution details
  3. Sleep for calculated delay
  4. Repeat until all slices completed

๐Ÿ“ธ Execution Examples

Market Order Execution

Market Order Successful market buy order execution on Binance Futures Testnet

Limit Order Execution

Limit Order Limit order placed at $45,000 price level

TWAP Strategy Execution

TWAP Strategy TWAP algorithm executing 5 sequential slices over 1-minute duration


๐Ÿ”ง Technical Implementation

Custom API Client (client.py)

  • Raw HTTP request handling using requests library
  • Dynamic header construction with timestamp and signature
  • HMAC SHA256 signature generation from scratch
  • Generic _request() method supporting all API endpoints

Logging System (logger.py)

  • Dual handler setup: StreamHandler (console) + FileHandler (bot.log)
  • ISO 8601 timestamp format for compliance
  • Color-coded console output (INFO=green, ERROR=red)
  • Rotation-ready for production deployment

Error Handling Strategy

try:
    response = self._request("POST", endpoint, params)
except requests.exceptions.HTTPError as e:
    logger.error(f"API Error: {e.response.json()}")
    # Specific handling for common errors:
    # - 400: Invalid parameters
    # - 401: Authentication failure
    # - 429: Rate limit exceeded
except Exception as e:
    logger.error(f"Unexpected error: {str(e)}")

TWAP Implementation Highlights

  • Stateful execution tracking across multiple iterations
  • Graceful interruption handling (Ctrl+C)
  • Real-time progress logging
  • Atomic order execution with rollback capability

๐Ÿš€ Future Enhancements

This architecture supports seamless integration of additional strategies:

  • Grid Trading - Automated buy low/sell high within price range
  • OCO Orders - One-Cancels-Other for stop-loss/take-profit
  • DCA Strategy - Dollar-Cost Averaging for position building
  • Portfolio Rebalancing - Multi-asset weight maintenance
  • WebSocket Integration - Real-time price monitoring
  • Backtesting Engine - Historical strategy validation

๐Ÿ“Š Project Statistics

  • Lines of Code: ~500 (core implementation)
  • Test Coverage: Validated on Binance Futures Testnet
  • Dependencies: Minimal (requests, python-dotenv, argparse)
  • API Endpoints Used: /fapi/v1/order, /fapi/v1/exchangeInfo

๐Ÿค Contributing

This project demonstrates professional-grade software engineering practices:

  • Clean, documented code following PEP 8 standards
  • Modular design enabling collaborative development
  • Comprehensive error handling and logging
  • Security-first approach with no hardcoded credentials

๐Ÿ“„ License

This project is available under the MIT License. See LICENSE file for details.


๐Ÿ‘ค Contact

Buvananand Vendotha

For questions, collaboration opportunities, or technical discussions about algorithmic trading systems, feel free to reach out.


Built with precision. Secured by design. Optimized for performance.

About

A secure, production-ready CLI trading bot for Binance USDT-M Futures featuring a custom HMAC-signed API client, support for market and limit orders, and an advanced TWAP algorithm for low-impact trade execution.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages