Project #10
Autobot: AI Binance Futures Bot
A Python-based algorithmic trading bot that uses local AI (via Ollama) and Technical Analysis (SMA, RSI) to automate trading decisions on Binance USD(M) Futures. It is accompanied by a standalone, realtime CLI tracking dashboard for monitoring your active trades and PNL.
Autobot: AI Binance Futures Bot
A Python-based algorithmic trading bot that uses local AI (via Ollama) and Technical Analysis (SMA, RSI) to automate trading decisions on Binance USD(M) Futures. It is accompanied by a standalone, realtime CLI tracking dashboard for monitoring your active trades and PNL.
Features
- AI-Driven Edge: Integrates with Ollama running a local LLM model (e.g., gemma4:e4b) to interpret market signals.
- Hedge Mode Compatible: Explicitly manages LONG and SHORT margins side-by-side natively.
- Standalone Dashboard: Realtime, flicker-free terminal dashboard tracking Mark Price, entry sizes, ROI%, and active UNREALIZED PNL.
- Historic PNL Reporting: Includes a secondary offline SQLite reporter updating every 60 seconds to accurately pull REALIZED PNL locally to calculate accurate Daily Returns independently of the active bot tracker.
- Automated Risk Management: Automatically bounds positions by opening isolated Take Profit and Stop Loss boundary limit orders.
- File Logging: Writes structural bot logic and server-side trade creations dynamically to an offline bot_activity.log file securely.
File Structure
- main.py - The core AI trading loop. It polls historical klines, applies RSI and SMA overlays, queries your local AI model, and creates bracket orders via the Binance API. Also automatically outputs local logs out to bot_activity.log.
- track.py - A standalone CLI position monitor to inspect UNREALIZED running stats in realtime.
- report.py - A secondary terminal process that syncs Binance's futures_income_history precisely every 60 seconds, buffering records seamlessly inside a local SQLite trades.db to continuously sum daily REALIZED PNL reliably.
Prerequisites
- Python 3.8+
- Ollama properly installed and running locally.
- A Binance account (Testnet or Live) with USD(M) Futures enabled.
Installation
Install the necessary Python dependencies:
pip install pandas ta python-binance colorama python-dotenv ollama
Pull the AI model via Ollama. By default, the bot assumes you have a model loaded like gemma4:e4b:
ollama pull gemma4:e4b
Configuration
Create a .env file in your root folder. This file will securely load your Binance keys and configure your network:
API_KEY=your_binance_api_key
API_SECRET=your_binance_api_secret
TESTNET=True
AI_MODEL=gemma4:e4b
Note: It is highly recommended to leave TESTNET=True initially while verifying the bot acts appropriately.
Usage
You can run up to three distinct terminal modules concurrently:
1. Start the Trading Engine:
python main.py
It will prompt you for a trading pair and an active USDT trade threshold on startup.
2. Launch the active Live Terminal Dashboard:
python track.py
This seamlessly loops strictly analyzing active unclosed position states in real time.
3. Launch the realized PNL Historical reporting system:
python report.py
This fetches securely from Binance via an independent DB schema the sum of all totally realized PNL activities per given day alongside breaking out exact performance metric logs for your 15 most recently closed positions independent of the main loops' active TP/SL boundary hits.
4. To solve IP change issue use the VPS for tunneling
ssh -D 1080 -f -N user@your_vps_ip
5. This finds the process on port 1080 and kills it (-k)
fuser -k 1080/tcp