Skip to content

Akhror/crypto-rating-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Crypto Rating API

A .NET Web API that fetches historical cryptocurrency price data from CoinGecko and computes a rating for each coin based on a custom algorithm.


Overview

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.


Features

  • Fetches historical coin data via the CoinGecko API /coins/{id}/history endpoint
  • 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

Technologies Used

  • .NET 9
  • ASP.NET Core Web API
  • SQLite for local data storage
  • Swashbuckle for Swagger/OpenAPI documentation
  • HttpClient for external API calls

Getting Started

Prerequisites

  • .NET SDK
  • (Optional) SQLite client/viewer to inspect the database file

Running the API

  1. Clone the repo:

    git clone https://github.com/akhror/crypto-rating-api.git
    cd crypto-rating-api
    
  2. Build and run: dotnet run You can also open the solution file and press F5 in Visual Studio.

  3. 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.

  4. 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.


API Endpoints

POST /fetch

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


GET /rating?startsWith={letter}

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 }, ... ]


Rating Algorithm Details

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.


Project Structure

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


Notes

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.

Error handling and retries could be improved with more time.

Potential Improvements

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.


Contact

For questions or feedback, please open an issue in the GitHub repo.

About

A .NET Web API that fetches historical cryptocurrency price data from CoinGecko and computes a rating for each coin based on a custom algorithm.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages