This project fetches cryptocurrency data from the CoinGecko API and stores it in a MongoDB database. It includes scheduled tasks to update prices at regular interval of 2 hours and provides endpoints to fetch the latest prices and calculate standard deviation.
-
Clone the repository:
git clone https://github.com/Aditya8840/Crypto
-
Navigate to the project directory:
cd Crypto -
Install the dependencies:
npm install
-
Start the server:
npm start
- Axios: For making API calls to the CoinGecko API.
- Cron: For scheduling tasks, such as fetching and updating cryptocurrency prices at regular interval of 2 hours.
- Winston: For efficient and customizable logging.
- Mongoose: As an ORM (Object Relational Mapper) to interact with MongoDB.
- Glob: For dynamically loading all JavaScript files in specific directories, enabling modular design and reducing manual imports.
Request:
GET /api/stats?coin=bitcoinResponse:
{
"status": 200,
"message": "Success",
"data": {
"price": 95387.74265127412,
"marketCap": 1889217818626.9343,
"24hChange": 2.730761761674287
}
}Request:
GET /api/deviation?coin=bitcoinResponse:
{
"status": 200,
"message": "Success",
"data": {
"deviation": 244.12672027653105
}
}- Ensure to create a
.envfile in the project root directory with your MongoDB URL and CoinGecko API key. - You can take reference from the provided
.env.examplefile for the required format and variables.