javascript - Calculate balances (in database) of different currencies (rates in API) - using javascript
问题描述
I would appreciate some help.
I have a database and API. The database has the balance for each crypto_currency and the API has the current rate for the cryptocurrency in euros.
#The data sources
API Data
data:
0: {id: "bitcoin", symbol: "btc", current_price: 47000,…}
1: {id: "ethereum", symbol: "eth", current_price: 1500,…}
2: {id: "monero", symbol: "xmr", current_price: 200,…}
Database
- id
- balance
- api_id
- currency_symbol
#Notes:
- api_id in the database is the same as id in the API
- current_rate
#What I want to achieve: I want to make the following calculation:
Calculate the balance for all currencies balance(from database)*current_rate
sum (balance*current_rate)
Where do I start? How do I filter the API data? One way would be to query the date from the API with query parameters, but then I would go over the API call limit if there are more users on the site, as there are on average 10 balances, so that would count as 10 API calls.
If you could guide me on where to start, how would you do it, in theory, would be appreciated.
#One solution that worked
I have tried this: I sort the balances desc by api_id in the database and sort the API query based on id aswell....that way the order of the currencies is the same in the API with the database, that way i can match the two things and make the calculation.
However i am thinking there is probably another way, that is more advanced.
解决方案
推荐阅读
- hyperledger-sawtooth - 客户端是否以超级账本锯齿形式向网络中的每个验证者发送交易请求?
- php - 从 Json url 结果 php 中提取数据
- sql-server - 布尔列的内连接
- asp.net-core - 安装 vue NuGet 包后找不到任何要链接的 vue.js 文件
- nginx - 在 Nginx 上运行的 OctoberCMS 项目在 chrome 中返回 404 错误
- reactjs - 我如何在反应中卸载组件
- tfs - TFS Online,更改管理员
- powershell - 从 Azure 自动化通过 Powershell 远程访问 azure vm
- php - 发布 Laravel 关系
- javascript - RouterModule.forRoot() 调用了两次