Problem
I need to build a profit/loss graph for a mobile app. The api from which I can get the historical price data only allows me to retrieve 1 item at a time. If the user has 500 items that would create an api failure since I can only make 50 req./min.
What is the best way to calculate this? Let's say the user buys:
- Bitcoin on 2018
- Ethereum on 2020
Solutions I thought about
Solution 1:
- On the very first time the user refreshes the data, save when and it was saved and up to which historical date.
- Do as many requests as coin the user have (problem here)
- Calculate offline the profit loss based on the dates.
- If the user comes back 5 days later, only pull those 5 days from the historical api and merge it with the previous ones.
The problem here is that I'm making too many api requests. Imagine the user has 1000+ coins.
Also calculating the profit/loss by hour might be a problem.
Solution 2:
Create a server side job and every day get the historical data, but this might be a little overboard since there are also multiple currencies, I was hoping to find an easier/less expensive solution.
Tech using
For the infrastructure I'm using AWS -> DynamoDB with DataStore + AppSync
What is the best way to accomplish this given many users and many coins per user, taking into consideration I can make 1 api request per coin and up to 50 request per min.?
Thanks