A .NET Web API that fetches historical cryptocurrency price data from CoinGecko and computes a rating for each coin based on a custom algorithm.
This API ingests historical price data for 20 popular cryptocurrencies on two fixed dates (01-06-2025 and 01-07-2025), stores it locally in an SQLite database, and calculates a rating (0–100) for each coin using:
- Base score of 50
- Adjustment based on price percentage change between the two dates
- Penalty if coin ID is shorter than 6 characters
- Bonus if coin ID starts with the letter 't'
The results are exposed through a REST API with optional filtering.
- Fetches historical coin data via the CoinGecko API
/coins/{id}/historyendpoint - Stores data locally in SQLite for persistence
- Calculates coin ratings with a defined business algorithm
- API endpoint to retrieve ratings, filterable by coin ID starting letter
- Swagger UI for interactive API exploration and testing
- Manual trigger endpoint to fetch and update data
- .NET 9
- ASP.NET Core Web API
- SQLite for local data storage
- Swashbuckle for Swagger/OpenAPI documentation
- HttpClient for external API calls
- .NET SDK
- (Optional) SQLite client/viewer to inspect the database file
-
Clone the repo:
git clone https://github.com/akhror/crypto-rating-api.git cd crypto-rating-api -
Build and run: dotnet run You can also open the solution file and press F5 in Visual Studio.
-
Open your browser and navigate to: https://localhost:7053/swagger (or http://localhost:5115/swagger) This opens Swagger UI for interactive API documentation and testing.
-
In Swagger to fetch data from CoinGecko API look for the Fetch section. Click POST /fetch → Try it out → Execute Fetching data from the CoinGecko API and saving it into the SQLite database may take approximately 9 minutes. This is due to a deliberate 15-second delay between requests to avoid hitting CoinGecko's rate limit and receiving HTTP 429 (Too Many Requests) errors.
Additionally, CoinGecko does not provide data for nopecoin, so only 19 out of the 20 specified coins will be successfully retrieved and stored.
Trigger the service to fetch historical price data for all 20 coins for the fixed dates and store the results locally.
Request body: None
Response: JSON summary of fetched data
Retrieve calculated ratings for all coins.
Query Parameters:
startsWith (optional): Filter coins whose IDs start with this letter (case-insensitive)
For example: https://localhost:7053/rating
https://localhost:7053/rating?startsWith=b
Response:
[ { "id": "bitcoin", "rating": 52 }, { "id": "bittensor", "rating": 28 }, ... ]
Start with a base rating of 50.
Calculate the percentage price change between 01-06-2025 and 01-07-2025.
If the price increased, add that percentage to the rating (max 100).
If decreased, subtract that percentage from the rating (min 0).
Subtract 10 points if the coin ID has fewer than 6 characters.
Add 15 points if the coin ID starts with the letter 't'.
Clamp the final rating between 0 and 100.
Controllers/ – API controllers (FetchController, RatingController)
Services/ – Business logic services (DataFetchService, RatingService)
Data/ – Repository for database access (CoinRepository)
Models/ – Data models (CoinHistoryRecord)
Program.cs – Application setup and DI configuration
The app uses HTTPS redirection for secure communication.
Swagger is enabled only in development environment.
SQLite database file is named coin_history.db and created in the app directory.
The fetch endpoint includes a delay between API calls to avoid rate limiting.
Add authentication and authorization for secure API access.
Implement unit and integration tests.
Use background jobs (e.g., hosted service or cron) for automatic data refresh.
Enhance error handling and logging.
Support dynamic date parameters for fetching historical data.
Add sorting to the /rating endpoint.
For questions or feedback, please open an issue in the GitHub repo.