Business Specification

Use cases, actors, business rules and end-to-end flows.

Business Specification Document

Use Case Methodology and Business Process Flows

ICICI Direct • Interactive Brokers • Revolut

Embedded document image

Figure 1. $hail's Dashboard is the single entry point to the three portfolio solutions.

Document objective Define the business scope, actors, use cases, rules, flows, acceptance criteria and operational exceptions for a personal multi-broker portfolio dashboard.

1. Executive summary

The solution consolidates access to ICICI Direct, Interactive Brokers and Revolut portfolio views behind a single authenticated web dashboard. Each broker uses a different integration method: Breeze API for ICICI Direct, a TWS-connected Windows agent plus Oracle-hosted snapshot for IBKR, and secure CSV ingestion for Revolut. Daily external market prices are cached on Oracle to keep dashboards useful when source applications are not open.

2. Business objectives

3. Scope

In scopeOut of scope / deferred
ICICI funds, holdings and portfolio display through BreezeAutomated ICICI token issuance without user authentication
IBKR one-click snapshot request and daily cached pricingAutomated trade placement or order management
Revolut full-history CSV upload and portfolio reconstructionTax filing or certified tax-lot accounting
Twelve Data / Alpha Vantage cached pricing and FXGuaranteed real-time data for every global exchange
Oracle hosting, security controls, backups and cronEnterprise multi-user tenancy

4. Actors

ActorResponsibility
Portfolio ownerAuthenticates, renews Breeze token, uploads Revolut statements, starts TWS/Windows agent and requests IBKR snapshots.
Web browserDisplays dashboard pages and status; never holds provider API secrets.
Oracle Ubuntu platformHosts Nginx, Flask APIs, static pages, snapshots, caches, logs, schedules and backups.
ICICI Breeze APISupplies ICICI portfolio and account data when the session is valid.
IBKR TWS / IB GatewayLocal authenticated IBKR source used by the Windows export agent.
Windows agentPolls Oracle, claims a refresh request, runs export_ibkr.py and uploads the snapshot.
External price providersSupply supported market prices and FX data to server-side refresh jobs.

5. Use case catalogue

IDUse casePrimary actorPreconditionMain flowPostcondition
UC-01Open central dashboardPortfolio ownerAuthenticated site is reachableDisplay cards for ICICI Direct, IBKR, Breeze token/login and RevolutSelected portfolio page opens
UC-02Refresh ICICI portfolioPortfolio ownerValid Breeze session tokenOpen ICICI Direct Portfolio; dashboard calls Breeze-backed APIFunds and holdings appear
UC-03Renew Breeze tokenPortfolio ownerICICI login availableGenerate token; open Breeze Session Token card; submit token and admin PINServer .env contains current token
UC-04Request IBKR snapshotPortfolio ownerTWS logged in; Windows agent runningClick Refresh IBKR Snapshot; enter PIN; server queues jobAgent claims job
UC-05Export/upload IBKR snapshotWindows agentQueued job and valid agent tokenConnect locally to TWS; run export; upload JSONOracle publishes a validated snapshot and dashboard reloads
UC-06Refresh IBKR pricesCron schedulerPrice keys, mappings and prior snapshot availableRun refresh_ibkr_prices.pyPrice cache and enriched snapshot updated
UC-07Upload Revolut statementsPortfolio ownerFull account CSV available; optional P&L CSVUpload validated files with admin PINRevolut snapshot rebuilt and browser returns to dashboard
UC-08Refresh Revolut pricesCron schedulerMappings and price keys availableRun refresh_revolut_prices.pySupported prices/FX cached; Pending remains for unmapped symbols
UC-09View portfolio metricsPortfolio ownerSnapshot/cache existsOpen/refresh portfolio pageCards, charts, market value and P/L display

6. Detailed primary flows

6.1 ICICI Direct refresh flow

  1. Open $hail's Dashboard.
  2. If the Breeze session is valid, open ICICI Direct Portfolio.
  3. If the session is expired, open ICICI Breeze Login and generate a current token.
  4. Open Breeze Session Token, submit the token and admin PIN.
  5. Return to ICICI Direct Portfolio and reload.

6.2 IBKR holdings and account flow

  1. Log in to TWS on a configured Windows laptop.
  2. Start ibkr_windows_agent.py and keep the PowerShell window open.
  3. From any browser, click Refresh IBKR Snapshot and submit the admin PIN.
  4. Oracle records a queued job. The first authenticated agent claims it.
  5. The agent runs export_ibkr.py against the local TWS socket.
  6. The agent uploads ibkr_snapshot.json using the private agent token.
  7. Oracle validates, backs up and publishes the snapshot. The browser polls status and reloads after success.

6.3 Revolut transaction flow

  1. Download a complete start-to-date account statement CSV and optional P&L CSV.
  2. Open the Revolut dashboard and choose Upload Revolut Statements.
  3. Select account and P&L files in the correct fields, enter the admin PIN and submit.
  4. The server validates extensions, size and required account columns.
  5. The processor reconstructs holdings, applies buys, sells, stock splits and merger adjustments, and ignores internal migration transfers.
  6. The prior snapshot is backed up; the new snapshot is published only after successful JSON validation.
  7. The browser returns to Revolut.html with a success message.

7. Business rules

RuleDefinition
BR-01API keys, agent tokens and broker credentials must remain server-side or in protected local configuration.
BR-02A dashboard page load reads cached JSON and must not call external pricing providers directly.
BR-03IBKR holdings/account changes require a new TWS snapshot; external prices alone do not change quantities or cash.
BR-04Revolut updates use a full-history account statement to minimise duplicate or omitted transactions.
BR-05UK GBX quotes are divided by 100 before GBP valuation.
BR-06Unsupported symbols use Pending or an IBKR snapshot fallback; a failed provider call must not delete a previously valid cached price.
BR-07Revolut price refresh runs at 22:30 UTC weekdays; IBKR price refresh runs at 22:40 UTC weekdays.
BR-08Admin PIN authorises dashboard actions; the separate agent token authorises Windows agent endpoints.

8. Alternate and exception flows

ConditionExpected behaviour
Breeze token expiredICICI page fails gracefully; user renews token and retries.
No Windows IBKR agent onlineRequest remains queued and dashboard displays Waiting for a Windows agent.
TWS unavailable or API socket disabledAgent reports export failure; old snapshot remains.
Revolut files reversedValidation reports missing account columns; old snapshot remains.
Alpha Vantage quota exhaustedExisting cache/fallback remains; error recorded; Twelve Data operations continue where applicable.
Unmapped Revolut symbolHolding displays with Pending price; transaction-derived quantity/cost remains available.
Cron/API errorThe log captures output; existing published cache remains available.

9. Acceptance criteria

References

10. End-to-End Business Flow

This section provides the integrated business process that links the use cases into complete operational journeys. The flow begins at $hail’s Dashboard, separates holdings/account updates from price updates, and ends when the relevant portfolio page displays validated holdings, market values and P/L.

End-to-end principle The solution has two independent update cycles: (1) holdings/account data changes when broker or statement data changes, and (2) market prices change through scheduled external-price jobs. The dashboard combines the latest available result from both cycles.
Embedded document image

Figure 2. End-to-end business flow across ICICI Direct, IBKR and Revolut.

10.1 Overall process from the main dashboard

StepBusiness stageActivityBusiness outcome
1AccessPortfolio owner signs in and opens $hail’s Dashboard.Authenticated home page is displayed.
2Select journeyPortfolio owner selects ICICI Direct, Interactive Brokers or Revolut.Relevant portfolio page opens.
3Determine update needPortfolio owner decides whether holdings/account data changed or only prices need refreshing.Correct manual or automatic path is selected.
4Acquire source dataBreeze API, local TWS export, or Revolut CSV provides holdings/account data.A current source payload is available.
5Validate and publishOracle validates responses/files, creates backups and publishes a snapshot.Last-known-good holdings snapshot is current.
6Refresh market dataScheduled jobs call supported external providers and apply cached/fallback values.Timestamped price/FX cache is current.
7Calculate portfolioMarket value and unrealised P/L are calculated from quantity, cost and price.Portfolio metrics are available.
8Present and monitorDashboard displays cards, charts, tables, status, timestamps and Pending/fallback conditions.User can review the consolidated portfolio and take corrective action if needed.

10.2 Trigger and routing decision

TriggerPortfolioRequired routeManual actionAutomatic action
Normal market day; no transactionsIBKR / RevolutPrice refresh onlyOpen/refresh dashboard after scheduled job.Revolut 22:30 UTC; IBKR 22:40 UTC, weekdays.
ICICI session expiredICICI DirectSession renewal then portfolio readGenerate Breeze token; submit via Breeze Session Token card.None.
IBKR buy, sale, cash or quantity changedIBKRTWS snapshot then price enrichmentLog in to TWS; start agent; click Refresh IBKR Snapshot.Next price job enriches the new snapshot; existing cache remains available.
Revolut transaction/dividend changedRevolutFull-history statement rebuildUpload complete account CSV and optional P&L CSV.Next price job uses the rebuilt holdings.
Price missingIBKR / RevolutFallback or mapping routeMap symbol later if required.Use existing cache, IBKR snapshot fallback, or show Pending.

10.3 ICICI Direct end-to-end journey

Embedded document image

Figure 3. ICICI Direct journey and exception paths.

  1. Portfolio owner selects ICICI Direct Portfolio from $hail’s Dashboard.
  2. The system checks whether the Breeze session is usable when API data is requested.
  3. If valid, Flask calls Breeze for funds and portfolio holdings/positions and returns the response to the dashboard.
  4. If expired or invalid, the user opens ICICI Breeze Login, authenticates with ICICI, and obtains a new session token.
  5. The user opens Breeze Session Token, submits the new token with the admin PIN, and the server updates the protected environment file.
  6. The portfolio page is reopened or refreshed; cards, holdings, charts and P/L are displayed.
  7. If an API error or timeout occurs, the dashboard reports failure and the user retries after confirming the token and service availability.
Entry criteriaExit criteriaFailure stateRecovery
Authenticated dashboard; Breeze app credentials configured.Funds/holdings displayed with current session.Expired token, API error or timeout.Generate/update token; retry portfolio page; inspect backend log if repeated.

10.4 Interactive Brokers end-to-end journey

Embedded document image

Figure 4. IBKR holdings/account and automated-pricing journeys.

10.4.1 Holdings and account change path

  1. Portfolio owner logs in to TWS or IB Gateway on a configured Windows laptop.
  2. Portfolio owner starts the Windows polling agent. The agent authenticates to Oracle with the private agent token.
  3. From any browser, portfolio owner clicks Refresh IBKR Snapshot and enters the admin PIN.
  4. Oracle creates a queued job. The first available agent claims the job and updates status to exporting.
  5. The agent runs export_ibkr.py, which connects to the local TWS socket and writes ibkr_snapshot.json.
  6. The agent uploads the snapshot to Oracle. Flask verifies the job ID and JSON, backs up the prior snapshot, and publishes the new file.
  7. The dashboard status changes to success and the browser reloads using the new account, position, cash and cost data.

10.4.2 Market-price path

  1. At the scheduled weekday time, cron runs refresh_ibkr_prices.py without requiring TWS.
  2. The script loads the latest IBKR positions and symbol mappings.
  3. Supported prices and FX are requested server-side. Provider pacing and daily limits are respected.
  4. Where an external quote is unavailable, the last IBKR snapshot market price is used as fallback.
  5. The script recalculates market value, cost basis, unrealised P/L and GBP totals, then publishes the cache and enriched snapshot.
  6. When the IBKR page is opened or refreshed, the updated cached/enriched values are displayed.
ConditionDashboard/system responseBusiness recovery
No agent onlineJob remains queued; dashboard shows Waiting for a Windows agent.Start agent on a TWS-connected laptop.
TWS not running or logged outAgent cannot export and job becomes error.Log in to TWS and request refresh again.
Order requests time out but portfolio savesExporter may still complete positions/account snapshot.Confirm Connected: True, snapshot saved and expected position count.
Provider quota/errorPrior cache or snapshot fallback remains.Wait for reset or use next scheduled cycle.

10.5 Revolut end-to-end journey

Embedded document image

Figure 5. Revolut statement-ingestion and automated-pricing journeys.

10.5.1 Transaction-change path

  1. Portfolio owner exports a complete start-to-date trading account statement CSV and, where available, the P&L statement CSV.
  2. Portfolio owner opens Revolut Portfolio and selects Upload Revolut Statements.
  3. The account statement is selected in the account field, the optional P&L statement in the P&L field, and the admin PIN is entered.
  4. Flask validates extension, file size, required account columns and file placement.
  5. The processor sorts the ledger, reconstructs FIFO lots, applies buys/sells/splits/mergers, excludes internal migration duplicates, and aggregates realised P/L and income.
  6. The old snapshot is backed up. The rebuilt JSON is validated and published only if processing completes successfully.
  7. The upload page redirects to Revolut.html and displays the holdings count and timestamp.

10.5.2 Market-price path

  1. At the scheduled weekday time, cron runs refresh_revolut_prices.py.
  2. The script reads the rebuilt holdings and symbol map, then refreshes supported US/UK prices and FX rates.
  3. Existing cached values are retained for failed requests; unmapped symbols remain Pending.
  4. Revolut.html combines quantity/cost from the snapshot with cached price/FX and calculates market value and unrealised P/L.
  5. The user refreshes the dashboard to view the latest published cache.
ConditionResponseRecovery
Account/P&L files reversedRequired account columns are missing; upload is rejected.Swap files and upload again.
Invalid CSV or PINNo new snapshot is published.Correct input/PIN and retry.
Corporate actionProcessor applies configured split/merger logic.Reconcile resulting holding count; update logic if a new format appears.
Unmapped external symbolPrice and price-dependent fields show Pending.Confirm exact listing and enable mapping later.

10.6 End-to-end controls and hand-offs

Control pointInput ownerSystem controlOutput / hand-off
AuthenticationPortfolio ownerHTTPS/site authenticationAccess to central dashboard.
Sensitive actionPortfolio ownerAdmin PINAuthorised token update, upload or IBKR request.
IBKR machine actionWindows agentPrivate agent token + job IDValidated outbound snapshot upload.
File ingestionPortfolio owner / RevolutType, size and required-column checksPrivate stored input and rebuilt snapshot.
Source publicationOracleTemporary write, JSON parse, backup, publishLast-known-good snapshot.
External pricingCron / providersServer-only keys, pacing, cache preservationTimestamped prices and FX.
PresentationBrowserRead-only snapshot/cache retrievalCards, charts, tables, status and timestamps.

10.7 Use-case traceability to the end-to-end flow

Business-flow segmentUse casesEvidence of completion
Access and portfolio selectionUC-01, UC-09Central cards open the broker-specific views.
ICICI data acquisitionUC-02, UC-03Breeze session renewal and portfolio API flow.
IBKR holdings acquisitionUC-04, UC-05Dashboard request → agent claim → TWS export → snapshot upload.
IBKR valuationUC-06, UC-09Scheduled price cache and enriched snapshot calculation.
Revolut holdings acquisitionUC-07Validated full-history CSV rebuild and redirect.
Revolut valuationUC-08, UC-09Scheduled price/FX cache and client-side calculation.
Exception managementAllStatus messages, rejected invalid input, cache/fallback and recoverable queued/error states.