crypto-portfolio-cli
v1.0.4
Published
A CLI that generates token values(in USD) for a customer's portfolio.
Downloads
7
Maintainers
Readme
crypto-portfolio-cli
CLI Commands
NOTE: Please add the crypto compare url and api key as an env variable before running the commands.
export BASE_URL=<cryptocompare_url>
export API_KEY=<cryptocompare_api_key>
Retrieve latest portfolio value per token in USD
npx crypto-portfolio-cli -f transactions.csv
Latest portfolio value for a token in USD
npx crypto-portfolio-cli -f transactions.csv -t ETH
Portfolio value per token in USD on a specified date
npx crypto-portfolio-cli -f transactions.csv -d '1571967208'
Portfolio value of provided token in USD on a specified date
npx crypto-portfolio-cli -f transactions.cv -t -d '1571967189'
Project set-up
Clone repo and install dendencies
npm i
Set cryptocompare BASE_URL and API_KEY in .env
BASE_URL=<cryptocompare_url>
API_KEY=<cryptocompare_api_key>
Create symlink to global folder, linking to the package.
npm link cpc
Run unit tests
npm test
Build application
npm run build
Cli command
cpc -f transactions.csv
Design
High Level Design
Since the CSV is large, it has to be processed incrementally in chunks becuase trying to load the whole file at once will lead to memory allocation issues. Streams have been used to solve this problem. The CSV file is divided into several chunks of data enabling it to easily fit into the available memory for parsing and further processing.
Processing data when a token is provided varies from when there is no token provided. The latter requires the parsed data to be grouped in order to extract all the tokens in the file, this makes the solution more robust as different portfolio files may have different tokens and it's not feasible to hard code the different token values.
Because of the slight difference in processing and to make the code easier to reason about, the template method design pattern is used whereby an abstract class is defined with different steps required to process the csv, these steps are abstract methods and the details are implemented by child classes which contain the business logic.
Areas to improve
- Make the error handling more robust across the application. Basically handle different edge cases gracefully and provide good feedback when an error occurs.
- Write more unit tests and add integration tests to prevent regression , bugs and improve the overall quality of the code.
- Add CI to ensure only tested and working code is pushed to main.
- Even when using streams parsing the CSV file still takes quite some time. I would explore using workers to parallelize workloads and take advantage of multi-core processors. I hypothesize this may improve performance. More research needs to be done. Alternatively using a different tool/language that handles CPU bound tasks better may improve performance. Further investigation needs to be done.
- Improve the TypeScript definitions across the application
- Make the validation of inputs more robust e.g ensure only valid tokens are provided, validate the date provided.
- Make the cli outputs beautiful using tools like chalk, cli-table.