RateTableBuilder Class
Definition
- Namespace
- Bodu.Financial.ExchangeRates
- Assembly
- Bodu.Financial.dll
- Package
- Bodu.Financial 1.0.0
- Source
- RateTableBuilder.cs
Provides a mutable collection of RateSeriesBuilder instances keyed by currency pair and provider, intended for assembling rate observations across many series before producing immutable snapshots.
public sealed class RateTableBuilder
- Inheritance
-
RateTableBuilder
- Inherited Members
- Extension Methods
Remarks
The table delegates per-series mutation to the underlying RateSeriesBuilder instances, so single-observation edits, bulk import, and snapshot semantics behave identically to working with a builder directly. The table itself adds only the multi-series indexing, lazy creation, and bulk snapshot operations.
Instances are not thread-safe; concurrent mutation requires external synchronisation.
using Bodu.Financial.Currencies;
using Bodu.Financial.ExchangeRates;
var builder = new RateTableBuilder();
builder.Upsert(new CurrencyPair(CurrencyCode.AUD, CurrencyCode.USD), "SampleData", new DateOnly(2024, 3, 15), 0.6580m);
builder.Upsert(new CurrencyPair(CurrencyCode.AUD, CurrencyCode.EUR), "SampleData", new DateOnly(2024, 3, 15), 0.6196m);
// Freeze every series into an immutable book, then wrap it in a dated provider.
var rates = new FixedDatedRateProvider(builder.ToBook());
RateLookupResult usd = rates.GetRate("AUD", "USD", new DateOnly(2024, 3, 15));
Constructors
RateTableBuilder()
Initializes a new instance of the RateTableBuilder class with no series.
public RateTableBuilder()
Properties
Count
Gets the number of series currently tracked.
public int Count { get; }
Property Value
- int
A non-negative series count.
Keys
Gets the set of keys currently tracked.
public IEnumerable<RateSeriesKey> Keys { get; }
Property Value
- IEnumerable<RateSeriesKey>
An enumeration of RateSeriesKey values in dictionary order.
Methods
ContainsSeries(CurrencyPair, string)
Reports whether the table tracks a series for the supplied pair and provider.
public bool ContainsSeries(CurrencyPair pair, string provider)
Parameters
pairCurrencyPairThe currency pair.
providerstringThe non-empty identifier of the publishing source.
Returns
Exceptions
- ArgumentNullException
Thrown if
provideris null.- ArgumentException
Thrown if
provideris empty or white-space.
GetOrAddSeries(CurrencyPair, string)
Returns the builder for the supplied pair and provider, creating an empty one if it does not yet exist.
public RateSeriesBuilder GetOrAddSeries(CurrencyPair pair, string provider)
Parameters
pairCurrencyPairThe currency pair.
providerstringThe non-empty identifier of the publishing source.
Returns
- RateSeriesBuilder
The existing or freshly created builder.
Exceptions
- ArgumentNullException
Thrown if
provideris null.- ArgumentException
Thrown if
provideris empty or white-space.
Remove(CurrencyPair, string)
Removes the entire series for the supplied pair and provider.
public bool Remove(CurrencyPair pair, string provider)
Parameters
pairCurrencyPairThe currency pair.
providerstringThe non-empty identifier of the publishing source.
Returns
Exceptions
- ArgumentNullException
Thrown if
provideris null.- ArgumentException
Thrown if
provideris empty or white-space.
ToBook()
Produces an immutable RateBook snapshot containing one series per non-empty builder.
public RateBook ToBook()
Returns
- RateBook
A new RateBook indexed by (pair, provider). Empty builders are skipped because an immutable series must contain at least one observation.
Remarks
The returned book preserves multi-provider entries for the same pair, making it the recommended hand-off path when feeding rates into a provider facade.
ToSeries()
Produces immutable snapshots for every non-empty series in the table.
public IReadOnlyList<RateSeries> ToSeries()
Returns
- IReadOnlyList<RateSeries>
A list of RateSeries instances, one per non-empty builder. Empty builders are skipped because an immutable series must contain at least one observation.
TryGetBuilder(CurrencyPair, string, out RateSeriesBuilder?)
Attempts to retrieve the builder for the supplied pair and provider without creating one.
public bool TryGetBuilder(CurrencyPair pair, string provider, out RateSeriesBuilder? builder)
Parameters
pairCurrencyPairThe currency pair.
providerstringThe non-empty identifier of the publishing source.
builderRateSeriesBuilderWhen this method returns true, the existing builder; otherwise null.
Returns
Exceptions
- ArgumentNullException
Thrown if
provideris null.- ArgumentException
Thrown if
provideris empty or white-space.
TryGetSeries(CurrencyPair, string, out RateSeries?)
Attempts to retrieve an immutable snapshot of the series for the supplied pair and provider.
public bool TryGetSeries(CurrencyPair pair, string provider, out RateSeries? series)
Parameters
pairCurrencyPairThe currency pair.
providerstringThe non-empty identifier of the publishing source.
seriesRateSeriesWhen this method returns true, the snapshot; otherwise null.
Returns
- bool
true if a non-empty series snapshot was produced; false if no series existed or it held no observations.
Exceptions
- ArgumentNullException
Thrown if
provideris null.- ArgumentException
Thrown if
provideris empty or white-space.
Upsert(CurrencyPair, string, DateOnly, decimal, DateTimeOffset?)
Upserts an observation into the series identified by pair and provider,
creating the series if it does not yet exist.
public void Upsert(CurrencyPair pair, string provider, DateOnly date, decimal rate, DateTimeOffset? fetchedAtUtc = null)
Parameters
pairCurrencyPairThe currency pair.
providerstringThe non-empty identifier of the publishing source.
dateDateOnlyThe observation date.
ratedecimalThe rate to record.
fetchedAtUtcDateTimeOffset?The UTC instant at which the load contributing this observation downloaded its source data, or null to leave the series' fetch instant unchanged.
Remarks
When supplied, fetchedAtUtc is recorded at the series grain - a property of the load, not of
the individual observation - and is stamped onto every ExchangeRate the series materializes. A
later upsert carrying a fresh instant overwrites it; passing null leaves any previously
recorded instant in place.
Exceptions
- ArgumentNullException
Thrown if
provideris null.- ArgumentException
Thrown if
provideris empty or white-space.- ArgumentOutOfRangeException
Thrown if
rateis zero or negative.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |