Skip to content

Sujit-1509/Junior-Python-Developer-Crypto-Trading-Bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Advanced Binance Futures Trading Bot

A comprehensive Python trading bot for Binance Futures Testnet with both CLI and web interfaces.

🚀 Features

Trading Operations

  • Market Orders: Instant buy/sell at current market price
  • Limit Orders: Buy/sell at specific price levels
  • Stop-Market Orders: Stop-loss and take-profit orders
  • TWAP Orders: Time-Weighted Average Price execution

Real-time Data

  • WebSocket Integration: Live order updates and market data
  • User Data Stream: Real-time account and order status updates
  • Market Data Stream: Live price feeds and ticker updates

Interfaces

  • CLI Interface: Command-line trading with full argument support
  • Web UI: Streamlit-based dashboard for user-friendly trading
  • Comprehensive Logging: All API calls and responses logged

Safety Features

  • Precision Validation: Automatic price/quantity rounding per exchange rules
  • Exchange Filters: Respects min/max quantities and tick sizes
  • Error Handling: Robust error handling and recovery
  • Testnet Environment: Safe testing with no real money

📦 Installation

  1. Install Python Dependencies:
pip install -r requirements.txt
  1. Get Binance Testnet API Keys:
    • Go to Binance Testnet
    • Create account and generate API keys
    • Note: These are testnet keys - no real money involved

🖥️ Usage

CLI Interface

Basic Commands

# Get server time
python advanced_binance_futures_bot.py --api-key YOUR_API_KEY --secret-key YOUR_SECRET_KEY time

# Place market order
python advanced_binance_futures_bot.py --api-key YOUR_API_KEY --secret-key YOUR_SECRET_KEY market --symbol BTCUSDT --side BUY --quantity 0.001

# Place limit order  
python advanced_binance_futures_bot.py --api-key YOUR_API_KEY --secret-key YOUR_SECRET_KEY limit --symbol BTCUSDT --side BUY --quantity 0.001 --price 30000

# Place stop order
python advanced_binance_futures_bot.py --api-key YOUR_API_KEY --secret-key YOUR_SECRET_KEY stop --symbol BTCUSDT --side SELL --quantity 0.001 --price 32000 --stop-price 31000

# Execute TWAP order
python advanced_binance_futures_bot.py --api-key YOUR_API_KEY --secret-key YOUR_SECRET_KEY twap --symbol BTCUSDT --side BUY --quantity 0.01 --slices 5 --interval 30

Web Interface

Launch the Streamlit dashboard:

streamlit run bot_ui.py

Then open your browser to http://localhost:8501

Web Interface Features:

  • API Configuration: Secure credential input
  • Order Placement: Visual interface for all order types
  • TWAP Execution: Progress tracking for multi-slice orders
  • Order History: Real-time display of executed orders
  • Market Data: Live price feeds (when WebSocket connected)

🏗️ Architecture

Core Components

BinanceFuturesREST: Handles all REST API operations

  • HMAC SHA256 signature generation
  • Automatic precision adjustment
  • Exchange info caching
  • Error handling and retry logic

BinanceFuturesWS: Manages WebSocket connections

  • User data stream for order updates
  • Market data stream for price feeds
  • Automatic reconnection handling
  • Thread-safe message processing

TWAPOrder: Implements time-weighted average price execution

  • Intelligent order splitting
  • Configurable timing intervals
  • Progress tracking and reporting
  • Error recovery between slices

File Structure

├── advanced_binance_futures_bot.py   # Main CLI application
├── bot_ui.py                        # Streamlit web interface  
├── requirements.txt                 # Python dependencies
├── README.md                        # Documentation
└── binance_futures_bot.log         # Application logs

🔒 Security Features

  • API Key Protection: Keys never logged or exposed
  • HMAC Signature: All requests cryptographically signed
  • Testnet Environment: No real funds at risk
  • Input Validation: All parameters validated before submission
  • Rate Limiting: Respects Binance API limits

📊 Logging

All operations are logged to binance_futures_bot.log:

  • API request/response details
  • Order execution summaries
  • WebSocket connection status
  • Error messages and stack traces
  • TWAP execution progress

⚠️ Important Notes

  1. Testnet Only: This bot is configured for Binance Futures Testnet
  2. No Real Trading: All operations use test funds only
  3. API Limits: Respect Binance rate limits to avoid restrictions
  4. Error Handling: Always check logs for detailed error information
  5. Precision: Orders automatically adjusted to meet exchange requirements

🚨 Disclaimer

This software is for educational and testing purposes only. Always test thoroughly in testnet before any real trading. The authors are not responsible for any financial losses.

📞 Support

For issues and questions:

  1. Check the logs in binance_futures_bot.log
  2. Verify API credentials and permissions
  3. Ensure stable internet connection for WebSocket streams
  4. Review Binance API documentation for specific error codes

About

A crypto trading bot for binance trading

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages