/// <summary> /// Gets the hash code /// </summary> /// <returns>Hash code</returns> public override int GetHashCode() { unchecked // Overflow is fine, just wrap { int hashCode = 41; if (Id != null) { hashCode = hashCode * 59 + Id.GetHashCode(); } if (Type != null) { hashCode = hashCode * 59 + Type.GetHashCode(); } if (Priority != null) { hashCode = hashCode * 59 + Priority.GetHashCode(); } if (Name != null) { hashCode = hashCode * 59 + Name.GetHashCode(); } if (Address != null) { hashCode = hashCode * 59 + Address.GetHashCode(); } if (Duration != null) { hashCode = hashCode * 59 + Duration.GetHashCode(); } if (PreparationTime != null) { hashCode = hashCode * 59 + PreparationTime.GetHashCode(); } if (TimeWindows != null) { hashCode = hashCode * 59 + TimeWindows.GetHashCode(); } if (Size != null) { hashCode = hashCode * 59 + Size.GetHashCode(); } if (RequiredSkills != null) { hashCode = hashCode * 59 + RequiredSkills.GetHashCode(); } if (AllowedVehicles != null) { hashCode = hashCode * 59 + AllowedVehicles.GetHashCode(); } if (DisallowedVehicles != null) { hashCode = hashCode * 59 + DisallowedVehicles.GetHashCode(); } if (MaxTimeInVehicle != null) { hashCode = hashCode * 59 + MaxTimeInVehicle.GetHashCode(); } return(hashCode); } }
public string GetAttendanceStatisticsReport(HttpRequestMessage request) { try { var content = request.Content; string j = content.ReadAsStringAsync().Result; TimeWindows timeWindow = new TimeWindows(); timeWindow = JsonConvert.DeserializeObject <TimeWindows>(j); if (timeWindow.admin.check()) { AttendanceStatisticsReport attendanceStatisticsReport = new AttendanceStatisticsReport(); attendanceStatisticsReport.GetAttendanceStatisticsReport(timeWindow.fromDate, timeWindow.toDate); if (attendanceStatisticsReport.registretedCards != null && attendanceStatisticsReport.usedCards != null && attendanceStatisticsReport.totalReturn != null && attendanceStatisticsReport.returnedNewCards != null && attendanceStatisticsReport.returnedOldCards != null && attendanceStatisticsReport.totalReturn != null) { return(JsonConvert.SerializeObject(attendanceStatisticsReport)); } } return(null); } catch (Exception exc) { Console.WriteLine(exc.ToString()); logger.Error(exc.ToString()); return(null); } }
public string GetAttractionReport(HttpRequestMessage request) { try { var content = request.Content; string j = content.ReadAsStringAsync().Result; TimeWindows timeWindow = new TimeWindows(); timeWindow = JsonConvert.DeserializeObject <TimeWindows>(j); if (timeWindow.admin.check()) { AttractionReport attractionReports = new AttractionReport(); attractionReports.GetAttractionReport(timeWindow.fromDate, timeWindow.toDate); if (attractionReports.reportedAttractions != null && attractionReports.attractionTotal != null) { return(JsonConvert.SerializeObject(attractionReports)); } } return(null); } catch (Exception exc) { Console.WriteLine(exc.ToString()); logger.Error(exc.ToString()); return(null); } }
public IHighVolumeVenueDecoratorFilter Build( TimeWindows timeWindows, IUniverseFilterService baseService, DecimalRangeRuleFilter venueVolumeFilterSetting, ISystemProcessOperationRunRuleContext ruleRunContext, IUniverseDataRequestsSubscriber dataRequestSubscriber, DataSource dataSource, RuleRunMode ruleRunMode) { var filterRule = new HighVolumeVenueFilter( timeWindows, venueVolumeFilterSetting, this._equityOrderFilterService, ruleRunContext, this._equityMarketCacheFactory, this._fixedIncomeMarketCacheFactory, ruleRunMode, this._marketTradingHoursService, dataRequestSubscriber, dataSource, this._tradingHistoryLogger, this._venueLogger); var filter = new HighVolumeVenueDecoratorFilter(timeWindows, baseService, filterRule); return(filter); }
public string GetCardReport(HttpRequestMessage request) { try { var content = request.Content; string j = content.ReadAsStringAsync().Result; TimeWindows timeWindow = new TimeWindows(); timeWindow = JsonConvert.DeserializeObject <TimeWindows>(j); if (timeWindow.admin.check()) { CardReport cardReport = new CardReport(); cardReport.GetCardReport(timeWindow.fromDate, timeWindow.toDate); if (cardReport != null) { return(JsonConvert.SerializeObject(cardReport)); } } return(null); } catch (Exception exc) { Console.WriteLine(exc.ToString()); logger.Error(exc.ToString()); return(null); } }
public void OnNext_SubscribeObserverAndOnNextValid_ReturnsNonNullAndCallsFactory() { var baseDate = new DateTime(2018, 01, 01); var timeWindows = new TimeWindows("1", TimeSpan.FromDays(1)); var venueFilter = new HighVolumeVenueDecoratorFilter( timeWindows, this._baseService, this._highVolumeVenueFilter); var anObserver = A.Fake <IObserver <IUniverseEvent> >(); var onNext1 = A.Fake <IUniverseEvent>(); A.CallTo(() => onNext1.EventTime).Returns(baseDate); var onNext2 = A.Fake <IUniverseEvent>(); A.CallTo(() => onNext2.EventTime).Returns(baseDate); A.CallTo(() => onNext2.StateChange).Returns(UniverseStateEvent.Eschaton); var result = venueFilter.Subscribe(anObserver); venueFilter.OnNext(onNext1); venueFilter.OnNext(onNext2); A.CallTo(() => this._baseService.Subscribe(anObserver)).MustHaveHappenedOnceExactly(); Assert.IsNotNull(result); A.CallTo(() => this._baseService.OnNext(onNext1)).MustHaveHappenedOnceExactly(); A.CallTo(() => this._baseService.OnNext(onNext2)).MustHaveHappenedOnceExactly(); }
public TransactionInfo( TimeWindows timeWindow, int cardId ) { this.timeWindow = timeWindow; this.cardId = cardId; }
public void Setup() { this._equityMarketCacheFactory = A.Fake <IUniverseEquityMarketCacheFactory>(); this._fixedIncomeMarketCacheFactory = A.Fake <IUniverseFixedIncomeMarketCacheFactory>(); this._ruleRunContext = A.Fake <ISystemProcessOperationRunRuleContext>(); this._ruleRunMode = RuleRunMode.ValidationRun; this._universeOrderFilter = A.Fake <IUniverseOrderFilter>(); this._timeWindows = new TimeWindows("id-1", TimeSpan.FromDays(1)); this._decimalRangeRuleFilter = new DecimalRangeRuleFilter(); this._marketTradingHoursService = A.Fake <IMarketTradingHoursService>(); this._dataRequestSubscriber = A.Fake <IUniverseDataRequestsSubscriber>(); this._baseLogger = A.Fake <ILogger>(); this._tradingLogger = A.Fake <ILogger <TradingHistoryStack> >(); this._logger = A.Fake <ILogger <HighVolumeVenueFilter> >(); A.CallTo(() => this._universeOrderFilter.Filter(A <IUniverseEvent> .Ignored)) .ReturnsLazily(_ => _.Arguments.First() as IUniverseEvent); var repository = A.Fake <IMarketOpenCloseApiCachingDecorator>(); A.CallTo(() => repository.GetAsync()).Returns( new[] { new ExchangeDto { Code = "XLON", MarketOpenTime = TimeSpan.FromHours(8), MarketCloseTime = TimeSpan.FromHours(16), IsOpenOnMonday = true, IsOpenOnTuesday = true, IsOpenOnWednesday = true, IsOpenOnThursday = true, IsOpenOnFriday = true, IsOpenOnSaturday = true, IsOpenOnSunday = true }, new ExchangeDto { Code = "NASDAQ", MarketOpenTime = TimeSpan.FromHours(15), MarketCloseTime = TimeSpan.FromHours(23), IsOpenOnMonday = true, IsOpenOnTuesday = true, IsOpenOnWednesday = true, IsOpenOnThursday = true, IsOpenOnFriday = true, IsOpenOnSaturday = true, IsOpenOnSunday = true } }); this._tradingHoursService = new MarketTradingHoursService( repository, new NullLogger <MarketTradingHoursService>()); }
public void OnCompleted_DelegatesCallToSubscriber() { var timeWindows = new TimeWindows("1", TimeSpan.FromDays(1)); var venueFilter = new HighVolumeVenueDecoratorFilter( timeWindows, this._baseService, this._highVolumeVenueFilter); venueFilter.OnCompleted(); A.CallTo(() => this._baseService.OnCompleted()).MustHaveHappenedOnceExactly(); }
public void Version_DelegatesCallToDecoratee() { var timeWindows = new TimeWindows("1", TimeSpan.FromDays(1)); var venueFilter = new HighVolumeVenueDecoratorFilter( timeWindows, this._baseService, this._highVolumeVenueFilter); var result = venueFilter.Version; A.CallTo(() => this._baseService.Version).MustHaveHappenedOnceExactly(); }
public void DailyParameter_NoThresholdBreach_DoesNotRaiseAlert() { var windows = new TimeWindows("id", TimeSpan.FromHours(1)); A.CallTo(() => _equitiesParameters.HighVolumePercentageDaily).Returns(0.1m); A.CallTo(() => _equitiesParameters.Windows).Returns(windows); var highVolumeRule = BuildRule(); var trade = Trade(); var underlyingTrade = (Order)trade.UnderlyingEvent; underlyingTrade.FilledDate = DateTime.UtcNow; underlyingTrade.OrderFilledVolume = 10; underlyingTrade.FilledDate = DateTime.UtcNow; var market = new Market("1", "XLON", "London Stock Exchange", MarketTypes.STOCKEXCHANGE); var marketData = new EquityIntraDayTimeBarCollection(market, underlyingTrade.PlacedDate.Value.AddSeconds(-55), new List <EquityInstrumentIntraDayTimeBar> { new EquityInstrumentIntraDayTimeBar( underlyingTrade.Instrument, new SpreadTimeBar( underlyingTrade.OrderAverageFillPrice.Value, underlyingTrade.OrderAverageFillPrice.Value, underlyingTrade.OrderAverageFillPrice.Value, new Volume(2000)), new DailySummaryTimeBar( 1000m, "USD", new IntradayPrices( underlyingTrade.OrderAverageFillPrice.Value, underlyingTrade.OrderAverageFillPrice.Value, underlyingTrade.OrderAverageFillPrice.Value, underlyingTrade.OrderAverageFillPrice.Value), 10000, new Volume(10000), underlyingTrade.PlacedDate.Value.AddSeconds(-55)), underlyingTrade.PlacedDate.Value.AddSeconds(-55), market) }); var marketEvent = new UniverseEvent( UniverseStateEvent.EquityIntraDayTick, DateTime.UtcNow.AddMinutes(-1), marketData); highVolumeRule.OnNext(marketEvent); highVolumeRule.OnNext(trade); highVolumeRule.OnNext(Eschaton()); A.CallTo(() => _alertStream.Add(A <IUniverseAlertEvent> .Ignored)).MustHaveHappenedOnceExactly(); }
/// <summary> /// Used to figure out if we can use fact set or not /// </summary> /// <param name="windows"> /// The windows. /// </param> /// <returns> /// The <see cref="DataSource"/>. /// </returns> protected DataSource DataSourceForWindow(TimeWindows windows) { if (windows == null) { return(DataSource.AnyInterday); } return(windows.BackwardWindowSize.Hours > 0 || windows.BackwardWindowSize.Minutes > 0 || windows.BackwardWindowSize.Days < 1 ? DataSource.AnyIntraday : DataSource.AnyInterday); }
public void GivenIHaveTheHighVolumeVenueFilterParameterValues(Table ruleParameters) { if (ruleParameters.RowCount != 1) { this._scenarioContext.Pending(); return; } this._venueFilterApiParameters = ruleParameters.CreateInstance <HighVolumeVenueFilterApiParameters>(); this._timeWindows = new TimeWindows( "some-id", TimeSpan.FromHours(this._venueFilterApiParameters.WindowHours)); }
public void Subscribe_SubscribeObserver_ReturnsNonNullAndCallsFactory() { var timeWindows = new TimeWindows("1", TimeSpan.FromDays(1)); var venueFilter = new HighVolumeVenueDecoratorFilter( timeWindows, this._baseService, this._highVolumeVenueFilter); var anObserver = A.Fake <IObserver <IUniverseEvent> >(); var result = venueFilter.Subscribe(anObserver); A.CallTo(() => this._baseService.Subscribe(anObserver)).MustHaveHappenedOnceExactly(); Assert.IsNotNull(result); }
public void Subscribe_SubscribeNullObserver_ReturnsNullAndDoesNotCallFactory() { var timeWindows = new TimeWindows("1", TimeSpan.FromDays(1)); var venueFilter = new HighVolumeVenueDecoratorFilter( timeWindows, this._baseService, this._highVolumeVenueFilter); var result = venueFilter.Subscribe(null); A.CallTo( () => this._universeUnsubscriberFactory.Create( A <ConcurrentDictionary <IObserver <IUniverseEvent>, IObserver <IUniverseEvent> > > .Ignored, A <IObserver <IUniverseEvent> > .Ignored)).MustNotHaveHappened(); Assert.IsNull(result); }
private void TryGenerateWindowAggregation(TimeWindows windowedBy) { if (windowedBy == null) { return; } var windowType = windowedBy switch { HoppingWindows _ => "HOPPING", SessionWindow _ => "SESSION", _ => "TUMBLING" }; string size = windowType == "SESSION" ? String.Empty : "SIZE "; Append($" WINDOW {windowType} ({size}{windowedBy.Duration.Value} {windowedBy.Duration.TimeUnit}"); if (windowedBy is HoppingWindows { AdvanceBy : { } } hoppingWindows) { Append($", ADVANCE BY {hoppingWindows.AdvanceBy.Value} {hoppingWindows.AdvanceBy.TimeUnit}"); } if (windowedBy is HoppingWindows { Retention : { } } hoppingWindows2) { Append($", RETENTION {hoppingWindows2.Retention.Value} {hoppingWindows2.Retention.TimeUnit}"); } if (windowedBy.GracePeriod != null) { Append($", GRACE PERIOD {windowedBy.GracePeriod.Value} {windowedBy.GracePeriod.TimeUnit}"); } Append(")"); } }
public string GetWorkShifts(HttpRequestMessage request) { try { var content = request.Content; string j = content.ReadAsStringAsync().Result; TimeWindows timeWindow = new TimeWindows(); timeWindow = JsonConvert.DeserializeObject <TimeWindows>(j); SqlConn sqlConn = new SqlConn(); WorkShiftsReport workShiftsReport = new WorkShiftsReport(); List <WorkShift> wokrShifts = sqlConn.selectWorkShifts("work_shifts", ""); workShiftsReport.workShifts = wokrShifts.FindAll(x => x.startTime.Date >= timeWindow.fromDate.Date).FindAll(x => x.startTime.Date <= timeWindow.toDate.Date); List <WorkShiftInfo> workShiftInfos = sqlConn.selectWorkShiftInfos("work_shifts_info", ""); workShiftsReport.workShiftInfos = new List <WorkShiftInfo>(); foreach (WorkShift workShift in workShiftsReport.workShifts) { foreach (WorkShiftInfo workShiftInfo in workShiftInfos) { if (workShiftInfo.workShiftId == workShift.id) { workShiftsReport.workShiftInfos.Add(workShiftInfo); } } } if (timeWindow.admin.check()) { return(JsonConvert.SerializeObject(workShiftsReport)); } return(null); } catch (Exception exc) { Console.WriteLine(exc.ToString()); logger.Error(exc.ToString()); return(null); } }
/// <summary> /// Initializes a new instance of the <see cref="HighVolumeVenueFilter"/> class. /// </summary> /// <param name="timeWindows"> /// The time windows. /// </param> /// <param name="decimalRangeRuleFilter"> /// The decimal range rule filter. /// </param> /// <param name="universeOrderFilter"> /// The universe order filter. /// </param> /// <param name="runRuleContext"> /// The run rule context. /// </param> /// <param name="equityMarketCacheFactory"> /// The universe market cache factory. /// </param> /// <param name="fixedIncomeMarketCacheFactory"> /// The universe market cache factory. /// </param> /// <param name="ruleRunMode"> /// The rule run mode. /// </param> /// <param name="marketTradingHoursService"> /// The market trading hours service. /// </param> /// <param name="dataRequestsSubscriber"> /// The data requests subscriber. /// </param> /// <param name="source"> /// The source. /// </param> /// <param name="stackLogger"> /// The stack logger. /// </param> /// <param name="logger"> /// The logger. /// </param> public HighVolumeVenueFilter( TimeWindows timeWindows, DecimalRangeRuleFilter decimalRangeRuleFilter, IUniverseOrderFilter universeOrderFilter, ISystemProcessOperationRunRuleContext runRuleContext, IUniverseEquityMarketCacheFactory equityMarketCacheFactory, IUniverseFixedIncomeMarketCacheFactory fixedIncomeMarketCacheFactory, RuleRunMode ruleRunMode, IMarketTradingHoursService marketTradingHoursService, IUniverseDataRequestsSubscriber dataRequestsSubscriber, DataSource source, ILogger <TradingHistoryStack> stackLogger, ILogger <HighVolumeVenueFilter> logger) : base( timeWindows.BackwardWindowSize, timeWindows.BackwardWindowSize, timeWindows.FutureWindowSize, Domain.Surveillance.Scheduling.Rules.UniverseFilter, Versioner.Version(1, 0), nameof(HighVolumeVenueFilter), runRuleContext, equityMarketCacheFactory, fixedIncomeMarketCacheFactory, ruleRunMode, logger, stackLogger) { this.eventExpiration = this.TradeBackwardWindowSize + this.TradeBackwardWindowSize + TimeSpan.FromDays(3); this.tradingHoursService = marketTradingHoursService ?? throw new ArgumentNullException(nameof(marketTradingHoursService)); this.decimalRangeRuleFilter = decimalRangeRuleFilter ?? DecimalRangeRuleFilter.None(); this.orderFilter = universeOrderFilter ?? throw new ArgumentNullException(nameof(universeOrderFilter)); this.dataRequestSubscriber = dataRequestsSubscriber ?? throw new ArgumentNullException(nameof(dataRequestsSubscriber)); this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); this.UniverseEventsPassedFilter = new HashSet <Order>(); this.source = source; }
private object ApplyTimeWindow( PropertyInfo pInfo, object targetBackward, TimeWindows timeWindow, PropertyInfo tunableRule) { var clonedTarget = targetBackward.DeepClone(); pInfo.SetMethod.Invoke(clonedTarget, new[] { timeWindow }); var props = timeWindow.GetType().GetProperties() ?? new PropertyInfo[0]; var tunedParamAttributes = props.FirstOrDefault(_ => Attribute.IsDefined(_, typeof(TunedParam))); if (tunedParamAttributes == null) { return(clonedTarget); } var tunedParam = tunedParamAttributes.GetMethod.Invoke(timeWindow, new object[0]); tunableRule.SetMethod.Invoke(clonedTarget, new[] { tunedParam }); return(clonedTarget); }
public static IQbservable <IWindowedKSql <TKey, TSource> > WindowedBy <TSource, TKey>(this IQbservable <IKSqlGrouping <TKey, TSource> > source, TimeWindows timeWindows) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (timeWindows == null) { throw new ArgumentNullException(nameof(timeWindows)); } return(source.Provider.CreateQuery <IWindowedKSql <TKey, TSource> >( Expression.Call(null, WindowedByTSourceTKey(typeof(TSource), typeof(TKey)), source.Expression, Expression.Constant(timeWindows)))); }
/// <summary> /// Returns true if Service instances are equal /// </summary> /// <param name="input">Instance of Service to be compared</param> /// <returns>Boolean</returns> public bool Equals(Service input) { if (input == null) { return(false); } return (( Id == input.Id || (Id != null && Id.Equals(input.Id)) ) && ( Type == input.Type || (Type != null && Type.Equals(input.Type)) ) && ( Priority == input.Priority || (Priority != null && Priority.Equals(input.Priority)) ) && ( Name == input.Name || (Name != null && Name.Equals(input.Name)) ) && ( Address == input.Address || (Address != null && Address.Equals(input.Address)) ) && ( Duration == input.Duration || (Duration != null && Duration.Equals(input.Duration)) ) && ( PreparationTime == input.PreparationTime || (PreparationTime != null && PreparationTime.Equals(input.PreparationTime)) ) && ( TimeWindows == input.TimeWindows || TimeWindows != null && TimeWindows.SequenceEqual(input.TimeWindows) ) && ( Size == input.Size || Size != null && Size.SequenceEqual(input.Size) ) && ( RequiredSkills == input.RequiredSkills || RequiredSkills != null && RequiredSkills.SequenceEqual(input.RequiredSkills) ) && ( AllowedVehicles == input.AllowedVehicles || AllowedVehicles != null && AllowedVehicles.SequenceEqual(input.AllowedVehicles) ) && ( DisallowedVehicles == input.DisallowedVehicles || DisallowedVehicles != null && DisallowedVehicles.SequenceEqual(input.DisallowedVehicles) ) && ( MaxTimeInVehicle == input.MaxTimeInVehicle || (MaxTimeInVehicle != null && MaxTimeInVehicle.Equals(input.MaxTimeInVehicle)) )); }