This backend application calculates profitability for all crypto assets.
knex migrate:latest
knex seed:run
Seed data includes both purchase and trade information.
In the scripts directory are node files which perform specific operations related to calculating profitability. The field I need to calculate for each cryptocurrency is weighted_usd_per_unit
.
node scripts/updatePrice.js
To calculate profitability, I need the most current prices.
This script fetches the latest price information for 10 cryptocurrencies.
Prices are from CoinMarketCap
Fetched data will update entries in the coins_index table.
node scripts/updateBalancePurchases.js
Because a single purchase contains less data, calculating weighted_usd_per_unit
for purchases is much simpler.
For each purchased cryptocurrency, this script calculates:
Then, the calculated objects are inserted into the balances table.
To calculate weighted_cost_per_unit
, run this script:
knex migrate:rollback && knex migrate:latest && knex seed:run && node scripts/updatePrice.js && node scripts/updateBalancePurchase.js && node scripts/weightedCost
After these six commands, in the balances table is an updated entry for each cryptocurrency.
In the balances table. Each unique cryptocurrency should show the sum of all liquid units
(how much of this currency I have available) and the weighted_usd_per_unit
.
if coins_index.usd_per_unit
> balances.weighted_usd_per_unit
, then that cryptocurrency is PROFITABLE!