npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

crypto-portfolio-cli

v1.0.4

Published

A CLI that generates token values(in USD) for a customer's portfolio.

Downloads

9

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.

high level design

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.

high level design

Areas to improve

  1. Make the error handling more robust across the application. Basically handle different edge cases gracefully and provide good feedback when an error occurs.
  2. Write more unit tests and add integration tests to prevent regression , bugs and improve the overall quality of the code.
  3. Add CI to ensure only tested and working code is pushed to main.
  4. 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.
  5. Improve the TypeScript definitions across the application
  6. Make the validation of inputs more robust e.g ensure only valid tokens are provided, validate the date provided.
  7. Make the cli outputs beautiful using tools like chalk, cli-table.