Crypto automation sounds exciting: a bot that trades while you sleep, catches profitable trends, and never gets tired.
But when I started exploring the space, most bots I found were either overhyped, under-documented, or flat-out broken.
So I decided to build my own bot from scratchโone that works in real time, with full control from the command line, supports backtesting, paper trading, and can deploy to a $5 VPS.
This post covers my journey from zero to real-time execution bot. If you're a Python dev or a trader curious about bot building, this one's for you.
๐งฑ Planning the Bot: Goals and Features
Before writing a single line of code, I outlined the core requirements:
- โ Real-time strategy execution using Binance API
- โ CLI-based interface for strategy selection and control
- โ Strategy modularity (plug-in based system)
- โ Support for backtesting and paper/live modes
- โ Logging of trades and errors
- โ Lightweight for VPS deployment
๐งฐ Tech Stack I Used
- Python 3.10+
-
Binance API via
python-binance
- TA-Lib / pandas-ta for technical indicators
- pandas / NumPy for data processing
- SQLite for optional trade logging
- argparse or Typer for CLI interface
๐ Project Architecture
crypto_bot/
โโโ strategies/
โ โโโ rsi_strategy.py
โ โโโ macd_strategy.py
โโโ core/
โ โโโ trader.py
โ โโโ logger.py
โโโ config/
โ โโโ settings.json
โโโ cli.py
โโโ bot.py
โโโ logs/
- Strategies: Each is a pluggable Python class
- Trader: Handles data fetching and order execution
- Logger: Manages session logs and optional SQLite
- CLI: Launches bot with selected strategy and symbol
๐ Real-Time Trading Loop (Core Logic)
Hereโs a simplified version of the loop:
while True:
df = fetch_ohlcv(symbol, interval)
signal = strategy.evaluate(df)
if signal == "BUY":
trader.buy(symbol, quantity)
elif signal == "SELL":
trader.sell(symbol, quantity)
sleep(next_candle_time())
This ensures:
- Continuous data pulling
- Strategy evaluation per new candle
- Instant execution for valid signals
๐ Strategy Example: RSI Strategy (Modular)
class RSIStrategy:
def __init__(self, period=14, overbought=70, oversold=30):
self.period = period
self.overbought = overbought
self.oversold = oversold
def evaluate(self, df):
df['rsi'] = ta.rsi(df['close'], length=self.period)
if df['rsi'].iloc[-1] < self.oversold:
return "BUY"
elif df['rsi'].iloc[-1] > self.overbought:
return "SELL"
return "HOLD"
New strategies can follow this simple class-based structure.
๐ป CLI Control: Run Strategies from Terminal
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--symbol', type=str, required=True)
parser.add_argument('--strategy', type=str, required=True)
parser.add_argument('--mode', choices=['paper', 'live'], default='paper')
args = parser.parse_args()
bot = TradingBot(symbol=args.symbol, strategy=args.strategy, mode=args.mode)
bot.run()
Launch your bot like this:
python cli.py --symbol BTCUSDT --strategy rsi --mode paper
๐งช Backtesting & Paper Trading Support
The bot has:
- Historical simulation with CSV or Binance fetch
- Paper mode that logs trades without placing them
- Live switch for actual order placement after testing
Sample output:
[2025-04-23 14:22:01] BUY BTCUSDT at 62410.5 [RSI: 29.7]
๐ Logging & Trade History
Choose between:
- Plain text log files
- SQLite logging for deeper analysis and dashboards
Sample session log:
[INFO] RSI crossed below 30. Triggering BUY signal.
[EXECUTE] Simulated BUY 0.01 BTC at 61,420.20
โ๏ธ VPS Deployment (DigitalOcean or Similar)
I deployed the bot on a $5/month droplet:
- Setup Python & virtualenv
- Clone the repo
- Run the bot using
screen
ortmux
- Use
tail -f logs/session.log
to monitor
It runs 24/7 on minimal resources.
๐ง Lessons Learned
- Always test with paper mode first
- Logging is essentialโdebugging without it is chaos
- Modular code = less burnout
- Donโt over-engineer your strategiesโsimple works
- Expect API hiccups and plan for recovery
๐ Want to Build This Bot Too?
I turned the full journey into a 250+ page guide with all code included.
๐ฅ Download the PDF Guide: https://shop.matrixtrak.com
๐ป Access the Full Python Bot Repo: https://shop.matrixtrak.com/b/gWzRM
๐ Final Thoughts
This bot evolved from a weekend project to a full trading framework I now trust with real money.
Whether youโre a dev, trader, or learnerโbuilding your own crypto bot teaches you way more than using a prebuilt tool.
Let me know if youโre working on something similar, or want feedback on your strategy code. ๐
Top comments (1)
I want to create a trading bot using python and machine learning with some indicator cam we chat up ?