A Node CLI program that displays your blockchain transactions from CSV file.
- Given no parameters, return the latest portfolio value per token in USD
- Given a token, return the latest portfolio value for that token in USD
- Given a date, return the portfolio value per token in USD on that date
- Given a date and a token, return the portfolio value of that token in USD on that date
The following tools were used in this project:
Extract CSV file file to root folder.
Also pushed .envrc
file which contains CRYPTO_COMPARE_API_KEY
for convenience.
# after cloning; install dependencies
$ npm install
# run CLI app
$ node index.js
# use arrow keys/input to navigate the app.
Upon running the app, this is the main navigation that you will see.
? How would you like to proceed?
> noParams
Token
Date
TokenDate
choose an option by using your arrow keys.
- noParams - will show you your token portfolio.
- Token - will ask you to input Token Symbol, default is BTC.
- Date - will ask you to input a Date, default is Today.
- TokenDate - will ask you for both Date and Token Symbol.
For reading the CSV with almost 21 million rows, instead of using libraries that parses the file for you, I used FS to create a readstream and compute necessarry data using own logic. This drastically lowers the run time of the csv read function from a minute down to less than 10 seconds.
Most important decision is the caching, I have utilized in-memory caching using node-cache, this allows user to get instant result from query. To save cost and not be rate-limited by third party apis especially those that are not free.
I have kept the code solution simple, maintainable and not over complicated functions as possible. To start the app getPortfolioDetails
function is first executed which prompts user for input, after input it will call the handleAnswer
function.
Depending on the answer the user inputs, the handleAnswer
will check if there is already data on cache and if there is not it will call the readCSV
function to read and save computed data to cache.
The getTokenInUsdAmount
and resultFormatter
functions are responsible for the formatting and displaying of the results.
const headersFormat = ['date', 'tx-type', 'token', 'amount']
if you happen to have more columns from your csv, you can easily update and make necessary changes to match your needs.- if you choose to add more user prompt or option, edit the
prompts.js
and add/edit your desired prompts. - update
const fileName = yourCSVFileName.csv
if you have a different file name.