A crypto price discovery tool for the time travelling investor.
The assignment was to create an application or an API backend that would let users check the price of bitcoin between two dates. We should also determine, during the given time frame:
- how many days did the longest downtrend last?
- which date had the highest trading volume?
- on which dates should we have bought and sold to maximize profits, if at all possible?
We were to use Coingecko's API for the data. The user is interested in daily values.
Citcoins is a REST API backend. It adds fields to the JSON responses from Coingecko, answering the assignment's questions. It forces daily granularity by requesting at least 91 days worth of data.
The API is running at https://citcoins.herokuapp.com/api/
To get daily prices, volumes and market caps for bitcoin in euros for the first week of December 2021, with the insights for longest downtrend, day with the highest volume and maximum profit included, send a GET request to
The response JSON has the unix timestamps in milliseconds:
{
"prices" : [],
"market_caps" : [],
"total_volumes" : [],
"max_volume" : [1638662400000, 49444429183.12263],
"longest_downtrend" : {
"found" : true,
"start" : [1638403200000, 50506.910551023844],
"end" : [1638662400000, 43452.36627055587],
"length_in_days" : 3
},
"max_profit" : {
"should_buy" : true,
"when_to_buy" : [1638316800000, 50310.23157858034],
"when_to_sell" : [1638403200000, 50506.910551023844],
"profit" : 196.67897244350752
},
"attribution" : "Data provided by CoinGecko"
}
The Citcoins API is organized around REST. The API has predictable resource-oriented URLs, returns JSON-encoded responses, and uses standard HTTP response codes.
Endpoint | Description |
---|---|
GET /api |
Returns links to API resources. |
GET /api/coins |
Returns links to API resources. |
GET /api/coins/list |
Lists the IDs of supported crypto and fiat currencies. |
GET /api/coins/:id |
Basic information on a cryptocurrency. id - cryptocurrency identifier, ex. bitcoin |
GET /api/coins/:id/market_chart |
Returns daily data for 100 days on prices, market caps and total volumes. id - cryptocurrency identifier, ex. bitcoin vs_currency - optional parameter for fiat currency, ex. eur |
GET /api/coins/:id/market_chart/range |
Returns daily data between the two dates given as parameters. Can also add analytical insights to the response. id - cryptocurrency identifier, ex. bitcoin from=1638309600 - unix timestamp in seconds to=1638828000 - unix timestamp in seconds insights=true - optional parameter for insights vs_currency - optional parameter for fiat currency, ex. eur |
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
Make sure you have a recent version of Node.js installed.
Clone the repository, install Node.js modules.
git clone https://github.com/simosavonen/citcoins.git
cd citcoins
cd server
npm install
Start the application in development mode.
npm run dev
The API should now be running at http://localhost:3001/api
To run the battery of tests
npm test
The tests are found in directory /tests
and are separated into integration and unit tests. Integration tests use real data fetched from Coingecko API.
Push server subdirectory to heroku
git subtree push --prefix server heroku master