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 ?