Skip to content

Conversation

@Nikhithaspoojary16
Copy link

Summary
Implemented Exchange Rate Provider for the Czech National Bank (CNB).

Used .NET 8.0 (LTS) — the current enterprise-supported release.

Key Features

  • Fetches real CNB daily exchange rates from public TXT feed.
  • Detects decimal separator style (comma or dot) dynamically.
  • Parses, normalizes, and converts rates per currency (per 1 unit).
  • Uses HttpClientFactory, dependency injection, and logging.
  • Configurable currencies, URL, and timeout.
  • Adds caching to reduce network calls.

Files

Program.cs :Entry point of the app. Sets up Dependency Injection (DI), logging, configuration, and orchestrates execution. Fetches the CNB payload once, detects decimal style (comma or dot), and prints formatted exchange rates.

Config/AppConfig.cs:
Holds strongly typed configuration (ExchangeRateSettings) with validation rules for the CNB URL, timeout, and currencies list. Ensures misconfiguration fails fast.

Models/Currency.cs: Immutable record representing a three-letter ISO currency code (e.g., EUR, USD).

Models/ExchangeRate.cs: Immutable record representing a rate pair (e.g., EUR/CZK=25.123456). Used to store per-unit rates between two currencies

Services/CnbClient.cs: Handles HTTP requests to the Czech National Bank (CNB) API using HttpClientFactory. Logs timeouts, network errors, and cancellations. Uses HttpTimeoutSeconds from config.

Services/CnbParser.cs: reads the CNB .txt file (pipe-separated). Handles header skipping, trimming, number normalization, and invalid rows. Detects whether the file uses comma or dot decimals (DetectCulture helper).

Services/ExchangeRateProvider.cs: Core business logic. Fetches data via the client, parses it, computes per-unit exchange rates.

Services/ICnbClient.cs, ICnbParser.cs, IExchangeRateProvider.cs: Interfaces for clean architecture and testability.

Appsettings.json: Central configuration file. Defines CNB URL, HTTP timeout, logging levels, and list of currencies to fetch. Can be changed without recompiling.

CNB Sources
-English: https://www.cnb.cz/en/.../daily.txt (dot decimals)

  • Czech: https://www.cnb.cz/cs/.../denni_kurz.txt (comma decimals)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant