private ExchangeQuality SwitchPrimaryExchange(string assetPairId, [CanBeNull] ExchangeQuality oldPrimary, ImmutableDictionary <string, ExchangeQuality> exchangeQualities, Func <ExchangeQuality, string> alertMessage) { var newPrimary = ChooseBackupExchange(assetPairId, exchangeQualities); if (newPrimary.ExchangeName == oldPrimary?.ExchangeName) { Trace.Write(TraceLevelGroupEnum.WarnTrace, assetPairId, $"Current exchange {oldPrimary.ExchangeName} is bad, but switch failed", new { Event = "ExchangeSwitchFailed", Reason = "No valid hedgable exchanges", oldPrimary.ExchangeName }); return(oldPrimary); } _primaryExchanges[assetPairId] = newPrimary.ExchangeName; _alertService.AlertPrimaryExchangeSwitched( new PrimaryExchangeSwitchedMessage { AssetPairId = assetPairId, AllExchangesStates = exchangeQualities.Values.Select(Convert).ToImmutableArray(), NewPrimaryExchange = Convert(newPrimary), }); _alertService.AlertRiskOfficer(assetPairId, alertMessage(newPrimary), EventTypeEnum.PrimaryExchangeChanged); return(newPrimary); }
private ExtPriceStatusModel Convert(string assetPairId, string exchangeName, ExchangeQuality exchangeQuality, bool isPrimary, BestPrices bestPrice) { var model = _convertService.Convert <ExchangeQuality, ExtPriceStatusModel>(exchangeQuality, o => o.ConfigureMap(MemberList.Source)); model.AssetPairId = assetPairId; model.ExchangeName = exchangeName; model.IsPrimary = isPrimary; model.ErrorState = model.ErrorState ?? "NoOrderbook"; model.BestPrices = _convertService.Convert <BestPrices, BestPricesModel>(bestPrice); return(model); }
private void LogCycle(ExternalOrderbook orderbook, [CanBeNull] Orderbook resultingOrderbook, Stopwatch watch, ExchangeQuality primaryExchangeQuality, [CanBeNull] string problem) { var elapsedMilliseconds = watch.ElapsedMilliseconds; if (elapsedMilliseconds > 20) { _telemetryService.PublishEventMetrics(nameof(GenerateOrderbookService) + '.' + nameof(OnNewOrderbook), null, new Dictionary <string, double> { { "ProcessingTime", elapsedMilliseconds } }, new Dictionary <string, string> { { "AssetPairId", orderbook.AssetPairId }, { "Exchange", orderbook.ExchangeName }, { "IsPrimary", (orderbook.ExchangeName == primaryExchangeQuality.ExchangeName).ToString() }, { "IsSkip", (resultingOrderbook == null).ToString() }, }); } var bestPrices = _bestPricesService.Calc(orderbook); var resultingBestPrices = resultingOrderbook == null ? null : _bestPricesService.Calc(resultingOrderbook); var action = resultingOrderbook == null ? "Skipped" : "Processed"; Trace.Write(TraceLevelGroupEnum.Trace, orderbook.AssetPairId, $"{action} from {orderbook.ExchangeName}, " + $"primary: {primaryExchangeQuality}, time: {elapsedMilliseconds} ms", new { Event = "ExternalOrderbook" + action, Reason = problem, orderbook.ExchangeName, PrimaryExchange = primaryExchangeQuality, ElapsedMilliseconds = elapsedMilliseconds, IsSkip = resultingOrderbook == null, bestPrices.BestBid, bestPrices.BestAsk, ResultingBestBid = resultingBestPrices?.BestBid, ResultingBestAsk = resultingBestPrices?.BestAsk, BidsDepth = orderbook.Bids.Length, AsksDepth = orderbook.Asks.Length, ResultingsBidsDepth = resultingOrderbook?.Bids.Length, ResultingsAsksDepth = resultingOrderbook?.Asks.Length, }); }
private ExchangeQualityMessage Convert(ExchangeQuality quality) { return(_convertService.Convert <ExchangeQuality, ExchangeQualityMessage>(quality)); }