Database Design
Overview
TradeEntry uses PostgreSQL 14+ as its primary database.
Core Tables
scr_nseeq_eod — NSE Equity EOD
Stores daily OHLCV data for all NSE-listed equities.
| Column | Type | Description |
|---|---|---|
sdate | DATE | Trading date |
symbol | VARCHAR | NSE symbol (e.g., RELIANCE) |
open | NUMERIC | Open price |
high | NUMERIC | High price |
low | NUMERIC | Low price |
close | NUMERIC | Close price |
volume | BIGINT | Volume (shares traded) |
delivery_qty | BIGINT | Delivery quantity |
delivery_pct | NUMERIC | Delivery percentage |
Primary Key: (sdate, symbol)
Index: sdate for range queries
scr_nsefo_eod — NSE F&O EOD
Stores daily OHLCV and OI data for all NSE F&O contracts.
| Column | Type | Description |
|---|---|---|
sdate | DATE | Trading date |
symbol | VARCHAR | Underlying symbol |
expiry_date | DATE | Contract expiry date |
option_type | CHAR(2) | CE, PE, or XX (futures) |
strike_price | NUMERIC | Strike price (0 for futures) |
open | NUMERIC | Open price |
high | NUMERIC | High price |
low | NUMERIC | Low price |
close | NUMERIC | Close price |
volume | BIGINT | Volume (contracts) |
open_interest | BIGINT | Open interest |
Primary Key: (sdate, symbol, expiry_date, option_type, strike_price)
scr_indexpepb — Index PE/PB Ratios
| Column | Type | Description |
|---|---|---|
sdate | DATE | Date |
index_name | VARCHAR | Index name |
pe | NUMERIC | Price-to-Earnings ratio |
pb | NUMERIC | Price-to-Book ratio |
div_yield | NUMERIC | Dividend yield |
scr_missing_bhav / scr_missing_eod
Internal tracking tables for missing or failed bhav copy downloads.
Rollback Strategy
The deleteadateabove(mdate) function removes all rows with sdate > mdate from all core tables, allowing a safe rollback to any clean baseline:
DELETE FROM scr_nseeq_eod WHERE sdate > '2025-01-10';
DELETE FROM scr_nsefo_eod WHERE sdate > '2025-01-10';
DELETE FROM scr_indexpepb WHERE sdate > '2025-01-10';
DELETE FROM scr_missing_bhav WHERE sdate > '2025-01-10';
DELETE FROM scr_missing_eod WHERE sdate > '2025-01-10';