32 - Master Contract Download
Overview
Architecture Diagram
┌──────────────────────────────────────────────────────────────────────────────┐
│ Master Contract Download Architecture │
└──────────────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────────────────┐
│ Download Trigger │
│ │
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
│ │ On Broker │ │ Manual │ │ Daily │ │
│ │ Login │ │ Trigger │ │ Scheduled │ │
│ └────────┬────────┘ └────────┬────────┘ └────────┬────────┘ │
│ │ │ │ │
│ └────────────────────┼────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ Async Download Task │ │
│ │ (Background Thread) │ │
│ └─────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ Broker-Specific Download │
│ │
│ broker/{name}/database/master_contract_db.py │
│ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ 1. Fetch from broker API or static URL │ │
│ │ 2. Parse CSV/JSON format │ │
│ │ 3. Transform to OpenAlgo format │ │
│ │ 4. Store in symtoken table │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────────────────┐
│ Symbol Database │
│ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ symtoken table │ │
│ │ │ │
│ │ symbol │ exchange │ token │ lotsize │ tick_size │ ... │ │
│ │ ────────────────────────────────────────────────────────────────── │ │
│ │ SBIN │ NSE │ 779 │ 1 │ 0.05 │ │ │
│ │ NIFTY │ NFO │ 256265 │ 65 │ 0.05 │ │ │
│ │ BANKNIFTY │ NFO │ 260105 │ 30 │ 0.05 │ │ │
│ └─────────────────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────────────────┘Download Process
1. Trigger on Broker Login
2. Background Download
3. Broker-Specific Download
Symbol Database Schema
symtoken Table
Symbol Mapping
OpenAlgo to Broker
Get Token
Get Symbol Info
Broker Implementations
Zerodha
Dhan
Angel One
Caching Strategy
In-Memory Cache
Database Index
Status Tracking
master_contract_status Table
Stuck Download Detection
Error Handling
Download Failures
Fallback to Cache
Daily Refresh
Scheduled Update
Key Files Reference
File
Purpose
Last updated