Table of Contents

IRateProvider Interface

Definition

Namespace
Bodu.Financial.ExchangeRates
Assembly
Bodu.Financial.dll
Package
Bodu.Financial 1.0.0
Source
IRateProvider.cs

Source of foreign-exchange rates used to convert between currencies.

public interface IRateProvider
Extension Methods

Examples

using Bodu.Financial;

// A minimal static-table implementation of the rate source.
sealed class FixedTable : IRateProvider
{
    public decimal GetRate(string fromIsoCode, string toIsoCode) =>
        (fromIsoCode, toIsoCode) switch
        {
            ("USD", "EUR") => 0.92m,
            ("EUR", "USD") => 1.087m,
            _ => throw new KeyNotFoundException($"{fromIsoCode}->{toIsoCode}"),
        };
}

decimal rate = new FixedTable().GetRate("USD", "EUR");   // 0.92

Remarks

Implementations decide where rates come from: a static table, a daily snapshot, a live ticker, a mid-market computed from bid/ask, and so on. Consumers of ConvertTo<TTarget>(IRateProvider) only need the abstract GetRate(string, string) contract.

Methods

GetRate(string, string)

Returns the exchange rate that converts one unit of fromIsoCode to units of toIsoCode.

decimal GetRate(string fromIsoCode, string toIsoCode)

Parameters

fromIsoCode string

The source currency's ISO 4217 code.

toIsoCode string

The destination currency's ISO 4217 code.

Returns

decimal

The rate.

Exceptions

KeyNotFoundException

No rate is available for the requested pair.

Applies to

ProductVersions
.NET8, 10