mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-01-18 21:32:27 +01:00
6049fa23a7
* Support pluginable rate providers This PR allows plugins to provide custom rate providers, that can be contextual to a store. For example, if you use the upcoming fiat offramp plugin, or the Blink plugin, you'll probably want to configure the fetch the rates from them since they are determining the actual fiat rrate to you. However, they require API keys. This PR enables these scenarios, even much more advanced ones, but for example: * Install fiat offramp plugin * Configure it * You can now use the fiat offramp rate provider (no additional config steps beyond selecting the rate source from the select, or maybe the plugin would automatically set it for you once configured) * Apply suggestions from code review * Simplify * Do not use BackgroundFetcherRateProvider for contextual rate prov --------- Co-authored-by: nicolas.dorier <nicolas.dorier@gmail.com>
42 lines
1.5 KiB
C#
42 lines
1.5 KiB
C#
#nullable enable
|
|
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using BTCPayServer.Rating;
|
|
|
|
namespace BTCPayServer.Services.Rates
|
|
{
|
|
public interface IRateProvider
|
|
{
|
|
RateSourceInfo RateSourceInfo { get; }
|
|
/// <summary>
|
|
/// Returns rates of the provider
|
|
/// </summary>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="NotSupportedException">If using this provider isn't supported (For example if a <see cref="IContextualRateProvider"/> requires a context)</exception>
|
|
Task<PairRate[]> GetRatesAsync(CancellationToken cancellationToken);
|
|
}
|
|
|
|
public interface IRateContext { }
|
|
public interface IHasStoreIdRateContext : IRateContext
|
|
{
|
|
string StoreId { get; }
|
|
}
|
|
public record StoreIdRateContext(string StoreId) : IHasStoreIdRateContext;
|
|
|
|
/// <summary>
|
|
/// A rate provider which know additional context about the rate query.
|
|
/// </summary>
|
|
public interface IContextualRateProvider : IRateProvider
|
|
{
|
|
/// <summary>
|
|
/// Returns rates of the provider when a context is available
|
|
/// </summary>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="NotSupportedException">If using this provider isn't getting an expected context</exception>
|
|
Task<PairRate[]> GetRatesAsync(IRateContext context, CancellationToken cancellationToken);
|
|
}
|
|
}
|