The
crypto-fetch-service
is a NestJS-based backend server that fetches the latest cryptocurrency prices, calculates statistics and deviations, and provides endpoints for retrieving this data.
Table of Contents
The Application is Deployed on Railway.


The Crypto Fetch Service is responsible for fetching the latest cryptocurrency prices from the CoinGecko API. It supports the following coins:
bitcoin
matic-network
ethereum
The service runs every 2 hours and stores the fetched data in a MongoDB database.
The MongoDB Store is used to persist the fetched cryptocurrency data. The data includes:
- Coin ID (
coinId: string
) - Price in USD (
priceUsd: number
) - Market Cap in USD (
marketCapUsd: number
) - 24-hour Change in USD (
change24h: number
) - Timestamp (
timestamp: Date
)
Endpoint: /stats
Method: POST
Description: Fetches the latest statistics for a specified cryptocurrency.
Request Body:
{
"coin": "bitcoin"
}
Response:
{
"price": 50000,
"marketCap": 1000000000,
"24hChange": 5
}
Endpoint: /deviation
Method: POST
Description: Calculates the standard deviation of the price for a specified cryptocurrency based on the latest 100 records.
Request Body:
{
"coin": "bitcoin"
}
Response:
{
"deviation": 1500
}
.env
.gitignore
.prettierrc
nest-cli.json
package.json
.eslintrc.js
README.md
src/
app.controller.spec.ts
app.controller.ts
app.module.ts
app.service.ts
controller/
deviation.controller.ts
stats.controller.ts
crypto-data/
crypto-data.module.ts
crypto-data.service.spec.ts
crypto-data.service.ts
schemas/
crypto-data.schema.ts
main.ts
test/
app.e2e-spec.ts
jest-e2e.json
tsconfig.build.json
tsconfig.json
app.module.ts
: The main module of the application.src/app.controller.ts
: The main controller of the application.src/app.service.ts
: The main service of the application.src/controller/
: Contains the controllers for the API endpoints.src/crypto-data/
: Contains the module, service, and schema for handling cryptocurrency data.src/main.ts
: The entry point of the application.
- Clone the repository:
git clone <repository-url>
- Install the dependencies:
npm install
- Create a
.env
file in the root directory and fill it with the following content:
MONGO_USERNAME=<your-mongodb-username>
MONGO_PASSWORD=<your-mongodb-password>
MONGO_DATABASE=<your-mongodb-database>
COINGECKO_API_URL=https://api.coingecko.com/api/v3/simple/price?x_cg_demo_api_key=
COINGECKO_API_KEY=<your-coingecko-api-key>
PORT=3000
- Start the application:
npm run start:dev
- The application will be running at http://localhost:3000.
# unit tests
npm run test
# e2e tests
npm run test:e2e
# test coverage
npm run test:cov