Environment setup: venv, SDK install

Isolate this project's dependencies from your system Python.

mkdir -p ~/algo-trading-bot && cd ~/algo-trading-bot
python3 -m venv .venv
source .venv/bin/activate        # Windows: .venv\Scripts\activate

pip install --upgrade pip
pip install kiteconnect python-dotenv pandas numpy requests
  • kiteconnect — official Zerodha SDK (REST + WebSocket ticker).
  • python-dotenv — loads secrets from a .env file (chapter 6).
  • pandas/numpy — for handling candle data later.
  • requests — used internally, occasionally directly for endpoints the SDK doesn't wrap.

Broker equivalents

pip install upstox-python-sdk      # Upstox
pip install fyers-apiv3            # Fyers
pip install dhanhq                 # Dhan

Verify the install

# check_setup.py
import kiteconnect
print("kiteconnect version:", kiteconnect.__version__)
python check_setup.py

If this prints a version string without error, you're set.

Project layout used for the rest of this course

algo-trading-bot/
├── .env                  # secrets, never committed
├── .gitignore            # must include .env, *.db, tokens/
├── config.py             # loads .env into constants
├── auth/
│   └── session.py        # login/token handling (ch 7-10)
├── data/
│   ├── instruments.py    # instrument master (ch 21-23)
│   └── historical.py     # candles (ch 27-30)
├── orders/
│   └── manager.py        # order placement/tracking (ch 43-68)
├── strategy/
│   └── ...               # ch 79+
└── main.py

Create it now, even empty — later chapters assume these paths exist.

mkdir -p auth data orders strategy
touch .env .gitignore config.py auth/session.py main.py
echo -e ".env\n*.db\ntokens/\n__pycache__/\n.venv/" >> .gitignore

Next: 006 — Store credentials securely