private async Task EnrichBondWithRicFromTr(IEnumerable <SecurityEnrichmentDto> bondsWithoutRrpsRic) { try { if (!bondsWithoutRrpsRic.Any()) { return; } foreach (var bond in bondsWithoutRrpsRic) { var request = new GetEnrichmentIdentifierRequest { Identifiers = new SecurityIdentifiers { Isin = bond.Isin } }; this._logger.LogInformation($"EnrichBondWithRicFromTr requesting Ric for Isin {bond.Isin}."); var tickPriceHistoryServiceClient = _tickPriceHistoryServiceClientFactory.Create(); var result = await tickPriceHistoryServiceClient.GetEnrichmentIdentifierAsync(request); bond.Ric = result.Identifiers.Select(s => s.Ric).FirstOrDefault(); this._logger.LogInformation($"EnrichBondWithRicFromTr found Ric {bond.Ric} for Isin {bond.Isin}."); } } catch (Exception ex) { this._logger.LogError(ex, "Error while enriching RIC from TR"); } }
public async Task Handle(string systemProcessOperationId, ISystemProcessOperationThirdPartyDataRequestContext dataRequestContext, IReadOnlyCollection <MarketDataRequest> marketDataRequests) { if (marketDataRequests == null || !marketDataRequests.Any()) { this._logger.LogError($"{nameof(RefinitivDataSynchroniser)} Handle received a null or empty market data request collection"); return; } var maxToDate = marketDataRequests.Select(a => a.UniverseEventTimeTo).Max(); var minFromDate = marketDataRequests.Select(a => a.UniverseEventTimeFrom).Min(); if (maxToDate != null && minFromDate != null) { var request = new GetEodPricingRequest { StartUtc = minFromDate.Value.ToUniversalTime().ToTimestamp(), EndUtc = maxToDate.Value.ToUniversalTime().ToTimestamp(), PollPeriod = _refinitivTickPriceHistoryApiConfig.RefinitivTickPriceHistoryApiPollingSeconds, TimeOut = new Duration() { Seconds = _refinitivTickPriceHistoryApiConfig.RefinitivTickPriceHistoryApiTimeOutDurationSeconds }, }; var ids = marketDataRequests.Select(req => new SecurityIdentifiers() { Ric = req.Identifiers.Ric, Cusip = req.Identifiers.Cusip, Isin = req.Identifiers.Isin, Sedol = req.Identifiers.Sedol }); request.Identifiers.AddRange(ids); if (request.Identifiers.All(s => s.Ric == null)) { this._logger.LogError($"{nameof(RefinitivDataSynchroniser)} Handle received a request that didn't have a RIC"); return; } this._logger.LogInformation($"{nameof(RefinitivDataSynchroniser)} Making request for the date range of {request.StartUtc} - {request.EndUtc} using the following RIC identifiers: " + $"{string.Join(" ", request.Identifiers.Select(s => s.Ric).ToArray())}"); var tickPriceHistoryServiceClient = _tickPriceHistoryServiceClientFactory.Create(); await tickPriceHistoryServiceClient.GetEodPricingAsync(request); this._logger.LogInformation($"{nameof(RefinitivDataSynchroniser)} Request returned for the date range of {request.StartUtc} - {request.EndUtc} using the following RIC identifiers: " + $"{string.Join(" ", request.Identifiers.Select(s => s.Ric).ToArray())}"); } else { this._logger.LogError($"{nameof(RefinitivDataSynchroniser)} Handle received a request collection with no dates"); return; } }
public async Task <IList <EndOfDaySecurityTimeBar> > GetInterdayTimeBars(DateTime?startDay, DateTime?endDay, IList <string> rics = null) { var allDayPeriods = SplitDateRangeByDay(startDay.Value, endDay.Value); var result = new List <EndOfDaySecurityTimeBar>(); foreach (var period in allDayPeriods) { var request = new SecurityTimeBarQueryRequest() { }; var requestByRics = rics?.Where(w => !string.IsNullOrEmpty(w)).ToList() ?? new List <string>(); if (!requestByRics.Any()) { requestByRics.Add(null); } var referenceId = Guid.NewGuid().ToString(); Timestamp startUtc = new Timestamp(Timestamp.FromDateTime(DateTime.SpecifyKind(period.Item1, DateTimeKind.Utc))); Timestamp endUtc = new Timestamp(Timestamp.FromDateTime(DateTime.SpecifyKind(period.Item2, DateTimeKind.Utc))); foreach (var item in requestByRics) { var subqueryRequest = new SecurityTimeBarSubqueryRequest() { StartUtc = startUtc, EndUtc = endUtc, ReferenceId = referenceId, PolicyOptions = TimeBarPolicyOptions.EndOfDay }; if (item != null) { subqueryRequest.Identifiers = new SecurityIdentifiers { Ric = item }; } request.Subqueries.Add(subqueryRequest); } var tickPriceHistoryServiceClient = tickPriceHistoryServiceClientFactory.Create(); var response = await tickPriceHistoryServiceClient .QuerySecurityTimeBarsAsync(request).ResponseAsync; foreach (var subResponse in response.SubResponses) { foreach (var timebar in subResponse.Timebars) { var endOfDaySecurityTimeBar = new EndOfDaySecurityTimeBar { SecurityIdentifiers = new SecurityIdentifier { Cusip = subResponse.Identifiers?.Cusip, ExternalId = subResponse.Identifiers.ExternalIdentifiers, Isin = subResponse.Identifiers.Isin, Ric = subResponse.Identifiers.Ric, Sedol = subResponse.Identifiers.Sedol }, TimeBar = MapTimeBar(timebar) }; result.Add(endOfDaySecurityTimeBar); } } var success = response.Success; } return(result); }