- 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.
- timestamp: Integer number of seconds since the Epoch
- transaction_type: Either a DEPOSIT or a WITHDRAWAL
- token: The token symbol
- amount: The amount transacted
Copy the
transactions.csv
in current folder.
Use the
portfolio
command to run this program.
node index.js help
node index.js portfolio --help
or
node index.js portfolio -h
node index.js portfolio
node index.js portfolio --token BTC
or
node index.js portfolio -t BTC
node index.js portfolio --date 2019-10-25
or
node index.js portfolio -d 2019-10-25
Note*: Date must be on YYYY-MM-DD format*
node index.js portfolio --token BTC --date 2019-10-25
or
node index.js portfolio -t BTC -d 2019-10-25
crypto_key=64 length hex string
crypto_url=https://min-api.cryptocompare.com/data/price
These are used to convert one currency to another.
I have tried csv-parser
and papaparse
module to parse the contents of csv.
Load Time (sec) | Downloads in past 1 Year | |
---|---|---|
csv-parser | 70 | 740480 |
papaparse | 45 | 1174560 |
node index.js portfolio --token
If --token
option is enabled but no token name is passed, check()
function throws an error Enter token name
and program gets terminated.
node index.js portfolio --date
If --date
option is enabled but no date is passed didn't pass any date, check()
function throws an error Enter date
and program gets terminated.
node index.js portfolio --date xxx
If given date is not format in YYYY-MM-DD
, check()
function throws an error Enter valid date in YYYY-MM-DD format
and program gets terminated.
We console the error Given token not found
.
We console the error No token transacted on given date
.
├── LICENSE ├── package.json ├── README.md ├── src │ ├── config.js │ ├── command_cli.js │ ├── services.js │ └── utils.js └── index.js
I made the structure of the source code simple, no folders for category because it's enough for 4 files. I like keeping things simple - In fact, 'small is good, short is better and simple is best'.
This is where we put the configuration files such as file names, and the urls to be fetched. We can also set urls and api key as environment variables if needed.
This is where we handle the command-line commands in the project.
I have used yargs
module to create command-line commands in node.js and makes command-line arguments flexible and easy to use.
This is where we implement functionalities in commands. Currently we only have 'portfolio' command and for this command, getPortfolio function is defined in this file.
This file contains the various utilization functions.
convertCurrency: Get the current price of any cryptocurrency in any other currency that you need. isValidDate: Check if input the date is vaild. dateToTimeStamp: Convert date format to timestamp format.