How to Set Up a Crypto Trading Bot for Beginners (Step-by-Step 2025)
A complete beginner's guide to setting up your first crypto trading bot in 2025. No prior trading experience needed. Covers choosing a bot, connecting to an exchange, and running it safely.
Builder of AI agents, crypto trading bots, and open-source automation tools. Sharing practical guides on how to build, deploy, and profit from AI and DeFi technology.
You Do Not Need to Be an Expert
The #1 reason beginners do not set up a trading bot is fear. Fear of losing money, fear of the technical complexity, fear of making a mistake.
This guide removes all of that. By the end, you will have a working bot connected to a real exchange โ using paper trading first so there is zero financial risk while you learn.
Step 1: Choose Your Exchange
Your bot needs an exchange with a good API. The best options for beginners in 2025:
| Exchange | API Quality | Fees | Good For | |----------|------------|------|---------| | Binance | Excellent | Low | Best overall choice | | Bybit | Excellent | Low | Futures/perpetuals | | Coinbase Advanced | Good | Medium | US users | | Kraken | Good | Medium | European users |
Recommendation: Start with Binance. Best liquidity, most pairs, excellent API documentation.
Step 2: Create API Keys (Safely)
On Binance:
- Log in โ Profile โ API Management
- Click "Create API"
- Name it "my-trading-bot"
- Critical security settings:
- โ Enable Spot & Margin Trading
- โ Disable Withdrawals (never give a bot withdrawal access)
- Restrict to your IP address
You will get two values โ save them securely:
API Key(public)Secret Key(private โ treat like a password)
Step 3: Install the Tools
# Install Python (if not already installed)
# Download from python.org
# Create a project folder
mkdir my-crypto-bot
cd my-crypto-bot
# Create virtual environment
python -m venv venv
source venv/bin/activate # Mac/Linux
# venv\Scripts\activate # Windows
# Install CCXT (the exchange library)
pip install ccxt python-dotenv
Step 4: Create Your Config File
# Create .env file (NEVER commit this to GitHub)
touch .env
# .env
BINANCE_API_KEY=your_api_key_here
BINANCE_SECRET=your_secret_key_here
Step 5: Your First Bot โ A Simple Moving Average Strategy
# bot.py
import ccxt
import time
import os
from dotenv import load_dotenv
load_dotenv()
# Connect to Binance
exchange = ccxt.binance({
'apiKey': os.getenv('BINANCE_API_KEY'),
'secret': os.getenv('BINANCE_SECRET'),
'sandbox': True, # โ PAPER TRADING MODE โ no real money
})
SYMBOL = 'BTC/USDT'
FAST_PERIOD = 9 # 9-candle moving average
SLOW_PERIOD = 21 # 21-candle moving average
TRADE_AMOUNT_USDT = 100 # Amount to trade in USDT
def get_moving_average(prices, period):
"""Calculate simple moving average."""
if len(prices) < period:
return None
return sum(prices[-period:]) / period
def get_ohlcv_closes(symbol, timeframe='1h', limit=50):
"""Get recent closing prices."""
candles = exchange.fetch_ohlcv(symbol, timeframe, limit=limit)
return [candle[4] for candle in candles] # Index 4 = close price
def check_signal():
"""Return BUY, SELL, or HOLD based on moving averages."""
closes = get_ohlcv_closes(SYMBOL)
fast_ma = get_moving_average(closes, FAST_PERIOD)
slow_ma = get_moving_average(closes, SLOW_PERIOD)
if fast_ma is None or slow_ma is None:
return 'HOLD'
# Golden cross: fast MA crosses above slow MA = BUY
# Death cross: fast MA crosses below slow MA = SELL
prev_closes = closes[:-1]
prev_fast = get_moving_average(prev_closes, FAST_PERIOD)
prev_slow = get_moving_average(prev_closes, SLOW_PERIOD)
if prev_fast <= prev_slow and fast_ma > slow_ma:
return 'BUY'
elif prev_fast >= prev_slow and fast_ma < slow_ma:
return 'SELL'
return 'HOLD'
def get_btc_amount(usdt_amount):
"""Convert USDT amount to BTC."""
ticker = exchange.fetch_ticker(SYMBOL)
return usdt_amount / ticker['last']
# Main loop
print("๐ค Bot started (PAPER TRADING MODE)")
last_signal = 'HOLD'
while True:
try:
signal = check_signal()
if signal != last_signal and signal != 'HOLD':
print(f"\n๐ Signal: {signal}")
if signal == 'BUY':
amount = get_btc_amount(TRADE_AMOUNT_USDT)
order = exchange.create_market_buy_order(SYMBOL, amount)
print(f"โ
BUY order placed: {order['id']}")
elif signal == 'SELL':
balance = exchange.fetch_balance()
btc_balance = balance['BTC']['free']
if btc_balance > 0.0001:
order = exchange.create_market_sell_order(SYMBOL, btc_balance)
print(f"โ
SELL order placed: {order['id']}")
last_signal = signal
else:
print(f"Signal: {signal} โ No action", end='\r')
time.sleep(60) # Check every minute
except Exception as e:
print(f"Error: {e}")
time.sleep(30)
Step 6: Run Your Bot
python bot.py
You will see output like:
๐ค Bot started (PAPER TRADING MODE)
Signal: HOLD โ No action
Signal: HOLD โ No action
๐ Signal: BUY
โ
BUY order placed: 12345678
Important: The bot is in paper trading mode (sandbox: True). No real money is used. Watch it for 1โ2 weeks before removing the sandbox setting.
Step 7: Switch to Live Trading (When Ready)
When you are confident the strategy works:
# bot.py โ remove sandbox
exchange = ccxt.binance({
'apiKey': os.getenv('BINANCE_API_KEY'),
'secret': os.getenv('BINANCE_SECRET'),
# 'sandbox': True, โ Remove this line
})
Before going live:
- โ Run in paper mode for at least 1 week
- โ Start with a small amount you can afford to lose
- โ Set a maximum daily loss limit in the code
- โ Monitor the first few live trades closely
Step 8: Run 24/7 on a VPS
Your laptop cannot run the bot while you sleep. Deploy to a cheap VPS:
# On Hetzner/DigitalOcean server (Ubuntu)
git clone https://github.com/yourusername/my-crypto-bot
cd my-crypto-bot
pip install -r requirements.txt
# Install PM2 for process management
npm install -g pm2
pm2 start bot.py --name crypto-bot --interpreter python3
pm2 save
pm2 startup
VPS cost: โฌ3โ5/month. Worth every cent for 24/7 uptime.
Common Beginner Mistakes to Avoid
- Using real money immediately โ Always test in paper mode first
- Giving the bot withdrawal permissions โ Never do this
- Using all your capital โ Start with 10โ20% of what you are willing to risk
- Stopping the bot after one bad trade โ Strategies have losing periods; that is normal
- Not keeping logs โ Log every trade for analysis
FAQ
Q: Do I need to know Python to run a trading bot? A: For this tutorial, basic Python knowledge helps but is not required. Copy, paste, and modify the values.
Q: How much money should I start with? A: Start with whatever you can afford to lose entirely. $100โ$500 is reasonable for learning.
Q: Is automated trading safe? A: No investment is "safe." Bots can lose money. Always test thoroughly and start small.
Q: Will this bot make me rich? A: The moving average strategy is a learning example, not a guaranteed profit strategy. Real edge requires research and backtesting.
Get a More Powerful Bot
The bot above is for learning. For production arbitrage and AI-driven strategies, grab our pre-built tools from the Tools page โ they include backtesting, risk management, and multi-exchange support.
Tagged in
Related Articles
Crypto Bot Risk Management: The 10 Rules That Separate Winners From Losers
7 min read
Crypto BotsHow to Build a Self-Healing Trading Bot That Fixes Its Own Errors
5 min read
Crypto BotsPump.fun and Solana Meme Coin Bots: How to Automate the Hottest Trend
5 min read
Crypto BotsHow to Build a Crypto Portfolio Auto-Rebalancing Bot
5 min read