How aabishkar2/nepse-data works
Purpose and Deliverable
This is a data-collection repository for Nepal Stock Exchange (NEPSE) historical and current trading data. Its primary product is a versioned dataset: one ascending date-wise CSV per trading symbol under data/company-wise/ (for example, data/company-wise/NMB.csv and data/company-wise/NABIL.csv).
Execution Entry Points
Scripts must run from src/ because imports are relative to that directory:
• src/discoverCompanies.py refreshes the symbol-to-company-ID registry from the live NEPSE source.
• src/allDataScrapper.py performs historical backfill only for symbols lacking a CSV.
• src/dailyDataScrapper.py incrementally updates existing company CSVs without duplicating same-day rows.
Dependencies and expected Python runtime are defined in src/requirements.txt (README specifies Python 3.8).
Company Discovery and Registry
Company discovery establishes the identifier boundary between local symbols and the upstream API/site. src/discoverCompanies.py retrieves live listings and regenerates src/constants/companyIdMap.py; it merges rather than replaces the existing mapping so delisted symbols remain addressable. URL and request-header definitions are separated into src/constants/url.py and src/config/headers.py.
Historical Seeding Pipeline
src/allDataScrapper.py iterates the company registry and fetches historical trading records for symbols that have no destination file. This makes backfill non-destructive: existing datasets are not overwritten or duplicated. Retrieved records are normalized into the repository’s common CSV schema, whose column contract is represented by src/constants/columns.py, then persisted as data/company-wise/<SYMBOL>.csv.
Incremental Daily Update Pipeline
src/dailyDataScrapper.py is the operational refresh path. It targets only already-seeded CSVs, obtains current trading data, and appends only records absent from each file’s local history. History and duplicate/append decisions are isolated in src/utils/history.py; status derivation (close versus open) is handled through src/utils/status.py. This preserves an idempotent daily update boundary.
Data Transformation and Persistence
The persistent interface is the CSV collection under data/company-wise/. Each row carries date, OHLC prices, percentage change, quantity, turnover, and derived status. Response-shape normalization is supported by src/utils/flatten.py; CSV mutation behavior is centralized in src/modified_csv.py. The dataset is therefore both the pipeline output and the repository’s consumer-facing API.
Automation and External Dependencies
A scheduled GitHub Actions job at .github/workflows/schedule-updater.yml runs the daily scraper multiple times on trading days, providing retry-by-schedule rather than a persistent service runtime. The scraper depends on live NEPSE listing and market-data endpoints, accessed through HTTP/session logic in src/utils/session.py and parameter construction in src/utils/params.py. GitHub is the storage/distribution infrastructure: successful automation commits updated CSV artifacts back into the repository.
Main entry points: dailyDataScrapper.py Daily updater · modified_csv.py CSV persistence · allDataScrapper.py Historical backfill · discoverCompanies.py Company discovery
Components 17
Company discovery
- Request headers
src/config/headers.py - Endpoint definitions
src/constants/url.py - Company discovery · Refreshes the symbol-to-ID registry while retaining delisted symbols.
src/discoverCompanies.py - Company ID registry · Identifier boundary between local symbols and NEPSE IDs.
src/constants/companyIdMap.py
Collection pipelines
- HTTP session
src/utils/session.py - Request parameters
src/utils/params.py - Historical backfill · Seeds only symbols without an existing CSV.
src/allDataScrapper.py - Daily updater · Updates only seeded symbol files idempotently.
src/dailyDataScrapper.py - Response normalization
src/utils/flatten.py - History deduplication · Determines rows absent from local symbol history.
src/utils/history.py - Trading status · Derives open or close status.
src/utils/status.py
Versioned dataset
- CSV schema · Defines common date, OHLC, change, quantity, turnover, and status fields.
src/constants/columns.py - CSV persistence · Centralizes CSV mutation behavior.
src/modified_csv.py - Company CSV collection · One ascending date-wise CSV per trading symbol.
Scheduled automation
- Scheduled updater · Runs the daily scraper multiple times on trading days.
.github/workflows/schedule-updater.yml - GitHub repository · Commits and distributes refreshed CSV artifacts.
Other components
- NEPSE live endpoints · Listings and market trading data.
Connections 22
- Request headers → Company discovery: configures
- Endpoint definitions → Company discovery: defines listing endpoint
- NEPSE live endpoints → Company discovery: live listings
- Company discovery → Company ID registry: merges registry
- Company ID registry → Historical backfill: symbols and IDs
- Company ID registry → Daily updater: symbols and IDs
- HTTP session → NEPSE live endpoints: HTTP access
- Request parameters → HTTP session: request parameters
- NEPSE live endpoints → Historical backfill: historical records
- NEPSE live endpoints → Daily updater: current records
- Historical backfill → Response normalization: normalizes responses
- Daily updater → Response normalization: normalizes responses
- Company CSV collection → History deduplication: local history
- History deduplication → Daily updater: missing rows only
- Daily updater → Trading status: derives status
- Response normalization → CSV persistence: normalized rows
- Trading status → CSV persistence: status values
- CSV schema → CSV persistence: schema
- Historical backfill → CSV persistence: seed rows
- CSV persistence → Company CSV collection: writes symbol CSVs
- Scheduled updater → Daily updater: runs
- Company CSV collection → GitHub repository: committed artifacts