This applicatio provides a service for cryptocurrency conversion. It uses Express.js as the server framework and MongoDB for data storage. This API also saves the available cryptocurrencies every hour in database to avoid calling the external API multiple times. Also provides functionality to get the list of companies holding the currency.
Yelisetty Karthikeya S M
, aka lurkingryuu
- Clone the repository
- Install the dependencies
- Configure the environment variables
git clone [email protected]:lurkingryuu/cryptocurrency-converter.git
cd cryptocurrency-converter
cp .env.example .env
- Start the server
npm install
npm start
The following environment variables are necessary to run the application:
MONGODB_URL
: The URL of the MongoDB databaseCOINGECKO_API_KEY
: The API key for the CoinGecko API
Other environment variables can be found in the .env.example
file.
- Clone the repository - same as above
- Build the Docker image
- Configure the environment variables - same as above
- Run the Docker container
docker build -t crypto_converter .
docker run -d --env-file .env -p 8080:3000 --name crypto_converter-1 crypto_converter
- Check the health of the API
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
15cdc3e4d5d3 crypto_converter "npm start" About a minute ago Up About a minute (healthy) 0.0.0.0:8080->3000/tcp crypto_converter-1
- Access the API at
http://localhost:8080
- Stop and remove the container after use
docker stop crypto_converter-1
docker rm crypto_converter-1
- Clone the repository - same as above
- Configure the environment variables - according to the
docker-compose.yaml
file - Run the Docker Compose
docker-compose build
docker-compose up -d
- Check the health of the API
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f3640494709e cryptocurrency_converter-app "npm run start" 7 minutes ago Up 7 minutes (healthy) 0.0.0.0:3000->3000/tcp crypto-converter-app
91a941d68da3 mongo:6.0.15-rc0-jammy "docker-entrypoint.s…" 7 minutes ago Up 7 minutes 27017/tcp crypto-converter-db
Optionally, you can check the logs of the API container
docker compose logs -f
- Access the API at
http://localhost:3000
- Stop and remove the containers after use
docker-compose down --volumes
rm -rf ./data
Go to Endpoints for the quick reference.
The APIs can be run in Postman using the collection provided here
The Documentation can be found here.
The API is hosted on azure based on the workflow in the repository and can be accessed koinx.lurkingryuu.me
Alternate link: koinx.azurewebsites.net
This endpoint is used to check the health of the API.
Request:
GET /ping
Response:
HTTP/1.1 200 OK
Content-Type: application/json
"Pong!"
This endpoint is used to convert a cryptocurrency to another cryptocurrency.
Request:
POST /api/convert
{
"fromCurrency": "bitcoin",
"toCurrency": "basic-attention-token",
"date": "12-01-2024"
}
Response:
HTTP/1.1 200 OK
Content-Type: application/json
{
"rate": 176558.73727068843
}
This endpoint is used to get the list of companies holding the currency in descending order based on total holdings.
Request:
POST /api/companies-holding
{
"currency": "ethereum"
}
Response:
HTTP/1.1 200 OK
Content-Type: application/json
{
"count": 2,
"companies": [
"Meitu Inc",
"Mogo Inc."
]
}