public OddsChangeAdapter( ILogger<OddsChangeAdapter> logger, OddsChangeConfiguration oddsChangeConfiguration ) { this.logger = logger; this.oddsChangeConfiguration = oddsChangeConfiguration; }
private static IEnumerable<CreateUpdateMarketsCommand> ConstructCreateUpdateMarketsCommand(MessageContext<OddsChange> messageContext, OddsChangeConfiguration config) { var message = messageContext.Message; var lineService = message.Product.ToLineService(); var marketsBuilder = new List<CreateUpdateMarketsCommandSelection>(); foreach (var market in message.Markets.Where(x => x.Outcomes.Any() == false)) { var specifiers = market.ExtractSpecifiers(); marketsBuilder.Add ( new CreateUpdateMarketsCommandSelection ( marketId: market.GetUniqueId(lineService, message.EventId), selectionId: "*", marketTypeId: market.Id.ToString(), specifiers: specifiers, selectionTypeId: "*", tradingStatus: market.Status.ToMarketTradingStatus(), selectionTradingStatus: null, value: null, probability: null ) ); } foreach (var market in message.Markets.Where(x => !x.Outcomes.Any() == false)) { var marketUniqueId = market.GetUniqueId(lineService, message.EventId); foreach (var outcome in market.Outcomes) { var specifiers = market.ExtractSpecifiers(); var probability = outcome.Probabilities.HasValue ? Convert.ToDecimal(outcome.Probabilities.Value) : default(decimal?); marketsBuilder.Add ( new CreateUpdateMarketsCommandSelection ( marketId: market.GetUniqueId(lineService, message.EventId), selectionId: outcome.GetUniqueId(marketUniqueId), marketTypeId: market.Id.ToString(), specifiers: specifiers, selectionTypeId: outcome.Id, tradingStatus: (outcome.Active && (market.Status == OddsChangeMarketStatus.Active)) ? TradingStatus.Open : TradingStatus.Suspended, selectionTradingStatus: outcome.Active ? TradingStatus.Open : TradingStatus.Closed, value: Convert.ToDecimal(outcome.Odds), probability: probability ) ); } // Max markets in command if (marketsBuilder.Count >= config.MarketCountMax) { yield return new CreateUpdateMarketsCommand( lineService: lineService, gameEventId: message.EventId.ToTransmitterEventId(), receivedOn: messageContext.ReceivedOn, incomingId: messageContext.IncomingId, selections: marketsBuilder.ToImmutableArray(), extraAttributes: null ); marketsBuilder.Clear(); } } // Markets are left or there are no markets at all if (marketsBuilder.Count > 0 || message.Markets.Any() == false) { yield return new CreateUpdateMarketsCommand( lineService: lineService, gameEventId: message.EventId.ToTransmitterEventId(), receivedOn: messageContext.ReceivedOn, incomingId: messageContext.IncomingId, selections: marketsBuilder.ToImmutableArray(), extraAttributes: null ); } }