How to Create an Alpaca Trading Bot (Complete 2026 Tutorial)
Step-by-step guide to building a trading bot with Alpaca API. Learn how to automate stock and crypto trading with Alpaca brokerage.
What is Alpaca?
Alpaca is a commission-free brokerage that provides a powerful API for automated trading. It's become the go-to choice for trading bot developers because:
- Zero commissions on stock and crypto trades
- Free paper trading with realistic market simulation
- Robust API for programmatic trading
- Fractional shares - Trade any amount, not just whole shares
Whether you're a developer or using a no-code platform like VibeTrader, Alpaca is the execution layer that makes your bot work.
Method 1: Using VibeTrader (No Code)
The easiest way to create an Alpaca trading bot:
Step 1: Create Your Alpaca Account
- Go to alpaca.markets
- Sign up for a free account
- Complete identity verification
- Navigate to Paper Trading (start here, not live!)
Step 2: Get Your API Keys
- In Alpaca dashboard, go to "Paper Trading" section
- Click "Generate API Keys"
- Copy your API Key and Secret Key
- Keep these secure - they control your account
Step 3: Connect to VibeTrader
- Go to vibetrader.markets/settings
- Click "Connect Alpaca"
- Enter your API Key and Secret
- Select "Paper Trading" mode
Step 4: Create Your Bot
Simply describe your strategy:
"Buy $500 of AAPL when RSI drops below 30 and sell when it rises above 70"
That's it! Your bot is now connected to Alpaca and will execute trades automatically.
Method 2: Using Python (For Developers)
If you prefer coding, here's how to build an Alpaca bot with Python:
Install the Alpaca SDK
\\\python
pip install alpaca-trade-api
\\\
Basic Connection
\\\python
import alpaca_trade_api as tradeapi
Paper trading URL
BASE_URL = 'https://paper-api.alpaca.markets'
api = tradeapi.REST(
'YOUR_API_KEY',
'YOUR_SECRET_KEY',
BASE_URL
)
Check account
account = api.get_account()
print(f'Account balance: $' + str(account.cash))
\\\
Place a Simple Order
\\\python
Buy 10 shares of Apple
api.submit_order(
symbol='AAPL',
qty=10,
side='buy',
type='market',
time_in_force='day'
)
\\\
RSI Trading Bot (Basic)
\\\python
import alpaca_trade_api as tradeapi
import pandas as pd
import time
def calculate_rsi(prices, period=14):
delta = prices.diff()
gain = delta.where(delta > 0, 0).rolling(period).mean()
loss = (-delta.where(delta < 0, 0)).rolling(period).mean()
rs = gain / loss
return 100 - (100 / (1 + rs))
def run_bot():
while True:
# Get recent prices
bars = api.get_bars('AAPL', '1Hour', limit=20).df
rsi = calculate_rsi(bars['close']).iloc[-1]
position = None
try:
position = api.get_position('AAPL')
except:
pass
if rsi < 30 and not position:
api.submit_order('AAPL', qty=10, side='buy', type='market', time_in_force='day')
print(f'Bought AAPL at RSI {rsi}')
elif rsi > 70 and position:
api.submit_order('AAPL', qty=10, side='sell', type='market', time_in_force='day')
print(f'Sold AAPL at RSI {rsi}')
time.sleep(3600) # Check every hour
run_bot()
\\\
Which Method Should You Choose?
| Factor | VibeTrader (No Code) | Python (Code) |
|--------|---------------------|---------------|
| Setup Time | 5 minutes | 1-2 hours |
| Coding Required | No | Yes |
| Flexibility | High | Maximum |
| Hosting/Deployment | Handled for you | You manage |
| Maintenance | Automatic | Manual |
| Best For | Most traders | Developers |
Alpaca Paper vs Live Trading
Paper Trading (Start Here)
- Uses simulated money ($100k default)
- Real market data and execution simulation
- No risk to real capital
- API endpoint: paper-api.alpaca.markets
Live Trading
- Real money, real consequences
- Same API, different endpoint
- Requires approved live account
- API endpoint: api.alpaca.markets
Always test in paper trading first. Even experienced developers make mistakes.
Common Alpaca Bot Mistakes
- Skipping paper trading - Always test first
- No stop losses - Protect your capital
- Over-trading - More trades ≠ more profit
- Ignoring market hours - Stocks only trade 9:30am-4pm ET
- Not handling API errors - Markets can be volatile, errors happen
Ready to Start?
The fastest path from idea to automated trading:
- Create a free Alpaca account
- Connect to VibeTrader
- Describe your strategy in plain English
- Start paper trading immediately
No coding required. Create your first bot in under 5 minutes.
Ready to Automate Your Trading?
VibeTrader lets you create trading bots using plain English. No coding required.
Create Your First Bot Free →