Skip to content

About

Dual-position futures trading bot across 100+ crypto pairs

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 

Repository files navigation

Binance Crypto Trading Bot

Automated dual-position futures trading system that simultaneously holds LONG and SHORT positions across 100+ crypto pairs on Binance, with real-time PnL tracking, DCA logic, and Telegram alerts.

Python Binance Threading Telegram


What it does

Opens both a LONG and SHORT position simultaneously on a given crypto pair (the "Sun and Moon" strategy). Monitors both positions in real time, takes profit on the winning side, and applies Dollar Cost Averaging (DCA) on the losing side to recover. Runs multiple pairs concurrently via threading. Sends trade alerts to Telegram.


Pipeline

Binance Futures API (live prices)
        ↓
leverage_and_margin() — set leverage + cross margin
        ↓
Sun_and_Moon() — open LONG + SHORT simultaneously
        ↓
The_Brain() — real-time PnL calculation loop
        ↓
Profit side → close position → notify Telegram
Loss side   → DCA_the_Gut() → add position at lower price
        ↓
the_unstoppable_heart() — reconnects on network failure
        ↓
the_engine() — threads one instance per symbol

Key Features

  • Dual-position strategy — simultaneous LONG and SHORT on the same pair
  • Real-time PnL engine — custom The_Brain() function calculates live profit/loss every tick
  • DCA recovery logic — automatically adds to losing position at configurable thresholds
  • Multi-symbol threading — runs 15–20 pairs concurrently via threading.Thread
  • Fault-tolerant heart loop — the_unstoppable_heart() catches network drops and API errors, sleeps, and restarts automatically
  • Telegram notifications — instant alerts on position open, close, profit, and loss events
  • Testnet support — switch between Binance testnet and live account via config

Technical Decisions

  • Threading over async — each symbol runs an independent blocking loop; threading was simpler to reason about than async for stateful position management
  • Custom PnL formula — uses inverse price arithmetic (1/entry - 1/live) * margin * leverage * live_price for accurate futures PnL, accounting for leverage correctly
  • DCA thresholds are configurable — margin size, loss level, and DCA add-amount are all parameterised, not hardcoded
  • Exponential backoff on failure — network errors sleep for 60–300 seconds before restarting to avoid API bans

Stack

Component Tool
Language Python 3.9+
Exchange API Binance Futures REST + python-binance
Concurrency threading
Notifications Telegram Bot API
Config python-dotenv

Setup

git clone https://github.com/aathi1/binance-crypto-bot
cd binance-crypto-bot
pip install -r requirements.txt

Create a .env file:

BINANCE_API_KEY=your_key
BINANCE_SECRET=your_secret
TELEGRAM_TOKEN=your_token
TELEGRAM_CHAT_ID=your_chat_id

Run:

python day_157.py

Configuration

Edit the top of the script to adjust:

usdt_pairs = ['ADAUSDT', 'BTCUSDT', ...]   # symbols to trade
leverage   = 15                              # futures leverage
usdt       = 0.35                            # initial position size per side
timing     = 0.8                             # loop interval in seconds

Disclaimer

This is a personal project built for learning and research. Crypto futures trading involves significant financial risk. Use at your own risk. Not financial advice.


Author

Aathithyan Venkatesh — GitHub · LinkedIn

About

Dual-position futures trading bot across 100+ crypto pairs

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors