The Cryptocurrency Tracker API allows users to fetch real-time cryptocurrency data, manage their portfolios, and gain insights into their investments. This README provides instructions for running the application locally and testing the API.
- Node.js (v16 or later)
- An API key for CoinMarketCap (https://coinmarketcap.com/api/)
git clone https://github.com/mwongess/cryptocurrency-tracker-api.git
cd cryptocurrency-tracker-api
Create a .env
file in the root directory and populate it with the following:
HOST=http://localhost
PORT=3000
API_KEY=
Build the Docker image and run the container using the following commands:
docker compose up --build
http://35.92.155.164:3000/api-docs/
The API is documented using Swagger. Once the application is running, visit:
http://localhost:3000/api-docs
http://35.92.155.164:3000/api-docs //Deployed Api
- URL:
GET /api/cryptocurrencies
- Description: Fetches the latest cryptocurrency prices and stores them in the database. Returns the top 10 cryptocurrencies sorted by market cap.
- Response:
{ "message": "Top 10 cryptocurrencies", "data": [ { "symbol": "BTC", "name": "Bitcoin", "price": 50000, "market_cap": 1000000000 } ] }
- URL:
POST /api/portfolio
- Description: Creates a new portfolio entry for a user.
- Body:
{ "userId": "12345", "symbol": "BTC", "quantity": 2, "purchasePrice": 45000 }
- Response:
{ "userId": "12345", "symbol": "BTC", "quantity": 2, "purchasePrice": 45000 }
- URL:
GET /api/portfolio?userId=<userId>
- Description: Fetches the portfolio for a user, including current values.
- Response:
[ { "userId": "12345", "symbol": "BTC", "quantity": 2, "purchasePrice": 45000, "currentPrice": 50000, "totalValue": 100000 } ]
- URL:
PUT /api/portfolio/{id}
- Description: Updates an existing portfolio entry.
- Body:
{ "quantity": 3, "purchasePrice": 47000 }
- Response:
{ "userId": "12345", "symbol": "BTC", "quantity": 3, "purchasePrice": 47000 }
- URL:
DELETE /api/portfolio/{id}
- Description: Deletes a portfolio entry.
- Response:
{ "message": "Portfolio entry deleted successfully." }
- URL:
GET /api/portfolio/insights?userId=<userId>
- Description: Retrieves insights about the user's portfolio.
- Response:
{ "totalValue": 91388.33261029968, "totalGainLoss": 91147.33261029968, "percentageGainLoss": "37820.47", "insights": [] }