'Portfolio Graph using Dart and Flutter

I am working on a portfolio management app where I have user data for historical stock/crypto transactions they have completed. I am trying to figure out what is the MOST EFFICIENT way to generate a historical portfolio graph for the user so that they can view how their portfolio has changed over the years. I have a local database (HIVE) that currently does not store any data and have a cloud database Firebase Firestore for storing all user and transaction data.

The steps that I have figured out that need to be taken care of are

  1. To generate a snapshot of what the portfolio (stocks/crypto symbols and quantity)looked like for the user from the beginning of their investing period. (Have a handle on this one but would love any inputs)
  2. To fetch the historical data for all the stocks they have had since the beginning of their portfolio from IEX cloud API. Currently fetching 5y data from IEX cloud for all the stocks in the portfolio every time the algo is run. Time-wise super-efficient but very expensive credit-wise
  3. Run a function to calculate the portfolio value for each day*(save it?)* and display it as a chart.

The question that I have is

What data should I save(&where to save(locally or on cloud)) and what data should I calculate on the fly for the user?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source