How flash0x45/portfolio-tracker works
This repository is a small Python application for tracking a mutual fund portfolio in real time during Indian market hours. The architecture is a pipeline: load configuration, check whether NSE is open, fetch scheme holdings, map them to tradable NSE symbols, fetch live prices, and compute portfolio-level returns.
The main runtime entry point appears to be app.py. It likely wires the subsystems together and starts the tracking loop. The README mentions main.py and a Streamlit app, but those files are not present in the tree, so the codebase shown here looks centered around the app.py/agents modules instead.
config.py is the configuration boundary. It holds environment-specific settings such as the fund slug, poll interval, and NSE holiday list. This is the main place where runtime behavior is tuned without changing the core logic.
The agents/market_clock.py module is the market-gating subsystem. Its job is to decide whether the tracker should run now, based on Indian market hours and holidays. This is important because it prevents unnecessary polling when NSE is closed and likely controls whether the app exits, sleeps, or waits.
agents/portfolio_builder.py is the portfolio ingestion and normalization step. It fetches the holdings for a Groww mutual fund scheme and resolves underlying equity holdings into NSE symbols. Architecturally, this is where the fund-specific source data is transformed into a portfolio the rest of the system can price.
agents/price_fetcher.py is the market-data adapter. It is responsible for retrieving current live prices for the resolved NSE symbols. This module forms the external data boundary to whatever quote source is being used.
agents/return_calculator.py is the valuation engine. It takes holdings plus live prices and computes current value, gains/losses, and other return metrics. This is the core computation layer and should be treated as pure business logic if possible.
agents/orchestrator.py is the control plane for the system. It likely coordinates the full refresh cycle: check market status, build the portfolio snapshot, fetch prices, calculate returns, and repeat at the configured polling interval. If you are drawing the architecture, this is the central node connecting all other agents.
The agents package is the main functional boundary in the codebase. Each module has a narrow responsibility, which suggests a layered design: market gating, portfolio normalization, price retrieval, and valuation. There is no evidence in the tree of persistence, message queues, or a separate backend service.
Data flow is mostly one-directional and in-memory:
config and market-calendar data go into the market clock;
fund holdings come from Groww into the portfolio builder;
resolved symbols go to the price fetcher;
prices and holdings feed the return calculator;
the orchestrator aggregates and repeats the cycle.
The likely external dependencies that materially affect the architecture are:
Groww or a similar source for mutual fund holdings,
an NSE quote source for live prices,
and the NSE trading calendar/holiday schedule for run-time gating.
These are the only external system boundaries implied by the file names and README.
There is also a presentation concern hinted at by the README’s Streamlit reference, but that UI file is not in the tree. Based on the repository contents shown, the core application is the tracking engine itself rather than a full web service or database-backed system.
Main entry points: orchestrator.py Orchestrator · config.py Config · portfolio_builder.py Portfolio builder · market_clock.py Market clock
Components 7
Core app
Runtime entrypoint and configuration boundary.
Agents
Pipeline components that gate, build, price, and value the portfolio.
- Orchestrator · Coordinates the refresh cycle and repeats it.
agents/orchestrator.py - Market clock · Checks NSE hours and holiday status.
agents/market_clock.py - Portfolio builder · Fetches scheme holdings and resolves tradable NSE symbols.
agents/portfolio_builder.py - Price fetcher · Retrieves live prices for resolved symbols.
agents/price_fetcher.py - Return calc · Computes value, gains, losses, and returns.
agents/return_calculator.py
Connections 11
- App → Config: loads · Reads runtime configuration at startup.
- App → Orchestrator: starts · Hands off execution to the coordinator.
- Orchestrator → Market clock: checks · Decides whether tracking should run now.
- Orchestrator → Portfolio builder: builds · Fetches and normalizes scheme holdings.
- Portfolio builder → Price fetcher: resolves symbols · Passes tradable NSE symbols for pricing.
- Price fetcher → Return calc: prices · Provides live market data for valuation.
- Portfolio builder → Return calc: holdings · Supplies quantities and cost basis.
- Return calc → Orchestrator: results · Returns portfolio metrics for the cycle.
- Config → Market clock: holidays · Provides market calendar and polling behavior.
- Config → Orchestrator: intervals · Controls refresh cadence and fund selection.
- Market clock → Orchestrator: allow/deny · Gates whether the refresh loop proceeds.