Skip to content

abdolrhman/top-currency-usd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Top Coins Prices In USD

Getting the top Currency prices in USD with support to limitation and more features

Table of Contents

Getting Started

This is an app to get Top assets prices in usd, build in top of 3 independent services

  • limitation
  • up to date information
  • speedy

Folder Structure

.
├── ...
├── src                    # All the three modules being hold there
│   ├── api                # Hold the API service 
│       ├── db                # DB Connection Source point
│       ├── coin_prices_receiver    # call from database all the coin prices
│       ├── top_assets_prices_handler   # Query the top_assets and geenrate the end-result
│   ├── procuder         # Holds the Two Services that gets the data
│       ├── coins_prices
│           ├── db            # DB connection
│           ├── model         # Hold the struct model for coins prices and some helper methods
│           ├── data_source   # Hold the struct model for coins prices and returns the data from the API
│           ├── handler       # Saves the API data, to the database
│       ├── top_assets
│           ├── db            # DB connection
│           ├── model            # Hold the struct model for coins prices and some helper methods
│           ├── data_source   # Hold the struct model for coins prices and returns the data from the API
│           ├── handler       # Saves the API data, to the database
│   
└── ...
  • Note, that it may not be the best structure, for goLang.

Installing

  • To be able to make the project work you need at least, postgres and go compiler
  • Then you need to install the dependencies of this application, unfortuante i didnt have the time to find a better way to install the dependcies, I have worked with many programming language, Go Seems to need a bit more work to install dep,
  • So i have worked with minimum depends on outside packages
  • Any way the project consist of 3 services, so you need to get into each one and use this command
go get .
  • Also support docker-compose
  • I didn't use .env for simplicity

Objectives

  1. Provide HTTP EndPoint, to fetch top assets and its currency
  2. provide limitation support
  3. merging the data of two-API's for getting the required information
  4. up-to date information
  5. independent three services each for specific tasks
  6. descriptive readme file
  7. tests
  8. docker
  9. output should be json or CSV

Implementation Solution

  • Simply my plan was to break the task into seprate thee service
  1. to grape the top assets, run in cron job each minute
  2. to grepe asset currency in USD, run in cron job each minute
  3. to push data in a shared database, periodically
  4. to provide API for the merged data in persistence matter
  • there are many solution for such structure, I have gone simple approach as to save the data, into Shared database, which is "POSTGRES",
    with a cron job that runs each 1 minute to the save two services data
    so service 1, will push into table : coin_prices
    - id int, symbol text, price real
    service 2, will push into table : top_assets - id int, symbol text, rank int

the rank and the API provider Page were tricky, you can see the code for more information, but data with limited to max 100 per 1 page, and for rank we need to make it be built in a matter to make it easy to update documents with the new rank in future And then, the API service, consume the data in away in which

  • Integration or test not implemented but intended to do
  • docker config not tested

How Edge-cases being Handled

How to save retrieve data

  • using the go-pg driver, and build it in matter of structuts instead of querying the db directly

Up-to date

  • up to date, is being solved by running the two servcies unlimited for each minute and then

Insert or update the data

Rank And Page Issue

  • so the cryptocompare API provider gives for limited data, 100 max recored per page

this been solved by running two loops when quering and insertingor update the records for top_assets

  • so issue here that once i have made two loops to loop over all of the data one to grape 100 each so tatal 200, i got into a tricky problem because i was saving the rank as with an iterator, so this made an issue which been solved

The most one that took time, Retriveing the data for the API

  • so how whould i constract the required data, and make the merge,

this has been done by

  1. Get all currency prices in array
  2. Get the limited top_assets Data and order by rank *important > tricky
  3. for each element inside top_asset, map it to the array of currency prices to get the price, once the record find get out of loop *> Tricky

Intended Approach

I believe A better approach would be to

  • use queues as something like "Producer and consumer",
  • where the producers are two services each push on seprate Queue,
  • And the consumer is the transformer or merging service
  • this can be done via kafka or rabitmq
  • that would end up with stream processor that would listen to both and transform them into a 3rd queue.
  • Now your end client only has to listen to the final stream to get updates.

Also the current implementation its not that bad,
but maybe it can be better, if there is a cache storage maybe 'redis', that cache the transformed or merged data,
so instead for each http call i get the data and merge it

Images Work flow

check the postman result with each asset contain rank and price

Alt Text

check 200 records exist for the two tables check for each cycle of cron job, updating records if needed, with order and rank in respect

Alt Text

About

Top Assets in USD

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published