0.1.3 • Published 3 years ago

@apquinit/propine v0.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

propine

Command-line program to help crypto investors track their assets. This program is also deployed in npm as an installable global package. Alternatively, you can use ./bin/run from within the root directory of this repository to run the program from source without installing. See development section below for more details on how to build and run this program from source.

Node.js CI Version Downloads/week License

Usage

Install propine globally via npm.

$ npm install -g @apquinit/propine

Pass the file path of your CSV file as the first and only argument. The CSV file must have the following columns:

  • timestamp - Integer number of seconds since the Epoch
  • transaction_type - Either a DEPOSIT or a WITHDRAWAL
  • token - The token symbol
  • amount - The amount transacted

For your reference, refer to this sample file here.

$ propine path/to/file.csv

$ propine (-v | --version)

$ propine --help [COMMAND]

Optionally, you can pass a token or timestamp flags to filter the returned value with those parameters. Here is the list of possible return values:

  • Given no parameters, returns the latest portfolio value per token in USD.
  • Given a token, returns the latest portfolio value for that token in USD.
  • Given a timestamp, returns the portfolio value per token in USD on that timestamp.
  • Given a timestamp and a token, returns the portfolio value of that token in USD on that timestamp.
$ propine path/to/file.csv --token=BTC

$ propine path/to/file.csv --timestamp=1571967208

$ propine path/to/file.csv --token=BTC --timestamp=1571967208

Development Setup

The following requirements must be installed in your system before proceeding.

  • Node.js (12.21.0)
  • npm (7.6.0)
  • git (latest)

Clone this repository.

git clone https://github.com/apquinit/propine-interview-questions.git

Go to 'Question 2' folder.

cd 'Question 2'

Install required dependencies.

npm install

Automatically fix code lint errors during development. ESLint is used for code linting. Linter will fix some of the common syntax warnings, refer to .eslintrc file to check currently implemented lint rules. Remember that not all of syntax warnings can be automatically fix by this command, some needs to be manually fixed by the developer. Don't worry, ESLint will tell you which line of codes needs to be fixed and where to find them.

npm run lint

Run code lint checks and unit tests. Mocha testing framework is used for unit tests and test coverage reports. Mocha also integrates ESLint, lint checks will run after the unit tests.

npm run test

For running the program locally, ./bin/run is the equivalent of the command propine when installed via npm:

$ ./bin/run path/to/file.csv
running command...

$ ./bin/run (-v | --version)
propine/0.0.0 linux-x64 node-v12.21.0

Design Decisions

  1. I chose to use ESLint to help avoid and fix common syntax and linting errors in the code.
  2. I chose to use Mocha test framework to run unit tests of every methods in the program, and to display the code coverage.
  3. The pipeline will automatically run tests using GitHub Actions when the master branch has been updated. My initial plan is to use TravisCI, but since this is a private repository, I can't. TravisCI is only free for public repositories.
  4. Instead of the file path being a flag (--file=path/to/file.csv), I designed the program to require it as an argument instead. Mainly because the file is always required in order for the code to run, unlike token and timestamp which are both optional.
  5. I've decided to design the program to accept any CSV files provided they have the required columns, and not lock the program to use only the provided CSV. Additionaly, I've also decided to not commit the transactions.csv file because of the file size (even when zipped). It is never a good coding practice to commit and push large files in the code repository.
  6. I've decided to limit the file size of the CSV to 50MB. Coding-wise, storing a large size of data in CSV format (tho' possible) is not the most optimized and efficient way to query and filter data fast. Loading almost 1 gigabyte of data directly into runtime memory will only result into an "out of memory" error. One possible solution for this is to import the CSV data into a database table, and query it from there. This can be done easily, but is out of scope in the requirements of this interview question.
  7. Crypto exchange rates are fetched only once by a single call with multiple symbols, the program will get all unique symbols in the CSV file. If a token symbol is invalid anywhere in the CSV, the program will simply ignore the faulty token symbol, and will just proceed on the valid ones.