using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Arbitrage { public class Engine { private IDataService mDataService { get; set; } private IEnumerable mNotificationChannels { get; set; } public Engine(IDataService dataService, IEnumerable notificationChannels) { mDataService = dataService; mNotificationChannels = notificationChannels; } public async Task RunAsync(IEnumerable sports) { await mDataService.InitialiseAsync(); foreach (Sport sport in sports) { Dictionary> events = await mDataService.ReconcileSportEventsAsync(sport); foreach ((Event @event, IEnumerable bookkeeperEvents) in events) { Dictionary> markets = await mDataService.ReconcileEventMarketsAsync(@event, bookkeeperEvents); @event.Markets = markets.Keys; foreach ((Market market, IEnumerable bookkeeperMarkets) in markets) { IEnumerable odds = await mDataService.ReconcileMarketOddsAsync(@event, bookkeeperMarkets); market.Odds = odds; if (odds.Any()) { (double arbitrage, IEnumerable bookkeeperOdds) = Calculator.FindBestArbitrage(market); if (arbitrage < 1) { foreach (INotificationChannel notificationChannel in mNotificationChannels) { notificationChannel.Notify(sport, @event, market, bookkeeperMarkets, arbitrage, bookkeeperOdds); } } } } } } } } }