DEV Community

Henry Lin
Henry Lin

Posted on

Lesson 2: Freqtrade Environment Setup

Lesson 2: Freqtrade Environment Setup

πŸ“š Course Series: Complete Freqtrade Quantitative Trading Course
πŸ“– Section: Part 1 - Getting Started
⏱ Duration: 2 hours
🎯 Difficulty: ⭐⭐ Beginner


🎯 Learning Objectives

After completing this lesson, you will be able to:

  • βœ… Install Python and Conda environment manager
  • βœ… Create an independent Freqtrade virtual environment
  • βœ… Successfully install Freqtrade 2025.9+
  • βœ… Configure your first config.json file
  • βœ… Run basic Freqtrade commands
  • βœ… Verify that the environment setup is successful

πŸ“‹ Prerequisites

System Requirements

Operating System:

  • βœ… macOS 10.15+
  • βœ… Ubuntu 20.04+ / Debian 11+
  • βœ… Windows 10+ (WSL2 or Native)

Hardware Requirements:

  • CPU: Dual-core or higher
  • Memory: 4GB+ (8GB recommended)
  • Storage: 20GB free space
  • Network: Stable internet connection

Estimated Time:

  • macOS/Linux: 30-45 minutes
  • Windows: 45-60 minutes

πŸ’» Part 1: Installing Conda Environment

2.1 What is Conda?

Conda is an environment management tool that can:

  • Manage different versions of Python
  • Isolate project dependencies (avoid conflicts)
  • Easily switch between environments

Why use Conda?

❌ Without Conda:
System Python (3.9) β†’ Project A needs 3.11 β†’ Conflict
                    β†’ Project B needs 3.9  β†’ OK
                    β†’ Freqtrade needs 3.11 β†’ Conflict

βœ… With Conda:
Environment A (Python 3.9) β†’ Project A
Environment B (Python 3.11) β†’ Freqtrade
System Python (3.9) β†’ Other programs
Enter fullscreen mode Exit fullscreen mode

2.2 Installing Miniconda

Miniconda is a lightweight version of Conda, recommended for use.

macOS Installation

# 1. Download Miniconda installation script
curl -O https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh

# 2. Run installation script
bash Miniconda3-latest-MacOSX-x86_64.sh

# 3. Follow prompts
# - Press Enter to view license agreement
# - Type "yes" to accept agreement
# - Press Enter to use default installation path
# - Type "yes" to initialize Conda

# 4. Reload terminal configuration
source ~/.bash_profile  # if using bash
source ~/.zshrc         # if using zsh

# 5. Verify installation
conda --version
# Output: conda 24.x.x
Enter fullscreen mode Exit fullscreen mode

Linux (Ubuntu/Debian) Installation

# 1. Download Miniconda installation script
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

# 2. Run installation script
bash Miniconda3-latest-Linux-x86_64.sh

# 3. Follow prompts (same as macOS)

# 4. Reload terminal configuration
source ~/.bashrc

# 5. Verify installation
conda --version
Enter fullscreen mode Exit fullscreen mode

Windows Installation

# Method 1: Use GUI installer (recommended)
# 1. Visit https://docs.conda.io/en/latest/miniconda.html
# 2. Download Miniconda3 Windows 64-bit
# 3. Double-click to install, select "Just Me"
# 4. Check "Add Conda to PATH"

# Method 2: Use WSL2 (suitable for developers)
# 1. Enable WSL2
# 2. Install Ubuntu 22.04
# 3. Install in Ubuntu using Linux method

# Verify installation (open Anaconda Prompt)
conda --version
Enter fullscreen mode Exit fullscreen mode

2.3 Configure Conda

# 1. Disable automatic activation of base environment (recommended)
conda config --set auto_activate_base false

# 2. Set up domestic mirrors (optional, speeds up downloads)
# Tsinghua mirror
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes

# 3. Verify configuration
conda config --show channels
Enter fullscreen mode Exit fullscreen mode

🐍 Part 2: Creating Freqtrade Environment

2.4 Create Independent Python Environment

# Starting from 2024, Anaconda has added TOS restrictions for enterprise users and certain environments, must be manually accepted.
# Execute the following commands before creating virtual environment:
conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/main
conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/r

# 1. Create environment named freqtrade with Python 3.11
conda create -n freqtrade python=3.11 -y

# Output example:
# Collecting package metadata (current_repodata.json): done
# Solving environment: done
# ...
# Preparing transaction: done
# Executing transaction: done

# 2. Activate environment
conda activate freqtrade

# Command prompt will change to:
# (freqtrade) user@computer:~$

# 3. Verify Python version
python --version
# Output: Python 3.11.x

# 4. Verify pip version
pip --version
# Output: pip 24.x.x from /path/to/conda/envs/freqtrade/...
Enter fullscreen mode Exit fullscreen mode

Important Concepts:

conda activate freqtrade  ← Activate environment (must run before each use)
conda deactivate          ← Exit environment
conda env list            ← List all environments
Enter fullscreen mode Exit fullscreen mode

πŸ“¦ Part 3: Installing Freqtrade

2.5 Install Freqtrade using pip

# Ensure freqtrade environment is activated
conda activate freqtrade

# Method 1: Install stable version (recommended for beginners)
pip install freqtrade

# Method 2: Install version with plot functionality (recommended)
pip install freqtrade[plot]

# Method 3: Install complete version (includes all optional features)
pip install freqtrade[all]

# Installation takes 5-10 minutes, please be patient...
Enter fullscreen mode Exit fullscreen mode

Installation Process Explanation:

Collecting freqtrade
  Downloading freqtrade-2025.9-py3-none-any.whl
Collecting ccxt>=4.0.0
  Downloading ccxt-4.5.6-py2.py3-none-any.whl
Collecting pandas>=2.2.0
  Downloading pandas-2.3.0-cp311-cp311-macosx_11_0_arm64.whl
...
Installing collected packages: ...
Successfully installed freqtrade-2025.9 ...
Enter fullscreen mode Exit fullscreen mode

2.6 Verify Freqtrade Installation

# 1. Check version
freqtrade --version
# Output: freqtrade 2025.9

# 2. View help information
freqtrade --help
# Output: Shows all available commands

# 3. Test import
python -c "import freqtrade; print('Freqtrade installed successfully!')"
# Output: Freqtrade installed successfully!
Enter fullscreen mode Exit fullscreen mode

If errors occur, see the Troubleshooting section at the end.


πŸ“ Part 4: Creating Project Directory

2.7 Initialize Freqtrade Project

# 1. Create project directory
mkdir ~/freqtrade-bot
cd ~/freqtrade-bot

# 2. Create necessary subdirectories
freqtrade create-userdir --userdir user_data

# Output:
# Created user-data directory: /path/to/freqtrade-bot/user_data
# Created strategies directory: /path/to/freqtrade-bot/user_data/strategies
# Created hyperopts directory: /path/to/freqtrade-bot/user_data/hyperopts

# 3. View directory structure
tree user_data -L 2

# Output:
# user_data/
# β”œβ”€β”€ backtest_results/
# β”œβ”€β”€ data/
# β”œβ”€β”€ hyperopts/
# β”œβ”€β”€ logs/
# β”œβ”€β”€ notebooks/
# β”œβ”€β”€ plot/
# └── strategies/
Enter fullscreen mode Exit fullscreen mode

Directory Explanation:

Directory Purpose
strategies/ Store trading strategy files
data/ Store downloaded historical data
backtest_results/ Store backtest results
logs/ Store log files
hyperopts/ Store parameter optimization configurations
plot/ Store generated charts

βš™οΈ Part 5: Configuring config.json

2.8 Create Configuration File

# 1. Generate sample configuration file
freqtrade new-config --config config.json

# System will ask a series of questions, recommended settings:
Enter fullscreen mode Exit fullscreen mode

Interactive Configuration (Recommended Settings):

? Do you want to use Dry-run (simulated trades)?
  Select: Yes  ← Simulated trading mode

? Please insert your stake currency:
  Input: USDT  ← Use USDT as pricing currency

? Please insert your stake amount (Number or 'unlimited'):
  Input: 100  ← 100 USDT per trade

? Please insert max_open_trades (Integer or 'unlimited'):
  Input: 3  ← Maximum 3 open positions

? Time Have your strategy define timeframe
  Input: 5m  ← Use 5-minute timeframe

? Please insert your display currency:
  Input: USD  ← Display in USD

? Select exchange
  Select: binance  ← Select Binance exchange

? Do you want to trade Futures?
  Select: No  ← Not trading futures for now

? Do you want to enable Telegram?
  Select: No  ← Not configuring Telegram for now

? Do you want to enable the REST API?
  Select: No  ← Not enabling API for now

? Do you want to enable the Plot dataframe
  Select: Yes  ← Enable charting functionality
Enter fullscreen mode Exit fullscreen mode

2.9 Understanding config.json

Generated configuration file example:

{
    "max_open_trades": 3,
    "stake_currency": "USDT",
    "stake_amount": 100,
    "tradable_balance_ratio": 0.99,
    "fiat_display_currency": "USD",
    "timeframe": "5m",
    "dry_run": true,
    "dry_run_wallet": 1000,
    "cancel_open_orders_on_exit": false,
    "unfilledtimeout": {
        "entry": 10,
        "exit": 10,
        "exit_timeout_count": 0,
        "unit": "minutes"
    },
    "entry_pricing": {
        "price_side": "same",
        "use_order_book": true,
        "order_book_top": 1,
        "price_last_balance": 0.0,
        "check_depth_of_market": {
            "enabled": false,
            "bids_to_ask_delta": 1
        }
    },
    "exit_pricing":{
        "price_side": "same",
        "use_order_book": true,
        "order_book_top": 1
    },
    "exchange": {
        "name": "binance",
        "key": "",
        "secret": "",
        "ccxt_config": {},
        "ccxt_async_config": {},
        "pair_whitelist": [
            "BTC/USDT",
            "ETH/USDT",
            "BNB/USDT"
        ],
        "pair_blacklist": [
            "BNB/.*"
        ]
    },
    "pairlists": [
        {"method": "StaticPairList"}
    ],
    "telegram": {
        "enabled": false,
        "token": "",
        "chat_id": ""
    },
    "api_server": {
        "enabled": false,
        "listen_ip_address": "127.0.0.1",
        "listen_port": 8080,
        "username": "freqtrader",
        "password": "SuperSecretPassword"
    },
    "bot_name": "freqtrade",
    "initial_state": "running",
    "force_entry_enable": false,
    "internals": {
        "process_throttle_secs": 5
    }
}
Enter fullscreen mode Exit fullscreen mode

Core Parameter Explanation:

Parameter Description Example Value
dry_run Simulated trading mode true
stake_currency Pricing currency "USDT"
stake_amount Amount per trade 100
max_open_trades Maximum open positions 3
timeframe Timeframe "5m"
pair_whitelist Allowed trading pairs ["BTC/USDT"]

πŸ“„ For detailed explanation: CONFIG_EXPLANATION.md


2.10 Modify Configuration File (Optional)

If you need to modify configuration, you can directly edit config.json:

# macOS/Linux
nano config.json
# or
vim config.json

# Windows
notepad config.json
Enter fullscreen mode Exit fullscreen mode

Recommended Modifications:

  1. Add more trading pairs:
"pair_whitelist": [
    "BTC/USDT",
    "ETH/USDT",
    "BNB/USDT",
    "SOL/USDT",  ← Added
    "XRP/USDT"   ← Added
]
Enter fullscreen mode Exit fullscreen mode
  1. Adjust initial funds (Dry-run only):
"dry_run_wallet": 1000  ← Change to 10000 (simulate 10000 USDT)
Enter fullscreen mode Exit fullscreen mode
  1. Modify trade amount:
"stake_amount": 100  ← Change to 50 or 200
Enter fullscreen mode Exit fullscreen mode

πŸ§ͺ Part 6: Verifying Environment

2.11 Run First Command

# 1. Activate environment (if not already activated)
conda activate freqtrade

# 2. Enter project directory
cd ~/freqtrade-bot

# 3. List all available strategies
freqtrade list-strategies -c config.json

# Expected output (might show no strategies):
# No strategies found. Please make sure the strategy directory exists.
# This is normal because we haven't added strategies yet
Enter fullscreen mode Exit fullscreen mode

2.12 Download Sample Strategy

# 1. Download official strategy repository
cd user_data/strategies
wget https://raw.githubusercontent.com/freqtrade/freqtrade-strategies/main/user_data/strategies/Strategy001.py

# Or manually download and place in user_data/strategies/ directory

# 2. Return to project root directory
cd ~/freqtrade-bot

# 3. List strategies again
freqtrade list-strategies -c config.json

# Expected output:
# ┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
# ┃ Strategy    ┃ Location         ┃ Status     ┃ Hyperoptable ┃
# ┑━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━┩
# β”‚ Strategy001 β”‚ Strategy001.py   β”‚ OK         β”‚ No           β”‚
# β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Enter fullscreen mode Exit fullscreen mode

2.13 Test Data Download

# Download BTC/USDT recent 7 days of 5-minute data
freqtrade download-data \
  -c config.json \
  --days 7 \
  --timeframes 5m

# Expected output:
# 2025-09-30 10:00:00 - freqtrade - INFO - Using data directory: user_data/data/binance
# 2025-09-30 10:00:01 - freqtrade - INFO - Downloading data for BTC/USDT, 5m...
# 2025-09-30 10:00:05 - freqtrade - INFO - Downloaded data for BTC/USDT with length 2016
Enter fullscreen mode Exit fullscreen mode

Verify Data Download Success:

# View downloaded data files
ls -lh user_data/data/binance/

# Output example:
# -rw-r--r-- 1 user group 1.2M Sep 30 10:00 BTC_USDT-5m.json
# -rw-r--r-- 1 user group 800K Sep 30 10:00 ETH_USDT-5m.json
Enter fullscreen mode Exit fullscreen mode

2.14 Run Quick Backtest

# Backtest Strategy001 (recent 7 days)
freqtrade backtesting \
  -c config.json \
  --strategy Strategy001 \
  --timerange 20250924-20250930

# If you see the backtest report table, environment setup is successful!
Enter fullscreen mode Exit fullscreen mode

βœ… Environment Verification Checklist

Please ensure all of the following can be executed successfully:

# 1. Conda version check
conda --version
# βœ… Should show: conda 24.x.x

# 2. Python version check
conda activate freqtrade
python --version
# βœ… Should show: Python 3.11.x

# 3. Freqtrade version check
freqtrade --version
# βœ… Should show: freqtrade 2025.9

# 4. Strategy list check
freqtrade list-strategies -c config.json
# βœ… Should show at least 1 strategy

# 5. Data directory check
ls user_data/data/binance/
# βœ… Should show at least 1 .json file

# 6. Configuration file check
cat config.json | grep "dry_run"
# βœ… Should show: "dry_run": true
Enter fullscreen mode Exit fullscreen mode

All passed? Congratulations, environment setup successful! πŸŽ‰


πŸ› Troubleshooting

Problem 1: conda: command not found

Cause: Conda not added to PATH or terminal configuration not reloaded

Solution:

# Method 1: Reload configuration
source ~/.bashrc  # Linux
source ~/.zshrc   # macOS (zsh)
source ~/.bash_profile  # macOS (bash)

# Method 2: Manually add PATH
export PATH="$HOME/miniconda3/bin:$PATH"

# Method 3: Restart terminal
Enter fullscreen mode Exit fullscreen mode

Problem 2: pip install very slow

Cause: Slow network connection or using foreign mirrors

Solution:

# Use Tsinghua mirror to speed up
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple freqtrade

# Or permanently configure mirror
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
Enter fullscreen mode Exit fullscreen mode

Problem 3: No module named 'talib'

Cause: TA-Lib library not properly installed

Solution:

# macOS
brew install ta-lib
pip install TA-Lib

# Ubuntu/Debian
sudo apt-get install libta-lib0-dev
pip install TA-Lib

# Windows
pip install TA-Lib-binary
Enter fullscreen mode Exit fullscreen mode

Problem 4: Data download failed

Error Message:

ERROR - ccxt.RequestTimeout: binance GET https://api.binance.com/api/v3/klines
Enter fullscreen mode Exit fullscreen mode

Solution:

# 1. Check network connection
ping api.binance.com

# 2. Check if rate limited
# Wait 1 minute and retry

# 3. Use proxy (if needed)
export HTTP_PROXY=http://127.0.0.1:7890
export HTTPS_PROXY=http://127.0.0.1:7890

# 4. Switch exchange
# Edit config.json, change to "name": "okx"
Enter fullscreen mode Exit fullscreen mode

Problem 5: Backtest error "No data found"

Cause: Data not downloaded or time range mismatch

Solution:

# 1. Check if data exists
freqtrade list-data -c config.json

# 2. Re-download data
freqtrade download-data -c config.json --days 30

# 3. Check time range
# Ensure --timerange is within downloaded data range
Enter fullscreen mode Exit fullscreen mode

πŸ“ Homework Assignments

Assignment 1: Environment Setup (Required)

Objective: Complete Freqtrade environment setup

Steps:

  • [ ] Install Miniconda
  • [ ] Create freqtrade virtual environment
  • [ ] Install Freqtrade 2025.9+
  • [ ] Create project directory
  • [ ] Configure config.json
  • [ ] Download sample strategy
  • [ ] Download test data
  • [ ] Run test backtest

Verification:

# Run complete verification script
bash verify_setup.sh  # See below
Enter fullscreen mode Exit fullscreen mode

Assignment 2: Create Verification Script (Recommended)

Create a verification script for convenient environment checking later:

# Create verification script
cat > verify_setup.sh << 'EOF'
#!/bin/bash

echo "=== Freqtrade Environment Verification ==="
echo ""

echo "1. Checking Conda..."
conda --version && echo "βœ… Conda OK" || echo "❌ Conda not installed"

echo ""
echo "2. Checking Python..."
conda activate freqtrade
python --version && echo "βœ… Python OK" || echo "❌ Python version error"

echo ""
echo "3. Checking Freqtrade..."
freqtrade --version && echo "βœ… Freqtrade OK" || echo "❌ Freqtrade not installed"

echo ""
echo "4. Checking configuration file..."
test -f config.json && echo "βœ… Configuration file exists" || echo "❌ Configuration file not found"

echo ""
echo "5. Checking strategies..."
freqtrade list-strategies -c config.json > /dev/null 2>&1 && \
  echo "βœ… Strategy loading OK" || echo "❌ Strategy loading failed"

echo ""
echo "6. Checking data..."
test -d user_data/data && \
  echo "βœ… Data directory exists" || echo "❌ Data directory not found"

echo ""
echo "=== Verification Complete ==="
EOF

# Add execute permission
chmod +x verify_setup.sh

# Run verification
./verify_setup.sh
Enter fullscreen mode Exit fullscreen mode

Assignment 3: Familiarize with Commands (Recommended)

Objective: Get familiar with basic Freqtrade commands

# 1. View all available commands
freqtrade --help

# 2. View help for specific commands
freqtrade backtesting --help
freqtrade download-data --help

# 3. List supported exchanges
freqtrade list-exchanges

# 4. List supported timeframes
freqtrade list-timeframes --exchange binance

# 5. View configuration
freqtrade show-config -c config.json
Enter fullscreen mode Exit fullscreen mode

Record: Organize commonly used commands in your notes.


Assignment 4: Personalized Configuration (Optional)

Objective: Adjust configuration according to personal needs

  1. Modify trading pair list

    • Add coins you're interested in
    • Recommend 3-10 trading pairs
  2. Adjust fund settings

    • Modify dry_run_wallet
    • Modify stake_amount
  3. Choose exchange

    • If in China, OKX might be more stable
    • Modify exchange.name

πŸŽ“ Post-Class Quiz

Multiple Choice

  1. What is the main purpose of Conda?

    • A. Download data
    • B. Manage Python environments
    • C. Execute trades
    • D. Generate strategies
  2. What does conda activate freqtrade do?

    • A. Install Freqtrade
    • B. Activate freqtrade environment
    • C. Run backtest
    • D. Download data
  3. What does dry_run: true mean?

    • A. Live trading
    • B. Simulated trading
    • C. Download data
    • D. Backtesting
  4. What does stake_amount: 100 mean?

    • A. Total funds 100
    • B. 100 per trade
    • C. Maximum loss 100
    • D. Trading fee 100
  5. Which command verifies the environment is correct?

    • A. conda install freqtrade
    • B. freqtrade --version
    • C. python --version
    • D. All of the above

Practical Questions

  1. How to check the currently activated Conda environment?
   Command: __________
Enter fullscreen mode Exit fullscreen mode
  1. How to list all available strategies?
   Command: __________
Enter fullscreen mode Exit fullscreen mode
  1. How to download recent 30 days of 1-hour data?
   Command: __________
Enter fullscreen mode Exit fullscreen mode

Answers at the end ⬇️


βœ… Learning Checklist

Before proceeding to Lesson 3, ensure you have:

  • [ ] Successfully installed Miniconda
  • [ ] Created and activated freqtrade environment
  • [ ] Installed Freqtrade 2025.9+
  • [ ] Created project directory structure
  • [ ] Configured config.json file
  • [ ] Downloaded at least 1 sample strategy
  • [ ] Successfully downloaded test data
  • [ ] Run first backtest
  • [ ] All verification items passed
  • [ ] Understood core configuration parameters

If you have any questions, please refer to the Troubleshooting section or ask in the community.


🎯 Next Lesson Preview

Lesson 3: Understanding Core Concepts

In Lesson 3, we will:

  • Deep dive into trading strategy structure
  • Learn common technical indicators (EMA, RSI, MACD)
  • Read and understand Strategy001 source code
  • Understand buy/sell signal generation logic
  • Master stop-loss and take-profit settings

Preparation:

  • Ensure environment setup is complete
  • Install a code editor (VS Code recommended)
  • Prepare 1-2 hours of study time

πŸ“Œ Quiz Answers

  1. B - Manage Python environments
  2. B - Activate freqtrade environment
  3. B - Simulated trading
  4. B - 100 per trade
  5. D - All of the above
  6. conda env list or conda info --envs
  7. freqtrade list-strategies -c config.json
  8. freqtrade download-data -c config.json --days 30 --timeframes 1h

πŸ’¬ Post-Class Discussion

Discussion Topics

  1. What problems did you encounter during environment setup?

    • Share your solutions
    • Help other classmates
  2. Which trading pairs did you choose?

    • Why did you choose these coins?
    • Share your strategy ideas
  3. Conda vs Docker

    • Which do you prefer?
    • What are the pros and cons of each?

Welcome to discuss in the community #course-discussion channel!


Congratulations on completing Lesson 2! Environment is set up, ready to learn strategy core concepts? πŸš€


πŸ“ Course Feedback: If any part of this lesson is unclear, feel free to provide suggestions!

Top comments (0)