diff --git a/Frontend/Marketplaces/Interfaces/IPotatoMarketplace.cs b/Frontend/Marketplaces/Interfaces/IPotatoMarketplace.cs new file mode 100644 index 0000000000000000000000000000000000000000..757223d802fe535e5395f22715d2f3830b54dbb3 --- /dev/null +++ b/Frontend/Marketplaces/Interfaces/IPotatoMarketplace.cs @@ -0,0 +1,13 @@ +using Frontend.Assets; + +namespace Frontend.Marketplaces.Interfaces +{ + public interface IPotatoMarketPlace + { + public double PotatoPrice { get; } + public double PotatoKgToChf(double kg); + public double ChfToPotatoKg(double chf); + public PotatoTransaction Buy(double amountInChf); + public double Sell(PotatoTransaction transaction); + } +} diff --git a/Frontend/Marketplaces/PotatoMarketplaceMock.cs b/Frontend/Marketplaces/PotatoMarketplaceMock.cs new file mode 100644 index 0000000000000000000000000000000000000000..fb3accf14f4242772fef27eeaf06fc3da2bab29e --- /dev/null +++ b/Frontend/Marketplaces/PotatoMarketplaceMock.cs @@ -0,0 +1,32 @@ +using Frontend.Assets; +using Frontend.Marketplaces.Interfaces; + +namespace Frontend.Marketplaces; + +public class PotatoMarketplaceMock() : IPotatoMarketPlace +{ + private const double potatoKgPrice = 2.02; // source: https://www.blw.admin.ch/blw/de/home/markt/marktbeobachtung/kartoffeln.html + + public double PotatoPrice => potatoKgPrice; + + public double ChfToPotatoKg(double chf) + { + return chf / potatoKgPrice; + } + + public double PotatoKgToChf(double kg) + { + return kg * potatoKgPrice; + } + + public PotatoTransaction Buy(double amountInChf) + { + var amountInKg = ChfToPotatoKg(amountInChf); + return new() { Weight = amountInKg }; + } + + public double Sell(PotatoTransaction transaction) + { + return PotatoKgToChf(transaction.Weight); + } +} diff --git a/Frontend/Program.cs b/Frontend/Program.cs index 4e9f8a5981638c79fcff8ae7c56198438e7cbbbe..2bf5552c8fe819b89ce90d843f64cc40c875e541 100644 --- a/Frontend/Program.cs +++ b/Frontend/Program.cs @@ -1,6 +1,8 @@ using Frontend; using Frontend.AssetStores; using Frontend.BackgroundServices; +using Frontend.Marketplaces; +using Frontend.Marketplaces.Interfaces; using Frontend.Metrics; using Microsoft.EntityFrameworkCore; using OpenTelemetry.Metrics; @@ -28,6 +30,7 @@ builder.Services.AddHostedService<PrometheusService>(); builder.Services.AddSingleton<Erc20TokenMetrics>(); builder.Services.AddSingleton<EthMetrics>(); builder.Services.AddSingleton<PotatoStorageMetrics>(); +builder.Services.AddSingleton<IPotatoMarketPlace>(sp => new PotatoMarketplaceMock()); builder.Services.AddSingleton(provider => new TokenClient( chainApiUrl,