A free-tier event-driven ETL pipeline that ingests news events and market data, aligns them by timestamp, and analyzes how crypto (BTC), oil, and gold react to breaking news.
This project correlates news events with price movements to detect:
- Sudden price moves after relevant news
- Measurable returns following market-moving events
- Asset reaction comparisons (which asset reacts most to the same news)
- Abnormal spikes compared to normal volatility patterns
-
Did a sudden price move happen after relevant news?
- Example: Iran/war news β oil spikes after
-
How much did the asset move after the news?
- Example: BTC moves +2% in 1 hour after a headline
-
Which asset reacted the most to the same news?
- Example: oil +3%, gold +1%, BTC -0.5%
-
Was the move abnormal?
- Example: oil jumps above its normal volatility range after news
- Binance WebSocket API β real-time streaming data
- Binance REST API β historical/batch data
- Primary asset: Bitcoin (BTC)
- Documentation: Binance API Docs
- Yahoo Finance (yfinance) β batch ingestion
- Assets: Oil (Crude) & Gold
- Documentation: yfinance Docs
- GDELT 2.0 β near-real-time news ingestion
- Documentation: GDELT 2.0 API
| Component | Technology | Purpose |
|---|---|---|
| Data Ingestion | Python (requests, python-binance) | Batch & real-time API polling |
| Streaming | Apache Kafka | Event streaming for real-time market data |
| Transformation | Apache Spark (PySpark) | Distributed data processing & analysis |
| Data Lake | MinIO (S3-compatible) | Raw & processed data storage (Bronze/Silver/Gold layers) |
| Database | Neon PostgreSQL | Analytical tables & metadata |
| Orchestration | Prefect | Workflow scheduling & monitoring |
| Visualization | Streamlit | Interactive dashboards & insights |
| Containerization | Docker & Docker Compose | Multi-service deployment |
| Monitoring | Grafana | Metrics & observability |
data_engineering/
βββ db/ # Database layer
β βββ schemas/ # SQLAlchemy ORM models
β β βββ dim_asset.py # Asset dimension table (BTC, Oil, Gold)
β β βββ dim_news.py # News dimension table (headlines, sources)
β β βββ fact_news_market.py # Fact table linking news & prices
β β βββ pipeline_run.py # Pipeline execution metadata
β β βββ task.py # Task execution tracking
β βββ config_db.py # Database configuration
β βββ init_db.py # Schema initialization
β βββ session_db.py # SQLAlchemy session management
β βββ base_db.py # Base database classes
β
βββ ingestion/ # Batch ingestion layer
β βββ ingestion.py # Main ingestion orchestration
β βββ sources/ # Individual data source clients
β βββ binance_client/ # Binance REST API client (BTC prices)
β βββ news_client/ # GDELT news client
β βββ yfinance_client/ # Yahoo Finance client (Oil, Gold)
β
βββ streaming/ # Real-time streaming layer
β βββ config/
β β βββ configuration.py # Kafka & streaming config
β βββ streaming/
β βββ producer.py # Kafka producer (publish market events)
β βββ consumer.py # Kafka consumer (subscribe to streams)
β
βββ spark/ # PySpark transformations (core processing)
β βββ jobs/ # Spark job scripts
β β βββ bitcoin.py # BTC analysis job
β β βββ gold.py # Gold analysis job
β β βββ news.py # News processing job
β β βββ oil.py # Oil analysis job
β β βββ bronze_to_silver/ # Raw β Cleaned data transformation
β β βββ crypto/stream.py
β βββ transformation/ # Spark utilities
β βββ utils.py # Spark utility functions
β βββ silver_to_gold/ # Cleaned β Analytics transformation
β βββ aggregate.py # Aggregations & correlations
β
βββ pipeline/ # Pipeline orchestration (Prefect)
β βββ main_flow.py # Master Prefect flow
β βββ pipeline_per_source.py # Per-source pipeline definitions
β
βββ load/ # Data loading layer
β βββ load.py # Load transformations into Neon DB
β
βββ transformation/ # Additional ETL utilities
β βββ transformation.py # Data transformation helpers
β
βββ utils/ # Utility modules
β βββ minio_client/ # MinIO S3 client wrapper
β βββ time_client/ # Timestamp & time utilities
β
βββ docker/ # Docker image definitions
β βββ base/ # Base image with dependencies
β βββ client/ # Client-side container
β βββ master/ # Prefect Master scheduler
β βββ worker/ # Prefect Worker executor
β βββ streamlit/ # Streamlit dashboard container
β βββ Dockerfile
β βββ requirements.txt
β βββ streamlit.py # Dashboard application
β
βββ grafana/ # Monitoring & observability
β βββ provisioning/ # Grafana datasources config
β βββ datasources/postgres.yaml
β
βββ minio_data/ # Local MinIO storage (S3-compatible)
β βββ raw-data/ # Bronze layer - raw ingested data
β β βββ binance/bitcoin/ (JSON files)
β β βββ news/arabic/ (JSON files)
β β βββ yfinance/oil/ & gold/
β βββ raw-data-staging/ # Temporary staging area
β βββ silver-data/ # Silver layer - cleaned data
β β βββ {source}/{asset}/ (_SUCCESS markers)
β βββ silver-data-staging/ # Temporary staging
β β βββ {source}/{asset}/
β βββ gold-data/ # Gold layer - analytics-ready data (Parquet)
β
βββ docs/ # Detailed documentation
β βββ batch-ingestion.md # Batch ingestion workflow & commands
β βββ streaming-ingestion.md # Kafka streaming setup
β βββ spark-transformation.md # Spark job details
β
βββ docker-compose.yml # Multi-service orchestration
βββ Dockerfile # Main application image
βββ requirements.txt # Python dependencies (Flask, Spark, etc.)
βββ README.md # This file
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 1. DATA INGESTION β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββββ β
β β Binance β β Yahoo Fin. β β GDELT News β β
β β REST API β β (yfinance) β β Micro-batches β β
β β (BTC prices) β β (Oil, Gold) β β (Headlines) β β
β ββββββββ¬ββββββββ ββββββββ¬ββββββββ ββββββββββ¬ββββββββββ β
β β β β β
βββββββββββΌββββββββββββββββββΌββββββββββββββββββββΌββββββββββββ
β β β
βββββββββββΌββββββββββββββββββΌββββββββββββββββββββΌββββββββββββ
β 2. STORE RAW DATA (MinIO Bronze Layer) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β βββ minio_data/raw-data/binance/bitcoin/ β
β βββ minio_data/raw-data/yfinance/oil/ & gold/ β
β βββ minio_data/raw-data/news/arabic/ β
ββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββ
β 3. SPARK TRANSFORMATION (PySpark Distributed) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β Bronze β Silver (spark/jobs/bronze_to_silver/) β
β βββ Normalize timestamps to UTC β
β βββ Parse & validate JSON β
β βββ Remove duplicates & null values β
β βββ Partition by asset & date for optimization β
β βββ Output: Parquet files to silver-data/ β
β β
β Silver β Gold (spark/transformation/silver_to_gold/) β
β βββ Calculate returns (1h, 4h, 24h windows) β
β βββ Compute volatility metrics β
β βββ Detect price spikes & anomalies β
β βββ Correlate news events with price moves β
β βββ Output: Analytics-ready Parquet to gold-data/ β
β β
ββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββ
β 4. STORE PROCESSED DATA (MinIO Silver/Gold Layers) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β βββ minio_data/silver-data/ (cleaned Parquet) β
β βββ minio_data/gold-data/ (analytics-ready Parquet) β
β β
ββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββ
β 5. LOAD INTO DATABASE (Neon PostgreSQL) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β βββ dim_asset (BTC, Oil, Gold metadata) β
β βββ dim_news (news headlines & metadata) β
β βββ fact_news_market (correlations & analysis) β
β βββ pipeline_run & task (execution tracking) β
β β
ββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββ
β 6. ORCHESTRATION & MONITORING β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β Prefect (Orchestration) β
β βββ Schedule daily/hourly jobs β
β βββ Handle retries & failures β
β βββ Track pipeline runs in DB β
β β
β Grafana (Monitoring) β
β βββ Query metrics from PostgreSQL β
β βββ Display dashboards & alerts β
β βββ Monitor Spark job performance β
β β
ββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββ
β 7. VISUALIZATION & INSIGHTS (Streamlit) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β βββ Interactive price movement charts β
β βββ News event timeline visualization β
β βββ Correlation heatmaps (news vs prices) β
β βββ Anomaly detection alerts β
β βββ Asset reaction comparison dashboard β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
The initial release includes:
- Binance REST API for BTC historical data
- Yahoo Finance for Oil & Gold periodic polling
- GDELT 2.0 for news micro-batch ingestion
- MinIO for data lake storage (Bronze/Silver/Gold layers)
- Neon PostgreSQL for analytical tables
- Streamlit dashboard for real-time insights
- PySpark for distributed data transformations
- Kafka for streaming architecture (simulated)
- Prefect for workflow orchestration
- Docker Compose for local development & deployment
- Docker & Docker Compose
- Python 3.9+
- Git
-
Clone the repository
git clone <repo-url> cd data_engineering
-
Create environment file (
.env)# Neon Database DATABASE_URL=postgresql://user:password@neon-host/dbname # MinIO MINIO_ROOT_USER=minioadmin MINIO_ROOT_PASSWORD=minioadmin MINIO_ENDPOINT=http://minio:9000 # Binance API BINANCE_API_KEY=your_key BINANCE_API_SECRET=your_secret # Prefect PREFECT_API_URL=http://prefect:4200/api -
Start all services
docker-compose up -d
-
Initialize database
docker-compose exec master python -m db.init_db -
Run first ingestion
docker-compose exec master python -m ingestion.ingestion -
Run Spark transformations
docker-compose exec master python -m spark.jobs.bitcoin -
View Streamlit dashboard
http://localhost:8501
dim_asset
βββ asset_id (PK)
βββ asset_name (BTC, Oil, Gold)
βββ asset_type (Crypto, Commodity)
βββ created_atdim_news
βββ news_id (PK)
βββ headline
βββ source
βββ language
βββ published_at
βββ gdelt_event_codefact_news_market
βββ fact_id (PK)
βββ asset_id (FK)
βββ news_id (FK)
βββ price_before
βββ price_after
βββ price_change_pct
βββ returns_1h, 4h, 24h
βββ volatility_metric
βββ is_anomaly
βββ event_window (seconds after news)
βββ created_atraw-data/β Bronze layer (raw JSON/CSV from APIs)silver-data/β Silver layer (cleaned Parquet, deduplicated)gold-data/β Gold layer (analytics-ready, aggregated)
- Multi-region support (default: US-East)
- Autoscaling enabled for query spikes
- Database branching for team collaboration
binance-btc-tradesβ Real-time BTC price updatesnews-eventsβ GDELT news streammarket-alertsβ Anomaly detections
spark/jobs/ # Individual asset analysis jobs
spark/transformation/ # Shared utilities & aggregations
- Batch: Run via Prefect on schedule (daily/hourly)
- Streaming: Consume from Kafka topics in real-time
- Partitioning: By asset & date for optimized queries
- Format: Parquet for efficient compression & columnar reads
- Caching: In-memory caching for frequently accessed datasets
- Shuffle Optimization: Coalesce partitions before writes
- Prefect Dashboard β Workflow monitoring (http://localhost:4200)
- Grafana β Metrics & alerts (http://localhost:3000)
- PostgreSQL β Query logs & execution plans
- MinIO Console β Data lake browser (http://localhost:9001)
- Create client in
sources/<source_name>/ - Add ORM schema to
db/schemas/ - Define ingestion task in
pipeline/pipeline_per_source.py - Add Spark transformation job in
spark/jobs/ - Update Prefect flow in
pipeline/main_flow.py
- Spark: Partitioned by asset & date for optimized queries
- Database: Indexes on (asset_id, timestamp) for fast lookups
- MinIO: Parquet format for 80% compression & columnar efficiency
- Kafka: 3 replicas for high availability & fault tolerance
- Caching: Spark RDD caching for repeated transformations
- All API credentials stored in
.env(never commit!) - PostgreSQL password rotation recommended monthly
- MinIO enabled with IAM policies per service
- Docker secrets for production deployments
- VPC isolation for cloud deployments
For questions or issues:
- Check existing GitHub Issues
Last Updated: April 28, 2026
Version: 0.1.0 (MVP)