Skip to content

About

Real-time stock data pipeline with Kafka streaming, Airflow orchestration, and TimescaleDB star-schema warehouse tracking 10 major tickers

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

106 Commits

Folders and files

Repository files navigation

CI Python Kafka Airflow TimescaleDB Docker License: MIT

Stock Data Platform

End-to-end data engineering pipeline that ingests, transforms, and warehouses real-time stock market data — built to demonstrate production-grade streaming, orchestration, and dimensional modeling.

View Live Site · Interactive Dashboard


What It Does

Tracks the full price history of 10 major US equities (AAPL, AMZN, GOOG, META, MSFT, NFLX, NVDA, TSLA, JPM, DIS) through a fully containerized pipeline:

  • Streams live market data via Kafka (producer → broker → consumer)
  • Orchestrates 23 Airflow DAGs for ETL, fundamentals, earnings, SEC filings, and macro data
  • Warehouses everything in a TimescaleDB star schema (3 dimension + 7 fact tables)
  • Visualizes results on a Bloomberg Terminal-style dashboard with Chart.js

Data Sources

Source Data Method
yfinance Prices, company info, earnings Python API
SEC EDGAR 10-K/10-Q financial statements EdgarTools
FRED Fed funds rate, CPI, GDP, unemployment fredapi
Alpaca Hourly price bars back to 2016 (free paper-trading account) REST API

Live Demo

Explore the platform's output — no setup required:

Landing Page Dashboard

The landing page features a Bloomberg-style ticker tape and architecture overview. The dashboard displays interactive charts for price trends, fundamentals, earnings surprises, and macro indicators.


Architecture

Architecture Diagram

7 Docker containers work together:

Service Image Port Role
timescaledb timescale/timescaledb:latest-pg14 5434 Star-schema warehouse
airflow-webserver Custom (Dockerfile.airflow) 8081 DAG monitoring UI
airflow-scheduler Custom (Dockerfile.airflow) — DAG execution engine
zookeeper confluentinc/cp-zookeeper 2181 Kafka coordination
kafka confluentinc/cp-kafka 9092 Message broker
kafka-producer Custom (Dockerfile.kafka) — Market data ingestion
kafka-consumer Custom (Dockerfile.kafka) — Kafka → TimescaleDB sink

Data Model (Star Schema)

Table Type Description
dim_company Dimension Ticker, company name, sector, industry, exchange (SCD Type 2)
dim_date Dimension Year, quarter, month, day, weekend flag
dim_macro_indicator Dimension FRED macro series metadata
fact_stock_price_daily Fact OHLCV data per ticker per day, back to each ticker's first traded day
fact_stock_price_intraday Fact Hourly regular-session OHLCV bars back to 2016, labelled by bar_interval and source
fact_stock_price_monthly Fact Aggregated monthly averages and total volume
fact_company_fundamentals Fact Market cap, PE ratios, dividends, beta
fact_earnings Fact Quarterly EPS: estimate vs actual, surprise %
fact_sec_financials Fact SEC filing line items, keyed on the full reporting period so quarterly and year-to-date figures stay distinct
fact_macro_data Fact Fed funds rate, CPI, unemployment, GDP time series

Built on TimescaleDB for time-series optimized queries on PostgreSQL 14.


Airflow DAGs

DAG Schedule Purpose
etl_stock_data_<ticker> Daily Per-ticker ETL (one DAG per ticker); first run loads the ticker's full history
populate_dim_company On-demand Load company dimension table
populate_dim_date On-demand Generate date dimension (1990-2035)
fundamentals_daily Daily Fetch company fundamentals
earnings_weekly Weekly Fetch earnings dates and EPS surprises
sec_financials_quarterly Quarterly Fetch SEC 10-K/10-Q financial statements
macro_daily Daily Fetch FRED macro indicators
intraday_prices_daily Daily Reload hourly bars from Alpaca (skipped if no keys are set)
monthly_aggregate_dag Daily Recompute monthly price aggregations (daily, so the current month stays current)
csv_export_dag Triggered Export last 30 days to CSV per ticker
populate_fundamentals On-demand One-off fundamentals backfill
populate_earnings On-demand One-off earnings backfill
populate_sec_financials On-demand One-off SEC filings backfill
populate_macro_data On-demand One-off FRED macro backfill

That is 23 DAGs in total: 10 per-ticker ETL DAGs plus the 13 listed here.


Quickstart

Prerequisites

Setup

# Clone and configure
git clone https://github.com/jayhemnani9910/stock-data-platform.git
cd stock-data-platform
cp .env.example .env    # Fill in FRED_API_KEY, EDGAR_IDENTITY, and optionally ALPACA_API_KEY/SECRET

# Start all 7 services
docker compose up -d

# Access Airflow UI
open http://localhost:8081   # credentials from .env

# Initialize dimensions (run these DAGs first)
#   1. populate_dim_company
#   2. populate_dim_date
#   3. etl_stock_data_aapl (or any ticker DAG)

# Query the warehouse
docker exec -it timescaledb psql -U data226 -d stockdw \
  -c "SELECT * FROM fact_stock_price_daily ORDER BY date DESC LIMIT 10;"

Project Structure

├── Dags/                          # Airflow DAG definitions
│   ├── dag_config.py              # Shared DAG defaults and ticker loading
│   ├── etl_stock_data_dag.py      # Per-ticker extract → transform → load
│   ├── populate_dags.py           # Dimension and fact table population
│   ├── fundamentals_dag.py        # Daily company fundamentals
│   ├── earnings_dag.py            # Weekly earnings data
│   ├── sec_financials_dag.py      # Quarterly SEC filings
│   ├── macro_dag.py               # Daily macro indicators
│   ├── intraday_dag.py            # Daily hourly-bar refresh
│   └── monthly_aggregate_dag.py   # Monthly rollups
├── scripts/                       # Data population and utilities
│   ├── db_utils.py                # Shared DB connection, batch insert, upsert SQL
│   ├── populate_dim_company.py
│   ├── populate_dim_date.py
│   ├── populate_company_fundamentals.py
│   ├── populate_earnings.py
│   ├── populate_stock_price_intraday.py
│   ├── populate_sec_financials.py
│   └── populate_macro_data.py
├── SQL/                           # Schema and queries
│   ├── schema.sql                 # Star schema DDL (TimescaleDB)
│   ├── migrations/                # Re-runnable changes for a live volume
│   └── aggregate_monthly.sql      # Monthly rollup query
├── tests/                         # Unit tests (pytest)
│   └── unit/                      # 202 tests across 10 modules
├── site/                          # GitHub Pages (landing page + dashboard)
├── docs/                          # Architecture diagrams (D2 format)
├── kafka_to_postgres.py           # Kafka consumer → TimescaleDB
├── live_from_kafka.py             # Real-time Kafka producer
├── Dockerfile.kafka               # Kafka producer/consumer image
├── Dockerfile.airflow             # Custom Airflow image
├── docker-compose.yml             # 7-service orchestration
├── ruff.toml                      # Linter and formatter config
├── Makefile                       # Common commands (up, down, test, lint)
├── .env.example                   # Environment variable template
└── requirements.txt               # Pinned Python dependencies

Tech Stack

Layer Technology
Streaming Apache Kafka (Confluent) with Zookeeper
Orchestration Apache Airflow 2.7
Database TimescaleDB (PostgreSQL 14 + time-series extensions)
Containerization Docker Compose (7 services)
CI/CD GitHub Actions (ruff lint + pytest)
Frontend GitHub Pages + Chart.js
Language Python 3.12 locally; the Airflow image is python 3.11

Contributing

Contributions are welcome! See CONTRIBUTING.md for setup instructions and guidelines.

License

This project is licensed under the MIT License — see the LICENSE file for details.

About

Real-time stock data pipeline with Kafka streaming, Airflow orchestration, and TimescaleDB star-schema warehouse tracking 10 major tickers

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages