Skip to main content

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.

ColumnTypeDescription
sdateDATETrading date
symbolVARCHARNSE symbol (e.g., RELIANCE)
openNUMERICOpen price
highNUMERICHigh price
lowNUMERICLow price
closeNUMERICClose price
volumeBIGINTVolume (shares traded)
delivery_qtyBIGINTDelivery quantity
delivery_pctNUMERICDelivery 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.

ColumnTypeDescription
sdateDATETrading date
symbolVARCHARUnderlying symbol
expiry_dateDATEContract expiry date
option_typeCHAR(2)CE, PE, or XX (futures)
strike_priceNUMERICStrike price (0 for futures)
openNUMERICOpen price
highNUMERICHigh price
lowNUMERICLow price
closeNUMERICClose price
volumeBIGINTVolume (contracts)
open_interestBIGINTOpen interest

Primary Key: (sdate, symbol, expiry_date, option_type, strike_price)


scr_indexpepb — Index PE/PB Ratios

ColumnTypeDescription
sdateDATEDate
index_nameVARCHARIndex name
peNUMERICPrice-to-Earnings ratio
pbNUMERICPrice-to-Book ratio
div_yieldNUMERICDividend 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';