HomePhase 1: Python FoundationsLesson 1
Lesson 1 of 24Phase 1: Python FoundationsBeginner

Setting Up Your Bot Workspace the Right Way

Learn how to organize your Python trading bot with virtual environments, secret .env files, and a setup-checker script before writing a single trade.

Bitfoster Team
December 3, 2026
8 Min Read
lesson-01-bot-workspace/
Setting Up Your Bot Workspace the Right Way

Hands-On Deliverable

A clean starter project folder and a simple setup-checker script.

Why Your Workspace Setup Matters Before Writing Any Strategy

Most beginners jump straight into downloading an exchange library and typing code into a single file on their Desktop. Within two weeks, things start breaking: installing a package for one project silently breaks another, API keys accidentally get pasted into a public GitHub repo, and nobody remembers which script is the real bot.

Think of your bot workspace like a kitchen before you start cooking. You do not need a computer science degree to keep it clean—you just need three simple habits:

  1. A dedicated virtual environment (venv): Think of this as a private toolbox just for your trading bot. If you install a library here, it stays here and never collides with the rest of your computer.
  2. A .env file for secrets: Exchange API keys and Telegram tokens are like house keys. You never hardcode them inside your .py scripts. Instead, you store them in a hidden .env file that Git ignores.
  3. Testnet-first defaults: Until your bot has been tested thoroughly, every config should point to a Testnet (play-money sandbox) environment so a typo never costs real money.

In this lesson, you will build a clean starter folder and a check_setup.py script that verifies your entire workspace in two seconds.


Prerequisites & Folder Structure

Make sure you have Python 3.10 or newer installed. Open your terminal and create a clean project folder with its own virtual environment:

mkdir my-crypto-bot
cd my-crypto-bot

# Create a private virtual environment named .venv
python3 -m venv .venv

# Activate it (macOS / Linux)
source .venv/bin/activate

# On Windows PowerShell, run this instead:
# .venv\Scripts\Activate.ps1

# Install our starter packages
pip install python-dotenv requests pandas numpy

Organize your project folder like this:

my-crypto-bot/
├── .venv/              # Private Python packages (never commit to Git)
├── .env                # Your private Testnet keys (never commit to Git)
├── .env.example        # Safe template showing which variables are needed
├── .gitignore          # Tells Git to ignore .env and .venv
├── data/               # Downloaded price charts
├── logs/               # Bot diary / log files
└── check_setup.py      # Our Lesson 1 checkpoint script

Create a .gitignore file so your secrets and environment folder never leave your machine:

.venv/
.env
logs/
__pycache__/

Next, create a .env file with placeholder Testnet values (never paste live real-money keys while learning):

TRADING_MODE=testnet
EXCHANGE_API_KEY=your_testnet_api_key_here
EXCHANGE_API_SECRET=your_testnet_api_secret_here

Common Beginner Mistake: Installing packages globally without activating .venv first, or pasting real exchange API keys directly into bot.py. If you ever push bot.py to GitHub—even for 10 seconds—automated bots scrape public commits and can abuse leaked keys. Always keep keys in .env, add .env to .gitignore, and check that (.venv) appears at the start of your terminal prompt before running pip install.


Checkpoint Script: check_setup.py

Save the code below as check_setup.py inside your my-crypto-bot/ folder. It verifies your Python version, confirms your virtual environment is active, checks that key libraries are installed, and reads your .env file safely without printing your secret keys.

"""
Lesson 1 Checkpoint: Bot Workspace Setup Checker
Verifies Python version, active virtual environment, required libraries,
and safe Testnet-first .env configuration.
"""

import importlib
import os
import sys
from pathlib import Path
from dotenv import load_dotenv

REQUIRED_PACKAGES = ["dotenv", "requests", "pandas", "numpy"]
REQUIRED_FOLDERS = ["data", "logs"]


def check_python_version() -> bool:
    version = sys.version_info
    ok = version >= (3, 10)
    status = "PASS" if ok else "FAIL"
    print(f"[{status}] Python version: {version.major}.{version.minor}.{version.micro} (need 3.10+)")
    return ok


def check_virtual_env() -> bool:
    # sys.prefix differs from sys.base_prefix when inside a virtual environment
    in_venv = sys.prefix != sys.base_prefix
    status = "PASS" if in_venv else "WARN"
    msg = f"Active ({Path(sys.prefix).name})" if in_venv else "Not active! Run: source .venv/bin/activate"
    print(f"[{status}] Virtual environment: {msg}")
    return in_venv


def check_packages() -> bool:
    all_ok = True
    for pkg in REQUIRED_PACKAGES:
        try:
            importlib.import_module(pkg)
            print(f"[PASS] Package installed: {pkg}")
        except ImportError:
            print(f"[FAIL] Missing package: {pkg} -> run 'pip install -r requirements.txt'")
            all_ok = False
    return all_ok


def check_folders() -> bool:
    for folder in REQUIRED_FOLDERS:
        path = Path(folder)
        if not path.exists():
            path.mkdir(parents=True, exist_ok=True)
            print(f"[PASS] Created missing folder: {folder}/")
        else:
            print(f"[PASS] Folder ready: {folder}/")
    return True


def check_env_config() -> bool:
    env_path = Path(".env")
    if not env_path.exists():
        print("[FAIL] Missing .env file. Copy .env.example to .env and add Testnet placeholders.")
        return False

    load_dotenv(env_path)
    mode = os.getenv("TRADING_MODE", "unset").lower()
    api_key = os.getenv("EXCHANGE_API_KEY", "")

    if mode != "testnet":
        print(f"[WARN] TRADING_MODE is '{mode}'. Set TRADING_MODE=testnet while learning!")
    else:
        print("[PASS] Trading mode: testnet (safe sandbox default)")

    # Never print the full secret! Only confirm whether it is set.
    key_status = "configured (placeholder/testnet)" if api_key else "missing"
    print(f"[PASS] EXCHANGE_API_KEY: {key_status}")
    return bool(api_key)


def main() -> None:
    print("=" * 52)
    print("  BITFOSTER BOT WORKSPACE CHECKER (LESSON 1)")
    print("=" * 52)

    results = [
        check_python_version(),
        check_virtual_env(),
        check_packages(),
        check_folders(),
        check_env_config(),
    ]

    print("-" * 52)
    if all(results):
        print("ALL CHECKS PASSED! Your workspace is ready for Phase 1.")
    else:
        print("Some checks need attention. Fix any [FAIL] or [WARN] items above.")


if __name__ == "__main__":
    main()

Run it from your terminal:

python check_setup.py

Expected Terminal Output

====================================================
  BITFOSTER BOT WORKSPACE CHECKER (LESSON 1)
====================================================
[PASS] Python version: 3.12.4 (need 3.10+)
[PASS] Virtual environment: Active (.venv)
[PASS] Package installed: dotenv
[PASS] Package installed: requests
[PASS] Package installed: pandas
[PASS] Package installed: numpy
[PASS] Created missing folder: data/
[PASS] Created missing folder: logs/
[PASS] Trading mode: testnet (safe sandbox default)
[PASS] EXCHANGE_API_KEY: configured (placeholder/testnet)
----------------------------------------------------
ALL CHECKS PASSED! Your workspace is ready for Phase 1.

Study & Practice Recap

  • Virtual environments isolate your bot: Keeping packages inside .venv prevents dependency conflicts across projects and makes your bot reproducible.
  • Secrets belong in .env, never in code: Pair .env with .gitignore so API keys never leak into version control or screen recordings.
  • Default to Testnet: Building a TRADING_MODE=testnet check into your workspace ensures educational scripts never accidentally touch real funds.

Tiny Hands-On Exercise: Run pip freeze > requirements.txt inside your active .venv, then add a check inside check_setup.py that verifies .gitignore exists and contains .env. Re-run the script to confirm it prints [PASS] .gitignore protects .env.

Topics:#Python#Virtual Environments#Dotenv#Bot Setup#Security