Giter Site home page Giter Site logo

sanath1188 / crypto-portfolio Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 11 KB

An app that takes data in form of deposits/withdrawals and calculates the portfolio value. Works well even if large (1GB+) files.

JavaScript 100.00%
cryptocurrency data-processing event-stream file-processing files nodejs

crypto-portfolio's Introduction

crypto-portfolio

An app that takes data in form of deposits/withdrawals and calculates the portfolio value

Design decisions

  • All config level values are stored in the config/default.json file
  • Used readline library to create a Q&A interface
  • Used event-stream library to be able to read the file quickly as it splits the file and reads the chunks in parallel without clocking the CPU
    • A function called filterAndStoreToken keeps storing the transaction information as and when every line in the file is parsed This starts filtering only the tokens that need to parsed and stores them as key value pairs in the tokensToBeProcessed object
    • Once the entire file is parsed, the getPortfolio function is triggered. At this point, the tokensToBeProcessed object has all the tokens that need to processed. I'm using promise.all to ensure all the API calls happen in parallel too.

Things to improve

  • Store the file metadata (file name and modified time) in the env somewhere. Read through the entire file again ONLY if either of the metadata change.
  • Can code the project in typescript to ensure better use of ENUMs and enabling data type integrity.
  • Add regex to ensure validity of values input (like date)

How to run the application

  • Clone the project and checkout to the main branch
  • Place the transaction.csv file in the root of the project and ensure the correct file name is given in the config/default.json file. The csv file should be of the format: https://general-project-assets.s3.ap-south-1.amazonaws.com/crypto_portfolio/transaction_file_sample.png
  • Install node 14.16.0 (It should just about run with any version >12)
  • Run the command: npm i
  • Run the command: npm i -g nodemon
  • Run the command: nodemon index.js
  • You'll be prompted to enter the token name and date in sequence. Hit enter to skip. If no value is provided, the app will calculate the entire portfolio value for all tokens.
  • If the token name is provided, the app calculates the portfolio value for the specfiic token.
  • If the date is provided, the app calculates the portfolio value for the specific date.
  • If both are provided, the app calculates the portfolio value for the specific token on the specific date.
  • Use the YYYY-MM-DD format to enter the date
  • The output comes in the format:
    • {
    • USD: 20318.7,
    • token: 'BTC',
    • value: 1200425.1521679235,
    • portFolioValue: 24391078539.35439
    • }
    • {
    • USD: 1497.54,
    • token: 'ETH',
    • value: 901704.2831248266,
    • portFolioValue: 1350338232.1507528
    • }
    • {
    • USD: 0.4694,
    • token: 'XRP',
    • value: 903332.9813728357,
    • portFolioValue: 424024.50145640905
    • } where portfolioValue in each object is the corresponding portfolio value for the token name.

crypto-portfolio's People

Contributors

sanath1188 avatar sanathkraft avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.