Learn how to extract data, analyze, and decide on stocks in the market using Django, Celery, TimescaleDB, Jupyter, OpenAI, and more.
Thanks to Timescale for partnering with me on this tutorial.
Tech Stack
- Python 3.12
- Django (
pip install "Django>=5.1,<5.2") - TimescaleDB Cloud (or Docker version)
- Django Timescaledb (
pip install django-timescaledb) - Python requests (
pip install requests) - Jupyter (
pip install jupyter) - Psycopg Binary Release (
pip install "psycopg[binary]") - Python Decouple to load environment variables (e.g.
.env) with type casting and default values. - Polygon.io (docs)
- Alpha Vantage (docs)
- OpenAI
- In-depth setup on YouTube (https://youtu.be/aApDye1TWJ4)
- Django Setup for use in Jupyter Notebooks (short + code)
- Full tutorial on YouTube (https://youtu.be/O3O1z5hTdUM)
Download the following:
- git
- VSCode (or Cursor)
- Docker Desktop or Docker Engine via get.docker.com (Linux Install Script)
- Python
Open a command line (Terminal, VSCode Terminal, Cursor Terminal, Powershell, etc)
Clone this Repo
mkdir -p ~/dev/stock-trading-bot
cd ~/dev/stock-trading-bot
git clone https://github.com/codingforentrepreneurs/Stock-Trading-Bot .Checkout the start branch
git checkout start
rm -rf .git
git init
git add --all
git commit -m "It's my bot now"Create a Python vitual environment macOS/Linux/WSL
python3.12 -m venv venv
source venv/bin/activatewindows powershell
c:\Path\To\Python312\python.exe -m venv venv
.\venv\Scripts\activateInstall requirements
(venv) python -m pip install -r requirements.txtDocker Compose Up (for local TimescaleDB and Redis)
docker compose -f compose.yaml up -dIf you don't have Docker, use TimescaleDB Cloud and Upstash Redis
Create .env in project root
mkdir -p ~/dev/stock-trading-bot
echo "" >> .envAdd DATABASE_URL and REDIS_URL to .env (these are based on the compose.yaml file):
DATABASE_URL="postgresql://postgres:postgres@localhost:5431/postgres"
REDIS_URL="redis://localhost:6378"