public void Setup() { this._missingMarketDataResponse = new MarketDataResponse <EquityInstrumentIntraDayTimeBar>(null, true, false); this._notMissingMarketDataResponse = new MarketDataResponse <EquityInstrumentIntraDayTimeBar>(null, false, false); }
public override async Task <MarketDataResponse> GetMarketData(Empty request, ServerCallContext context) { var response = new MarketDataResponse(); var data = await _redisService.GetMarketDataAsync(); response.Items.AddRange(data); return(response); }
public void Filter_WhenUniverseEventAndMarketCapFilter_MustFilterCorrectly( decimal?marketCap, decimal?min, decimal?max, bool mustBeFiltered) { A.CallTo( () => this.currencyConverterService.Convert( A <IReadOnlyCollection <Money> > .Ignored, A <Currency> .Ignored, A <DateTime> .Ignored, A <ISystemProcessOperationRunRuleContext> .Ignored)).Returns(new Money(marketCap.Value, "GBP")); var fundOne = ((Order)null).Random(); var eventOne = new UniverseEvent(UniverseStateEvent.Order, DateTime.UtcNow, fundOne); A.CallTo(() => _tradingHoursService.GetTradingHoursForMic(fundOne.Market.MarketIdentifierCode)) .Returns(new TradingHours() { IsValid = true }); //decimal? marketCap = 150; var marketDataResponse = new MarketDataResponse <EquityInstrumentInterDayTimeBar>( new EquityInstrumentInterDayTimeBar(null, new DailySummaryTimeBar(marketCap, "GBP", null, null, new Volume(), DateTime.UtcNow), DateTime.UtcNow, null), false, false); A.CallTo(() => _universeEquityInterDayCache.Get( A <MarketDataRequest> .That.Matches( m => m.MarketIdentifierCode == fundOne.Market.MarketIdentifierCode && m.Cfi == fundOne.Instrument.Cfi ))) .Returns(marketDataResponse); var marketCapRangeRuleFilter = new DecimalRangeRuleFilter { Type = RuleFilterType.Include, Min = min, Max = max }; var highMarketCapFilter = new HighMarketCapFilter( _universeMarketCacheFactory, Engine.Rules.Rules.RuleRunMode.ValidationRun, marketCapRangeRuleFilter, _tradingHoursService, _operationRunRuleContext, _universeDataRequestsSubscriber, this.currencyConverterService, "test", _logger); var result = highMarketCapFilter.Filter(eventOne); Assert.AreEqual(result, mustBeFiltered); }
public MarketDataResponse <EquityInstrumentIntraDayTimeBar> GetForLatestDayOnly(MarketDataRequest request) { if (request == null || !request.IsValid()) { this._logger.LogError("UniverseMarketCache received either a null or invalid request"); return(MarketDataResponse <EquityInstrumentIntraDayTimeBar> .MissingData()); } this._logger.LogInformation( $"UniverseMarketCache fetching for market {request?.MarketIdentifierCode} from {request?.UniverseEventTimeFrom} to {request?.UniverseEventTimeTo} as part of rule run {request?.SystemProcessOperationRuleRunId}"); if (!this._latestExchangeFrameBook.ContainsKey(request.MarketIdentifierCode)) { this._dataRequestRepository.CreateDataRequest(request); this._logger.LogInformation( $"UniverseMarketCache was not able to find the MIC {request.MarketIdentifierCode} in the latest exchange frame book. Recording missing data."); return(MarketDataResponse <EquityInstrumentIntraDayTimeBar> .MissingData()); } this._latestExchangeFrameBook.TryGetValue(request.MarketIdentifierCode, out var exchangeFrame); if (exchangeFrame == null) { this._dataRequestRepository.CreateDataRequest(request); this._logger.LogInformation( $"UniverseMarketCache was not able to find the MIC {request.MarketIdentifierCode} in the latest exchange frame book. Recording missing data."); return(MarketDataResponse <EquityInstrumentIntraDayTimeBar> .MissingData()); } var security = exchangeFrame.Securities.FirstOrDefault(sec => Equals(sec.Security.Identifiers, request.Identifiers)); if (security == null) { this._dataRequestRepository.CreateDataRequest(request); this._logger.LogInformation( $"UniverseMarketCache was not able to find the security {request.Identifiers} for MIC {request.MarketIdentifierCode} in the latest exchange frame book. Recording missing data."); return(MarketDataResponse <EquityInstrumentIntraDayTimeBar> .MissingData()); } if (exchangeFrame.Epoch > request.UniverseEventTimeTo || exchangeFrame.Epoch < request.UniverseEventTimeFrom) { this._dataRequestRepository.CreateDataRequest(request); this._logger.LogInformation( $"UniverseMarketCache was not able to find the security {request.Identifiers} for MIC {request.MarketIdentifierCode} in the latest exchange frame book within a suitable data range to {request.UniverseEventTimeTo} from {request.UniverseEventTimeFrom}. Recording missing data."); return(MarketDataResponse <EquityInstrumentIntraDayTimeBar> .MissingData()); } this._logger.LogInformation( $"UniverseMarketCache was able to find a match for {request.Identifiers} returning data."); return(new MarketDataResponse <EquityInstrumentIntraDayTimeBar>(security, false, false)); }
public void Initialize() { FakeMarketOrderRepository.Initialize(); _dataResponse = new MarketDataResponse { BuyOrders = FakeMarketOrderRepository.BuyOrders, SellOrders = FakeMarketOrderRepository.SellOrders }; MarketDataResponse.ResequenceOrders(_dataResponse); }
public void Filter_WhenUniverseEventAndHadMissingDataInUniverseEquityInterdayCache_MustBeFiltered() { var fundOne = ((Order)null).Random(); var eventOne = new UniverseEvent(UniverseStateEvent.Order, DateTime.UtcNow, fundOne); A.CallTo(() => _tradingHoursService.GetTradingHoursForMic(fundOne.Market.MarketIdentifierCode)) .Returns(new TradingHours() { IsValid = true }); A.CallTo(() => _universeEquityInterDayCache.Get( A <MarketDataRequest> .That.Matches( m => m.MarketIdentifierCode == fundOne.Market.MarketIdentifierCode && m.Cfi == fundOne.Instrument.Cfi ))) .Returns(MarketDataResponse <EquityInstrumentInterDayTimeBar> .MissingData()); var marketCapRangeRuleFilter = new DecimalRangeRuleFilter { Type = RuleFilterType.Include }; var highMarketCapFilter = new HighMarketCapFilter( _universeMarketCacheFactory, Engine.Rules.Rules.RuleRunMode.ValidationRun, marketCapRangeRuleFilter, _tradingHoursService, _operationRunRuleContext, _universeDataRequestsSubscriber, this.currencyConverterService, "test", _logger); var result = highMarketCapFilter.Filter(eventOne); Assert.IsTrue(result); }
private void Analyze(IProgress <int> progress) { int index = 0; var itemTasks = new List <Task>(); foreach (var item in _storeItems) { itemTasks.Add(Task.Factory.StartNew(() => { using (MarketDataHelper helper = new MarketDataHelper(MarketDataHelper.QuickLook)) { MarketDataRequest request = new MarketDataRequest { TypeId = item.ItemId.ToString(), SystemId = MarketDataHelper.Jita, Duration = MarketDataHelper.Freshness }; var productData = helper.GetData(request); MarketDataResponse.ResequenceOrders(productData); var order = productData.HighestBuyOrder; item.Product.Data = productData; item.Product.Price = order != null ? order.Price : 0.0; item.MarketPrice = order != null ? order.Price : 0.0; item.ProfitMargin = item.MarketPrice - item.StorePrice; item.ProfitEfficiency = item.ProfitMargin / item.Points; item.UpdateProperties(); var currentProgress = ((double)++index / _storeItems.Count) * 100; progress.Report((int)currentProgress); } }, TaskCreationOptions.AttachedToParent)); } Task.Factory.ContinueWhenAll(itemTasks.ToArray(), groupedTasks => { AnalysisInProgress = false; }); }
/// <summary> /// Assumes that any data implies that the whole data set/range is covered /// </summary> public MarketDataResponse <List <EquityInstrumentIntraDayTimeBar> > GetMarkets(MarketDataRequest request) { if (request == null || !request.IsValid()) { this._logger.LogError("UniverseMarketCache received either a null or invalid request"); return(MarketDataResponse <List <EquityInstrumentIntraDayTimeBar> > .MissingData()); } if (!this._marketHistory.TryGetValue(request.MarketIdentifierCode, out var marketStack)) { this._logger.LogInformation( $"UniverseMarketCache GetMarkets was not able to find a market history entry for {request.MarketIdentifierCode}"); this._dataRequestRepository.CreateDataRequest(request); return(MarketDataResponse <List <EquityInstrumentIntraDayTimeBar> > .MissingData()); } var securityDataTicks = marketStack.ActiveMarketHistory().Where(amh => amh != null) .Select( amh => amh.Securities?.FirstOrDefault(sec => Equals(sec.Security.Identifiers, request.Identifiers))) .Where(sec => sec != null).Where(sec => sec.TimeStamp <= request.UniverseEventTimeTo) .Where(sec => sec.TimeStamp >= request.UniverseEventTimeFrom).ToList(); if (!securityDataTicks.Any()) { this._logger.LogInformation( $"UniverseMarketCache GetMarkets was not able to find market data for the security on {request.MarketIdentifierCode} with ids {request.Identifiers}"); this._dataRequestRepository.CreateDataRequest(request); return(MarketDataResponse <List <EquityInstrumentIntraDayTimeBar> > .MissingData()); } this._logger.LogInformation( $"UniverseMarketCache GetMarkets was able to find a market history entry for {request.MarketIdentifierCode} and id {request.Identifiers}"); return(new MarketDataResponse <List <EquityInstrumentIntraDayTimeBar> >(securityDataTicks, false, false)); }
public FixedIncomeInterDayMarketDataResponse(MarketDataResponse <FixedIncomeInstrumentInterDayTimeBar> response) { this._response = response ?? throw new ArgumentNullException(nameof(response)); }
public void Setup() { _responseMissingData = new MarketDataResponse <EquityInstrumentInterDayTimeBar>(null, true, false); _responseNoMissingData = new MarketDataResponse <EquityInstrumentInterDayTimeBar>(null, false, false); }
private void Analyze(IProgress <AnalysisResult> progress) { int index = 0; var itemTasks = new List <Task>(); foreach (var item in AnalysisItems) { itemTasks.Add(Task.Factory.StartNew(() => { using (MarketDataHelper helper = new MarketDataHelper(MarketDataHelper.QuickLook)) { MarketDataRequest request = new MarketDataRequest { TypeId = item.Product.ItemId.ToString(), SystemId = MarketDataHelper.Jita, Duration = MarketDataHelper.Freshness }; var productData = helper.GetData(request); MarketDataResponse.ResequenceOrders(productData); var order = productData.HighestBuyOrder; item.Product.Price = order != null ? order.Price : 0.0; item.Product.ExportCost = ProductionHelper.GetExportCost(ProductionLevel); item.Product.OutputBatchSize = ProductionHelper.GetOutputBatchSize(ProductionLevel); item.Product.Data = productData; foreach (var input in item.Materials) { request = new MarketDataRequest { TypeId = input.ItemId.ToString(), Duration = MarketDataHelper.Freshness, SystemId = MarketDataHelper.Jita }; var materialData = helper.GetData(request); MarketDataResponse.ResequenceOrders(materialData); order = materialData.LowestSellOrder(null); input.Price = order != null ? order.Price : 0.0; input.ImportCost = ProductionHelper.GetImportCost(input.InputLevel); input.InputBatchSize = ProductionHelper.GetInputBatchSize(input.InputLevel); input.Data = materialData; } var productionResult = ProductionHelper.Calculate(item.Product, item.Materials); item.ProductionCost = productionResult.PurchaseCost; item.SaleValue = productionResult.SaleCost; item.ProfitMargin = productionResult.ProfitMargin; item.UpdateProperties(); var currentProgress = ((double)++index / AnalysisItems.Count) * 100; progress.Report(new AnalysisResult { ProgressIndex = (int)currentProgress, Item = item }); Task.Delay(2000).Wait(); } }, TaskCreationOptions.AttachedToParent)); } Task.Factory.ContinueWhenAll(itemTasks.ToArray(), groupedTasks => { }); }
/// <summary> /// The interday market traded volume. /// </summary> /// <param name="securityResult"> /// The security result. /// </param> /// <returns> /// The <see cref="long"/>. /// </returns> private long InterdayMarketTradedVolume(MarketDataResponse <List <EquityInstrumentInterDayTimeBar> > securityResult) { var marketTradedVolume = securityResult.Response.Sum(_ => _.DailySummaryTimeBar.DailyVolume.Traded); return(marketTradedVolume); }
/// <summary> /// The intraday market traded volume. /// </summary> /// <param name="securityResult"> /// The security result. /// </param> /// <returns> /// The <see cref="long"/>. /// </returns> private long IntradayMarketTradedVolume(MarketDataResponse <List <EquityInstrumentIntraDayTimeBar> > securityResult) { var marketTradedVolume = securityResult.Response.Sum(_ => _.SpreadTimeBar.Volume.Traded); return(marketTradedVolume); }
public MarketDataResponse <List <EquityInstrumentIntraDayTimeBar> > GetMarketsForRange( MarketDataRequest request, IReadOnlyCollection <DateRange> dates, RuleRunMode runMode) { dates = dates?.Where(dat => dat != null)?.ToList(); if (dates == null || !dates.Any()) { this._logger.LogError( "UniverseMarketCache GetMarketsForRange received either a null or invalid request (dates)"); return(MarketDataResponse <List <EquityInstrumentIntraDayTimeBar> > .MissingData()); } if (request == null || !request.IsValid()) { this._logger.LogError( "UniverseMarketCache GetMarketsForRange received either a null or invalid request"); return(MarketDataResponse <List <EquityInstrumentIntraDayTimeBar> > .MissingData()); } var projectedRequests = dates.Select( i => new MarketDataRequest( null, request.MarketIdentifierCode, request.Cfi, request.Identifiers, i.Start, i.End, request.SystemProcessOperationRuleRunId, request.IsCompleted, DataSource.AnyIntraday)).ToList(); var responseList = new List <MarketDataResponse <List <EquityInstrumentIntraDayTimeBar> > >(); foreach (var paramSet in projectedRequests) { responseList.Add(this.GetMarkets(paramSet)); } if (!responseList.Any()) { this._logger.LogInformation( $"UniverseMarketCache GetMarketsForRange had missing data for rule run id {request.SystemProcessOperationRuleRunId}"); return(MarketDataResponse <List <EquityInstrumentIntraDayTimeBar> > .MissingData()); } if (runMode == RuleRunMode.ValidationRun && responseList.Any(o => o.HadMissingData)) { this._logger.LogInformation( $"UniverseMarketCache GetMarketsForRange was running a validation run and had missing data for rule run id {request.SystemProcessOperationRuleRunId}"); return(MarketDataResponse <List <EquityInstrumentIntraDayTimeBar> > .MissingData()); } var isMissingData = responseList.Any(o => o.HadMissingData); var responses = responseList.Where(i => i.Response != null).SelectMany(i => i.Response).ToList(); if (isMissingData) { this._logger.LogInformation( $"UniverseMarketCache GetMarketsForRange was running and had missing data for rule run id {request.SystemProcessOperationRuleRunId} but is proceeding on a best effort basis"); } // hide that we're missing data from the consumer return(new MarketDataResponse <List <EquityInstrumentIntraDayTimeBar> >(responses, false, true)); }
public EquityIntraDayMarketDataResponse(MarketDataResponse <EquityInstrumentIntraDayTimeBar> response) { this._response = response ?? throw new ArgumentNullException(nameof(response)); }