简体   繁体   中英

Best practice for keeping accurate stock prices

I am building a service (web via html/css/nodejs and iOS app via swift 4 for now) that will calculate how much you have total of all stocks across multiple brokers, in your country's currency. The website and app both pull from the same database, and therefore display the same information.

Let's say hypothetically, I can only pull the quantity owned of each stock (in # of stocks, not any currency) and I store this in a database. The website/app will retrieve it from the database when a user requests a refresh.

I want to be able to calculate the sum of all stocks in an account using that quantity and the exchange's price for that stock (pulled from elsewhere).

Users don't need real time accuracy, and there is a daily cap of 200 on the amount of calls you can make to the exchange. This could be increased through a request.

I was thinking of the best practice for how to retrieve/store the price data. Seems like I have 2 options:

1) Store it in the database with the quantity owned and have the website/app query the database for both the amount owned and price. This could be updated centrally and all users could pull from it or request new updates, but I feel that is a lot of I/O on the database and exchange's API.

2) Retrieve the price info and store locally each time a user requests it straight from the exchange. This is less storage than option 1, but is still fairly I/O heavy especially on the exchange's API

Which is the best way to do this? Or is there a better way that I'm missing?

Since a given stock price is the same for everyone at any particular moment, it'd make sense to have your web application query the data source for the stocks. Then your app can query your web application for the price instead of hitting the data source every time. (Check the license for the data source, though -- some providers don't want you to cache and re-distribute their data.)

This approach should limit the number of requests that you have to make to the data source, and it'll also ensure that your web application and mobile app are always working from the same set of data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM