/// <summary> /// Initializes a new instance of the <see cref="FixedIncomeWashTradeRule"/> class. /// </summary> /// <param name="parameters"> /// The parameters. /// </param> /// <param name="orderFilterService"> /// The order filter service. /// </param> /// <param name="ruleContext"> /// The rule context. /// </param> /// <param name="equityFactory"> /// The factory. /// </param> /// <param name="fixedIncomeFactory"> /// The factory. /// </param> /// <param name="runMode"> /// The run mode. /// </param> /// <param name="alertStream"> /// The alert stream. /// </param> /// <param name="clusteringService"> /// The clustering service. /// </param> /// <param name="portfolioFactory"> /// The portfolio factory. /// </param> /// <param name="logger"> /// The logger. /// </param> /// <param name="tradingStackLogger"> /// The trading stack logger. /// </param> public FixedIncomeWashTradeRule( IWashTradeRuleFixedIncomeParameters parameters, IUniverseFixedIncomeOrderFilterService orderFilterService, ISystemProcessOperationRunRuleContext ruleContext, IUniverseEquityMarketCacheFactory equityFactory, IUniverseFixedIncomeMarketCacheFactory fixedIncomeFactory, RuleRunMode runMode, IUniverseAlertStream alertStream, IClusteringService clusteringService, IPortfolioFactory portfolioFactory, ILogger <FixedIncomeWashTradeRule> logger, ILogger <TradingHistoryStack> tradingStackLogger) : base( parameters?.Windows?.BackwardWindowSize ?? TimeSpan.FromDays(1), parameters?.Windows?.BackwardWindowSize ?? TimeSpan.FromDays(1), parameters?.Windows?.FutureWindowSize ?? TimeSpan.Zero, Rules.FixedIncomeWashTrades, Versioner.Version(1, 0), $"{nameof(FixedIncomeWashTradeRule)}", ruleContext, equityFactory, fixedIncomeFactory, runMode, logger, tradingStackLogger) { this.parameters = parameters ?? throw new ArgumentNullException(nameof(parameters)); this.orderFilterService = orderFilterService ?? throw new ArgumentNullException(nameof(orderFilterService)); this.alertStream = alertStream ?? throw new ArgumentNullException(nameof(alertStream)); this.clusteringService = clusteringService ?? throw new ArgumentNullException(nameof(clusteringService)); this.portfolioFactory = portfolioFactory ?? throw new ArgumentNullException(nameof(portfolioFactory)); this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
/// <summary> /// Initializes a new instance of the <see cref="FixedIncomeHighVolumeRule"/> class. /// </summary> /// <param name="parameters"> /// The parameters. /// </param> /// <param name="orderFilterService"> /// The order filter service. /// </param> /// <param name="ruleContext"> /// The rule context. /// </param> /// <param name="equityFactory"> /// The factory. /// </param> /// <param name="fixedIncomeFactory"> /// The factory. /// </param> /// <param name="judgementService"> /// The judgement service. /// </param> /// <param name="dataRequestSubscriber"> /// The data request subscriber /// </param> /// <param name="tradingHoursService"> /// The trading hours service /// </param> /// <param name="runMode"> /// The run mode. /// </param> /// <param name="logger"> /// The logger. /// </param> /// <param name="tradingStackLogger"> /// The trading stack logger. /// </param> public FixedIncomeHighVolumeRule( IHighVolumeIssuanceRuleFixedIncomeParameters parameters, IUniverseFixedIncomeOrderFilterService orderFilterService, ISystemProcessOperationRunRuleContext ruleContext, IUniverseEquityMarketCacheFactory equityFactory, IUniverseFixedIncomeMarketCacheFactory fixedIncomeFactory, IFixedIncomeHighVolumeJudgementService judgementService, IUniverseDataRequestsSubscriber dataRequestSubscriber, IMarketTradingHoursService tradingHoursService, RuleRunMode runMode, ILogger <FixedIncomeHighVolumeRule> logger, ILogger <TradingHistoryStack> tradingStackLogger) : base( parameters.Windows.BackwardWindowSize, parameters.Windows.BackwardWindowSize, parameters.Windows.FutureWindowSize, Rules.FixedIncomeHighVolumeIssuance, FixedIncomeHighVolumeFactory.Version, $"{nameof(FixedIncomeHighVolumeRule)}", ruleContext, equityFactory, fixedIncomeFactory, runMode, logger, tradingStackLogger) { this.parameters = parameters ?? throw new ArgumentNullException(nameof(parameters)); this.orderFilterService = orderFilterService ?? throw new ArgumentNullException(nameof(orderFilterService)); this.judgementService = judgementService ?? throw new ArgumentNullException(nameof(judgementService)); this.dataRequestSubscriber = dataRequestSubscriber ?? throw new ArgumentNullException(nameof(dataRequestSubscriber)); this.tradingHoursService = tradingHoursService ?? throw new ArgumentNullException(nameof(tradingHoursService)); this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
public async Task <Money?> CalculateCostOfPosition( IList <Order> activeFulfilledTradeOrders, DateTime universeDateTime, ISystemProcessOperationRunRuleContext ctx) { if (activeFulfilledTradeOrders == null || !activeFulfilledTradeOrders.Any()) { this._logger.LogInformation( "CostCurrencyConvertingCalculator CalculateCostOfPosition had null or empty active fulfilled trade orders. Returning."); return(null); } var purchaseOrders = activeFulfilledTradeOrders .Where( afto => afto.OrderDirection == OrderDirections.BUY || afto.OrderDirection == OrderDirections.COVER) .Select( afto => new Money( afto.OrderFilledVolume.GetValueOrDefault(0) * afto.OrderAverageFillPrice.GetValueOrDefault().Value, afto.OrderCurrency)).ToList(); var adjustedToCurrencyPurchaseOrders = await this._currencyConverterService.Convert( purchaseOrders, this._targetCurrency, universeDateTime, ctx); this._logger.LogInformation( $"CostCurrencyConvertingCalculator CalculateCostOfPosition calculated for {activeFulfilledTradeOrders.FirstOrDefault()?.Instrument?.Identifiers} a cost of ({adjustedToCurrencyPurchaseOrders?.Currency}) {adjustedToCurrencyPurchaseOrders?.Value}"); return(adjustedToCurrencyPurchaseOrders); }
/// <summary> /// The market data request. /// </summary> /// <param name="marketIdentifierCode"> /// The market identifier code. /// </param> /// <param name="identifiers"> /// The identifiers. /// </param> /// <param name="universeDateTime"> /// The universe date time. /// </param> /// <param name="context"> /// The context. /// </param> /// <param name="dataSource"> /// The data source. /// </param> /// <returns> /// The <see cref="MarketDataRequest"/>. /// </returns> protected virtual MarketDataRequest MarketDataRequest( string marketIdentifierCode, InstrumentIdentifiers identifiers, DateTime universeDateTime, ISystemProcessOperationRunRuleContext context, DataSource dataSource) { var tradingHours = this.TradingHoursService.GetTradingHoursForMic(marketIdentifierCode); if (!tradingHours.IsValid) { this.Logger.LogError( $"RevenueCurrencyConvertingCalculator was not able to get meaningful trading hours for the mic {marketIdentifierCode}. Unable to proceed with currency conversions."); return(null); } return(new MarketDataRequest( marketIdentifierCode, string.Empty, identifiers, tradingHours.OpeningInUtcForDay(universeDateTime), tradingHours.MinimumOfCloseInUtcForDayOrUniverse(universeDateTime), context?.Id(), dataSource)); }
/// <summary> /// Sum the total buy in for the position /// </summary> public async Task <Money?> CalculateCostOfPosition( IList <Order> activeFulfilledTradeOrders, DateTime universeDateTime, ISystemProcessOperationRunRuleContext ctx) { if (activeFulfilledTradeOrders == null || !activeFulfilledTradeOrders.Any()) { this._logger.LogInformation( "CostCalculator CalculateCostOfPosition had null active trade orders or empty. Returning null."); return(null); } var purchaseOrders = activeFulfilledTradeOrders .Where( afto => afto.OrderDirection == OrderDirections.BUY || afto.OrderDirection == OrderDirections.COVER) .Select( afto => new Money( afto.OrderFilledVolume.GetValueOrDefault(0) * afto.OrderAverageFillPrice.GetValueOrDefault().Value, afto.OrderCurrency)).ToList(); var money = new Money(purchaseOrders.Sum(po => po.Value), purchaseOrders.FirstOrDefault().Currency); this._logger.LogInformation( $"CostCalculator CalculateCostOfPosition had calculated costs for {activeFulfilledTradeOrders.FirstOrDefault()?.Instrument?.Identifiers} at {universeDateTime} as ({money.Currency}) {money.Value}."); return(await Task.FromResult(money)); }
/// <summary> /// Initializes a new instance of the <see cref="WashTradeRule"/> class. /// </summary> /// <param name="equitiesParameters"> /// The equities parameters. /// </param> /// <param name="ruleContext"> /// The rule context. /// </param> /// <param name="clustering"> /// The clustering. /// </param> /// <param name="alertStream"> /// The alert stream. /// </param> /// <param name="currencyConverterService"> /// The currency converter service. /// </param> /// <param name="orderFilter"> /// The order filter. /// </param> /// <param name="equityMarketCacheFactory"> /// The market cache factory. /// </param> /// <param name="fixedIncomeMarketCacheFactory"> /// The market cache factory. /// </param> /// <param name="runMode"> /// The run mode. /// </param> /// <param name="logger"> /// The logger. /// </param> /// <param name="tradingHistoryLogger"> /// The trading history logger. /// </param> public WashTradeRule( IWashTradeRuleEquitiesParameters equitiesParameters, ISystemProcessOperationRunRuleContext ruleContext, IClusteringService clustering, IUniverseAlertStream alertStream, ICurrencyConverterService currencyConverterService, IUniverseOrderFilter orderFilter, IUniverseEquityMarketCacheFactory equityMarketCacheFactory, IUniverseFixedIncomeMarketCacheFactory fixedIncomeMarketCacheFactory, RuleRunMode runMode, ILogger logger, ILogger <TradingHistoryStack> tradingHistoryLogger) : base( equitiesParameters?.Windows?.BackwardWindowSize ?? TimeSpan.FromDays(1), equitiesParameters?.Windows?.BackwardWindowSize ?? TimeSpan.FromDays(1), equitiesParameters?.Windows?.FutureWindowSize ?? TimeSpan.Zero, Rules.WashTrade, EquityRuleWashTradeFactory.Version, "Wash Trade Rule", ruleContext, equityMarketCacheFactory, fixedIncomeMarketCacheFactory, runMode, logger, tradingHistoryLogger) { this.equitiesParameters = equitiesParameters ?? throw new ArgumentNullException(nameof(equitiesParameters)); this.clustering = clustering ?? throw new ArgumentNullException(nameof(clustering)); this.currencyConverterService = currencyConverterService ?? throw new ArgumentNullException(nameof(currencyConverterService)); this.orderFilter = orderFilter ?? throw new ArgumentNullException(nameof(orderFilter)); this.alertStream = alertStream ?? throw new ArgumentNullException(nameof(alertStream)); this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
public IWashTradeRule Build( IWashTradeRuleEquitiesParameters equitiesParameters, ISystemProcessOperationRunRuleContext ruleCtx, IUniverseAlertStream alertStream, RuleRunMode runMode) { if (ruleCtx == null) { throw new ArgumentNullException(nameof(ruleCtx)); } if (equitiesParameters == null) { throw new ArgumentNullException(nameof(equitiesParameters)); } return(new WashTradeRule( equitiesParameters, ruleCtx, this._clustering, alertStream, this._currencyConverterService, this._orderFilterService, this._equityFactory, this._fixedIncomeFactory, runMode, this._logger, this._tradingHistoryLogger)); }
private async Task <Money?> CalculateRealisedRevenue (IList <Order> activeFulfilledTradeOrders, Domain.Core.Financial.Money.Currency targetCurrency, DateTime universeDateTime, ISystemProcessOperationRunRuleContext ruleCtx) { if (!activeFulfilledTradeOrders?.Any() ?? true) { return(null); } var filledOrders = activeFulfilledTradeOrders .Where(afto => afto.OrderDirection == OrderDirections.SELL || afto.OrderDirection == OrderDirections.SHORT) .Select(afto => new Money( afto.OrderFilledVolume.GetValueOrDefault(0) * afto.OrderAverageFillPrice.GetValueOrDefault().Value, afto.OrderCurrency)) .ToList(); var conversion = await _currencyConverterService.Convert(filledOrders, targetCurrency, universeDateTime, ruleCtx); return(conversion); }
/// <summary> /// The decorate with filters. /// </summary> /// <param name="operationContext"> /// The operation context. /// </param> /// <param name="parameters"> /// The parameters. /// </param> /// <param name="washTrade"> /// The wash trade. /// </param> /// <param name="universeDataRequestsSubscriber"> /// The universe data requests subscriber. /// </param> /// <param name="processOperationRunRuleContext"> /// The process operation run rule context. /// </param> /// <param name="ruleRunMode"> /// The rule run mode. /// </param> /// <returns> /// The <see cref="IUniverseRule"/>. /// </returns> private IUniverseRule DecorateWithFilters( ISystemProcessOperationContext operationContext, IWashTradeRuleFixedIncomeParameters parameters, IUniverseRule washTrade, IUniverseDataRequestsSubscriber universeDataRequestsSubscriber, ISystemProcessOperationRunRuleContext processOperationRunRuleContext, RuleRunMode ruleRunMode) { if (parameters.HasInternalFilters()) { this.logger.LogInformation($"parameters had filters. Inserting filtered universe in {operationContext.Id} OpCtx"); var filteredUniverse = this.universeFilterFactory.Build( washTrade, parameters.Accounts, parameters.Traders, parameters.Markets, parameters.Funds, parameters.Strategies, null, null, null, null, null, ruleRunMode, "Wash Trade Fixed Income", universeDataRequestsSubscriber, processOperationRunRuleContext); filteredUniverse.Subscribe(washTrade); return(filteredUniverse); } return(washTrade); }
public SpoofingSteps(ScenarioContext scenarioContext, UniverseSelectionState universeSelectionState) { this._scenarioContext = scenarioContext ?? throw new ArgumentNullException(nameof(scenarioContext)); this._universeSelectionState = universeSelectionState ?? throw new ArgumentNullException(nameof(universeSelectionState)); this._orderAnalysisService = new OrderAnalysisService(); this._ruleCtx = A.Fake <ISystemProcessOperationRunRuleContext>(); this._alertStream = A.Fake <IUniverseAlertStream>(); var equityMarketCacheFactory = new UniverseEquityMarketCacheFactory( new StubRuleRunDataRequestRepository(), new StubRuleRunDataRequestRepository(), new NullLogger <UniverseEquityMarketCacheFactory>()); var fixedIncomeMarketCacheFactory = new UniverseFixedIncomeMarketCacheFactory( new StubRuleRunDataRequestRepository(), new StubRuleRunDataRequestRepository(), new NullLogger <UniverseFixedIncomeMarketCacheFactory>()); this._equityRuleSpoofingFactory = new EquityRuleSpoofingFactory( equityMarketCacheFactory, fixedIncomeMarketCacheFactory, new UniverseEquityOrderFilterService(new NullLogger <UniverseEquityOrderFilterService>()), new PortfolioFactory(), this._orderAnalysisService, new NullLogger <SpoofingRule>(), new NullLogger <TradingHistoryStack>()); }
/// <summary> /// Initializes a new instance of the <see cref="SpoofingRule"/> class. /// </summary> /// <param name="equitiesParameters"> /// The equities parameters. /// </param> /// <param name="ruleContext"> /// The rule context. /// </param> /// <param name="alertStream"> /// The alert stream. /// </param> /// <param name="orderFilter"> /// The order filter. /// </param> /// <param name="equityMarketCacheFactory"> /// The market cache factory. /// </param> /// <param name="fixedIncomeMarketCacheFactory"> /// The market cache factory. /// </param> /// <param name="runMode"> /// The run mode. /// </param> /// <param name="portfolioFactory"> /// The portfolio factory. /// </param> /// <param name="analysisService"> /// The analysis service. /// </param> /// <param name="logger"> /// The logger. /// </param> /// <param name="tradingHistoryLogger"> /// The trading history logger. /// </param> public SpoofingRule( ISpoofingRuleEquitiesParameters equitiesParameters, ISystemProcessOperationRunRuleContext ruleContext, IUniverseAlertStream alertStream, IUniverseOrderFilter orderFilter, IUniverseEquityMarketCacheFactory equityMarketCacheFactory, IUniverseFixedIncomeMarketCacheFactory fixedIncomeMarketCacheFactory, RuleRunMode runMode, IPortfolioFactory portfolioFactory, IOrderAnalysisService analysisService, ILogger logger, ILogger <TradingHistoryStack> tradingHistoryLogger) : base( equitiesParameters?.Windows?.BackwardWindowSize ?? TimeSpan.FromMinutes(30), equitiesParameters?.Windows?.BackwardWindowSize ?? TimeSpan.FromMinutes(30), equitiesParameters?.Windows?.FutureWindowSize ?? TimeSpan.Zero, Rules.Spoofing, EquityRuleSpoofingFactory.Version, "Spoofing Rule", ruleContext, equityMarketCacheFactory, fixedIncomeMarketCacheFactory, runMode, logger, tradingHistoryLogger) { this.equitiesParameters = equitiesParameters ?? throw new ArgumentNullException(nameof(equitiesParameters)); this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); this.alertStream = alertStream ?? throw new ArgumentNullException(nameof(alertStream)); this.orderFilter = orderFilter ?? throw new ArgumentNullException(nameof(orderFilter)); this.portfolioFactory = portfolioFactory ?? throw new ArgumentNullException(nameof(portfolioFactory)); this.analysisService = analysisService ?? throw new ArgumentNullException(nameof(analysisService)); this.ruleContext = ruleContext ?? throw new ArgumentNullException(nameof(ruleContext)); }
/// <summary> /// Initializes a new instance of the <see cref="HighProfitMarketClosureRule"/> class. /// </summary> /// <param name="equitiesParameters"> /// The equities parameters. /// </param> /// <param name="ruleContext"> /// The rule context. /// </param> /// <param name="costCalculatorFactory"> /// The cost calculator factory. /// </param> /// <param name="revenueCalculatorFactory"> /// The revenue calculator factory. /// </param> /// <param name="exchangeRateProfitCalculator"> /// The exchange rate profit calculator. /// </param> /// <param name="orderFilter"> /// The order filter. /// </param> /// <param name="equityMarketCacheFactory"> /// The market cache factory. /// </param> /// <param name="fixedIncomeMarketCacheFactory"> /// The market cache factory. /// </param> /// <param name="marketDataCacheFactory"> /// The market data cache factory. /// </param> /// <param name="dataRequestSubscriber"> /// The data request subscriber. /// </param> /// <param name="judgementService"> /// The judgement service. /// </param> /// <param name="runMode"> /// The run mode. /// </param> /// <param name="logger"> /// The logger. /// </param> /// <param name="tradingHistoryLogger"> /// The trading history logger. /// </param> public HighProfitMarketClosureRule( IHighProfitsRuleEquitiesParameters equitiesParameters, ISystemProcessOperationRunRuleContext ruleContext, ICostCalculatorFactory costCalculatorFactory, IRevenueCalculatorFactory revenueCalculatorFactory, IExchangeRateProfitCalculator exchangeRateProfitCalculator, IUniverseOrderFilter orderFilter, IUniverseEquityMarketCacheFactory equityMarketCacheFactory, IUniverseFixedIncomeMarketCacheFactory fixedIncomeMarketCacheFactory, IEquityMarketDataCacheStrategyFactory marketDataCacheFactory, IUniverseDataRequestsSubscriber dataRequestSubscriber, IHighProfitJudgementService judgementService, ICurrencyConverterService currencyConverterService, RuleRunMode runMode, ILogger <HighProfitsRule> logger, ILogger <TradingHistoryStack> tradingHistoryLogger) : base( equitiesParameters, ruleContext, costCalculatorFactory, revenueCalculatorFactory, exchangeRateProfitCalculator, orderFilter, equityMarketCacheFactory, fixedIncomeMarketCacheFactory, marketDataCacheFactory, dataRequestSubscriber, judgementService, currencyConverterService, runMode, logger, tradingHistoryLogger) { this.MarketClosureRule = true; }
public void Setup() { this._currencyConverterService = A.Fake <ICurrencyConverterService>(); this._ruleCtx = A.Fake <ISystemProcessOperationRunRuleContext>(); this._alertStream = A.Fake <IUniverseAlertStream>(); this._clustering = new ClusteringService(); this._equitiesParameters = A.Fake <IWashTradeRuleEquitiesParameters>(); this._logger = A.Fake <ILogger>(); this._ruleRunRepository = A.Fake <IRuleRunDataRequestRepository>(); this._stubRuleRunRepository = A.Fake <IStubRuleRunDataRequestRepository>(); this._loggerEquityCache = A.Fake <ILogger <UniverseEquityMarketCacheFactory> >(); this._loggerFixedIncomeCache = A.Fake <ILogger <UniverseFixedIncomeMarketCacheFactory> >(); this._tradingLogger = A.Fake <ILogger <TradingHistoryStack> >(); this._orderFilter = A.Fake <IUniverseOrderFilter>(); this._equityFactory = new UniverseEquityMarketCacheFactory( this._stubRuleRunRepository, this._ruleRunRepository, this._loggerEquityCache); this._fixedIncomeFactory = new UniverseFixedIncomeMarketCacheFactory( this._stubRuleRunRepository, this._ruleRunRepository, this._loggerFixedIncomeCache); A.CallTo(() => this._orderFilter.Filter(A <IUniverseEvent> .Ignored)) .ReturnsLazily(i => (IUniverseEvent)i.Arguments[0]); A.CallTo(() => this._equitiesParameters.PerformClusteringPositionAnalysis).Returns(true); A.CallTo(() => this._equitiesParameters.ClusteringPercentageValueDifferenceThreshold).Returns(0.05m); }
protected override MarketDataRequest MarketDataRequest( string mic, InstrumentIdentifiers identifiers, DateTime universeDateTime, ISystemProcessOperationRunRuleContext ctx, DataSource dataSource) { var tradingHours = this.TradingHoursService.GetTradingHoursForMic(mic); if (!tradingHours.IsValid) { this.Logger.LogError( $"RevenueCurrencyConvertingMarkingCloseCalculator was not able to get meaningful trading hours for the mic {mic}. Unable to proceed with currency conversions."); return(null); } return(new MarketDataRequest( mic, string.Empty, identifiers, tradingHours.ClosingInUtcForDay(universeDateTime).Subtract(TimeSpan.FromMinutes(15)), tradingHours.ClosingInUtcForDay(universeDateTime), ctx?.Id(), dataSource)); }
public CancelledOrdersSteps(ScenarioContext scenarioContext, UniverseSelectionState universeSelectionState) { this._scenarioContext = scenarioContext; this._universeSelectionState = universeSelectionState; this._equityMarketCacheFactory = new UniverseEquityMarketCacheFactory( new StubRuleRunDataRequestRepository(), new StubRuleRunDataRequestRepository(), new NullLogger <UniverseEquityMarketCacheFactory>()); this._fixedIncomeMarketCacheFactory = new UniverseFixedIncomeMarketCacheFactory( new StubRuleRunDataRequestRepository(), new StubRuleRunDataRequestRepository(), new NullLogger <UniverseFixedIncomeMarketCacheFactory>()); this._alertStream = A.Fake <IUniverseAlertStream>(); this._ruleCtx = A.Fake <ISystemProcessOperationRunRuleContext>(); this._universeOrderFilterService = A.Fake <IUniverseEquityOrderFilterService>(); this._equityRuleCancelledOrderFactory = new EquityRuleCancelledOrderFactory( this._universeOrderFilterService, this._equityMarketCacheFactory, this._fixedIncomeMarketCacheFactory, new NullLogger <CancelledOrderRule>(), new NullLogger <TradingHistoryStack>()); }
public PlacingOrderWithNoIntentToExecuteRuleRuleBreach( TimeSpan window, ITradePosition trades, FinancialInstrument security, IFactorValue factorValue, decimal meanPrice, decimal sdPrice, IReadOnlyCollection <ProbabilityOfExecution> probabilityForOrders, IPlacingOrderWithNoIntentToExecuteRuleEquitiesParameters parameters, ISystemProcessOperationRunRuleContext ctx, string description, string caseTitle, DateTime universeDateTime) { this.Window = window; this.Trades = trades; this.Security = security; this.FactorValue = factorValue; this.Parameters = parameters; this.MeanPrice = meanPrice; this.StandardDeviationPrice = sdPrice; this.ProbabilityForOrders = probabilityForOrders ?? new List <ProbabilityOfExecution>(); this.RuleParameterId = parameters.Id; this.SystemOperationId = ctx.Id(); this.CorrelationId = ctx.CorrelationId(); this.RuleParameters = parameters; this.Description = description ?? string.Empty; this.CaseTitle = caseTitle ?? string.Empty; this.UniverseDateTime = universeDateTime; }
public void Setup() { _alertStream = A.Fake <IUniverseAlertStream>(); _equitiesParameters = A.Fake <IHighVolumeRuleEquitiesParameters>(); _ruleCtx = A.Fake <ISystemProcessOperationRunRuleContext>(); _opCtx = A.Fake <ISystemProcessOperationContext>(); _dataRequestRepository = A.Fake <IRuleRunDataRequestRepository>(); _stubDataRequestRepository = A.Fake <IStubRuleRunDataRequestRepository>(); _equityFactoryCache = A.Fake <ILogger <UniverseEquityMarketCacheFactory> >(); _equityFactory = new UniverseEquityMarketCacheFactory(_stubDataRequestRepository, _dataRequestRepository, _equityFactoryCache); _fixedIncomeFactoryCache = A.Fake <ILogger <UniverseFixedIncomeMarketCacheFactory> >(); _fixedIncomeFactory = new UniverseFixedIncomeMarketCacheFactory(_stubDataRequestRepository, _dataRequestRepository, _fixedIncomeFactoryCache); _tradingHoursService = A.Fake <IMarketTradingHoursService>(); _dataRequestSubscriber = A.Fake <IUniverseDataRequestsSubscriber>(); this.currencyConverterService = A.Fake <ICurrencyConverterService>(); _logger = A.Fake <ILogger <IHighVolumeRule> >(); _tradingLogger = A.Fake <ILogger <TradingHistoryStack> >(); _orderFilter = A.Fake <IUniverseOrderFilter>(); A.CallTo(() => _orderFilter.Filter(A <IUniverseEvent> .Ignored)).ReturnsLazily(i => (IUniverseEvent)i.Arguments[0]); A.CallTo(() => _ruleCtx.EndEvent()).Returns(_opCtx); }
/// <summary> /// Initializes a new instance of the <see cref="MarkingTheCloseRule"/> class. /// </summary> /// <param name="equitiesParameters"> /// The equities parameters. /// </param> /// <param name="alertStream"> /// The alert stream. /// </param> /// <param name="ruleContext"> /// The rule context. /// </param> /// <param name="orderFilter"> /// The order filter. /// </param> /// <param name="equityMarketCacheFactory"> /// The market cache factory. /// </param> /// <param name="fixedIncomeMarketCacheFactory"> /// The market cache factory. /// </param> /// <param name="tradingHoursService"> /// The trading hours service. /// </param> /// <param name="dataRequestSubscriber"> /// The data request subscriber. /// </param> /// <param name="runMode"> /// The run mode. /// </param> /// <param name="logger"> /// The logger. /// </param> /// <param name="tradingHistoryLogger"> /// The trading history logger. /// </param> public MarkingTheCloseRule( IMarkingTheCloseEquitiesParameters equitiesParameters, IUniverseAlertStream alertStream, ISystemProcessOperationRunRuleContext ruleContext, IUniverseOrderFilter orderFilter, IUniverseEquityMarketCacheFactory equityMarketCacheFactory, IUniverseFixedIncomeMarketCacheFactory fixedIncomeMarketCacheFactory, IMarketTradingHoursService tradingHoursService, IUniverseDataRequestsSubscriber dataRequestSubscriber, RuleRunMode runMode, ILogger <MarkingTheCloseRule> logger, ILogger <TradingHistoryStack> tradingHistoryLogger) : base( equitiesParameters?.Windows?.BackwardWindowSize ?? TimeSpan.FromMinutes(30), equitiesParameters?.Windows?.BackwardWindowSize ?? TimeSpan.FromMinutes(30), equitiesParameters?.Windows?.FutureWindowSize ?? TimeSpan.FromMinutes(30), Domain.Surveillance.Scheduling.Rules.MarkingTheClose, EquityRuleMarkingTheCloseFactory.Version, "Marking The Close", ruleContext, equityMarketCacheFactory, fixedIncomeMarketCacheFactory, runMode, logger, tradingHistoryLogger) { this.equitiesParameters = equitiesParameters ?? throw new ArgumentNullException(nameof(equitiesParameters)); this.alertStream = alertStream ?? throw new ArgumentNullException(nameof(alertStream)); this.ruleContext = ruleContext ?? throw new ArgumentNullException(nameof(ruleContext)); this.orderFilter = orderFilter ?? throw new ArgumentNullException(nameof(orderFilter)); this.tradingHoursService = tradingHoursService ?? throw new ArgumentNullException(nameof(tradingHoursService)); this.dataRequestSubscriber = dataRequestSubscriber ?? throw new ArgumentNullException(nameof(dataRequestSubscriber)); this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
/// <summary> /// Initializes a new instance of the <see cref="LayeringRule"/> class. /// </summary> /// <param name="equitiesParameters"> /// The equities parameters. /// </param> /// <param name="alertStream"> /// The alert stream. /// </param> /// <param name="orderFilter"> /// The order filter. /// </param> /// <param name="logger"> /// The logger. /// </param> /// <param name="equityMarketCacheFactory"> /// The market cache factory. /// </param> /// <param name="fixedIncomeMarketCacheFactory"> /// The market cache factory. /// </param> /// <param name="tradingHoursService"> /// The trading hours service. /// </param> /// <param name="operationContext"> /// The op context. /// </param> /// <param name="runMode"> /// The run mode. /// </param> /// <param name="tradingHistoryLogger"> /// The trading history logger. /// </param> public LayeringRule( ILayeringRuleEquitiesParameters equitiesParameters, IUniverseAlertStream alertStream, IUniverseOrderFilter orderFilter, ILogger logger, IUniverseEquityMarketCacheFactory equityMarketCacheFactory, IUniverseFixedIncomeMarketCacheFactory fixedIncomeMarketCacheFactory, IMarketTradingHoursService tradingHoursService, ISystemProcessOperationRunRuleContext operationContext, RuleRunMode runMode, ILogger <TradingHistoryStack> tradingHistoryLogger) : base( equitiesParameters?.Windows?.BackwardWindowSize ?? TimeSpan.FromMinutes(20), equitiesParameters?.Windows?.BackwardWindowSize ?? TimeSpan.FromMinutes(20), equitiesParameters?.Windows?.FutureWindowSize ?? TimeSpan.Zero, Domain.Surveillance.Scheduling.Rules.Layering, EquityRuleLayeringFactory.Version, "Layering Rule", operationContext, equityMarketCacheFactory, fixedIncomeMarketCacheFactory, runMode, logger, tradingHistoryLogger) { this.equitiesParameters = equitiesParameters ?? throw new ArgumentNullException(nameof(equitiesParameters)); this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); this.tradingHoursService = tradingHoursService ?? throw new ArgumentNullException(nameof(tradingHoursService)); this.ruleContext = operationContext ?? throw new ArgumentNullException(nameof(operationContext)); this.alertStream = alertStream ?? throw new ArgumentNullException(nameof(alertStream)); this.orderFilter = orderFilter ?? throw new ArgumentNullException(nameof(orderFilter)); }
/// <summary> /// Initializes a new instance of the <see cref="CancelledOrderRule"/> class. /// </summary> /// <param name="parameters"> /// The parameters. /// </param> /// <param name="operationContext"> /// The operation context. /// </param> /// <param name="alertStream"> /// The alert stream. /// </param> /// <param name="orderFilter"> /// The order filter. /// </param> /// <param name="equityMarketCacheFactory"> /// The market cache factory. /// </param> /// <param name="fixedIncomeMarketCacheFactory"> /// The market cache factory. /// </param> /// <param name="runMode"> /// The run mode. /// </param> /// <param name="logger"> /// The logger. /// </param> /// <param name="tradingHistoryLogger"> /// The trading history logger. /// </param> public CancelledOrderRule( ICancelledOrderRuleEquitiesParameters parameters, ISystemProcessOperationRunRuleContext operationContext, IUniverseAlertStream alertStream, IUniverseOrderFilter orderFilter, IUniverseEquityMarketCacheFactory equityMarketCacheFactory, IUniverseFixedIncomeMarketCacheFactory fixedIncomeMarketCacheFactory, RuleRunMode runMode, ILogger <CancelledOrderRule> logger, ILogger <TradingHistoryStack> tradingHistoryLogger) : base( parameters?.Windows?.BackwardWindowSize ?? TimeSpan.FromMinutes(60), parameters?.Windows?.BackwardWindowSize ?? TimeSpan.FromMinutes(60), parameters?.Windows?.FutureWindowSize ?? TimeSpan.Zero, Rules.CancelledOrders, Versioner.Version(2, 0), "Cancelled Order Rule", operationContext, equityMarketCacheFactory, fixedIncomeMarketCacheFactory, runMode, logger, tradingHistoryLogger) { this.parameters = parameters ?? throw new ArgumentNullException(nameof(parameters)); this.operationContext = operationContext ?? throw new ArgumentNullException(nameof(operationContext)); this.alertStream = alertStream ?? throw new ArgumentNullException(nameof(alertStream)); this.orderFilter = orderFilter ?? throw new ArgumentNullException(nameof(orderFilter)); this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
/// <summary> /// Initializes a new instance of the <see cref="HighVolumeRule"/> class. /// </summary> /// <param name="equitiesParameters"> /// The equities parameters. /// </param> /// <param name="operationContext"> /// The operation context. /// </param> /// <param name="alertStream"> /// The alert stream. /// </param> /// <param name="orderFilter"> /// The order filter. /// </param> /// <param name="equityMarketCacheFactory"> /// The market cache factory. /// </param> /// <param name="fixedIncomeMarketCacheFactory"> /// The market cache factory. /// </param> /// <param name="tradingHoursService"> /// The trading hours service. /// </param> /// <param name="dataRequestSubscriber"> /// The data request subscriber. /// </param> /// <param name="currencyConverterService"> /// The currency converter service. /// </param> /// <param name="runMode"> /// The run mode. /// </param> /// <param name="logger"> /// The logger. /// </param> /// <param name="tradingHistoryLogger"> /// The trading history logger. /// </param> public HighVolumeRule( IHighVolumeRuleEquitiesParameters equitiesParameters, ISystemProcessOperationRunRuleContext operationContext, IUniverseAlertStream alertStream, IUniverseOrderFilter orderFilter, IUniverseEquityMarketCacheFactory equityMarketCacheFactory, IUniverseFixedIncomeMarketCacheFactory fixedIncomeMarketCacheFactory, IMarketTradingHoursService tradingHoursService, IUniverseDataRequestsSubscriber dataRequestSubscriber, ICurrencyConverterService currencyConverterService, RuleRunMode runMode, ILogger <IHighVolumeRule> logger, ILogger <TradingHistoryStack> tradingHistoryLogger) : base( equitiesParameters?.Windows.BackwardWindowSize ?? TimeSpan.FromDays(1), equitiesParameters?.Windows.BackwardWindowSize ?? TimeSpan.FromDays(1), equitiesParameters?.Windows?.FutureWindowSize ?? TimeSpan.Zero, Domain.Surveillance.Scheduling.Rules.HighVolume, EquityRuleHighVolumeFactory.Version, "High Volume Rule", operationContext, equityMarketCacheFactory, fixedIncomeMarketCacheFactory, runMode, logger, tradingHistoryLogger) { this.EquitiesParameters = equitiesParameters ?? throw new ArgumentNullException(nameof(equitiesParameters)); this.AlertStream = alertStream ?? throw new ArgumentNullException(nameof(alertStream)); this.OrderFilter = orderFilter ?? throw new ArgumentNullException(nameof(orderFilter)); this.TradingHoursService = tradingHoursService ?? throw new ArgumentNullException(nameof(tradingHoursService)); this.DataRequestSubscriber = dataRequestSubscriber ?? throw new ArgumentNullException(nameof(dataRequestSubscriber)); this.CurrencyConverterService = currencyConverterService ?? throw new ArgumentNullException(nameof(currencyConverterService)); this.Logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
public HighMarketCapFilter( IUniverseEquityMarketCacheFactory factory, RuleRunMode ruleRunMode, DecimalRangeRuleFilter marketCap, IMarketTradingHoursService tradingHoursService, ISystemProcessOperationRunRuleContext operationRunRuleContext, IUniverseDataRequestsSubscriber universeDataRequestsSubscriber, ICurrencyConverterService currencyConverterService, string ruleName, ILogger <HighMarketCapFilter> logger ) { _universeEquityInterdayCache = factory?.BuildInterday(ruleRunMode) ?? throw new ArgumentNullException(nameof(factory)); _ruleRunMode = ruleRunMode; _marketCapFilter = marketCap ?? DecimalRangeRuleFilter.None(); _tradingHoursService = tradingHoursService ?? throw new ArgumentNullException(nameof(tradingHoursService)); _operationRunRuleContext = operationRunRuleContext ?? throw new ArgumentNullException(nameof(operationRunRuleContext)); _universeDataRequestsSubscriber = universeDataRequestsSubscriber; this.currencyConverterService = currencyConverterService ?? throw new ArgumentNullException(nameof(currencyConverterService)); _name = ruleName; _logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
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); }
/// <summary> /// Initializes a new instance of the <see cref="PlacingOrdersWithNoIntentToExecuteRule"/> class. /// </summary> /// <param name="parameters"> /// The parameters. /// </param> /// <param name="orderFilter"> /// The order filter. /// </param> /// <param name="ruleContext"> /// The rule context. /// </param> /// <param name="equityMarketCacheFactory"> /// The market cache factory. /// </param> /// <param name="fixedIncomeMarketCacheFactory"> /// The market cache factory. /// </param> /// <param name="alertStream"> /// The alert stream. /// </param> /// <param name="dataRequestSubscriber"> /// The data request subscriber. /// </param> /// <param name="tradingHoursService"> /// The trading hours service. /// </param> /// <param name="runMode"> /// The run mode. /// </param> /// <param name="logger"> /// The logger. /// </param> /// <param name="tradingStackLogger"> /// The trading stack logger. /// </param> public PlacingOrdersWithNoIntentToExecuteRule( IPlacingOrderWithNoIntentToExecuteRuleEquitiesParameters parameters, IUniverseOrderFilter orderFilter, ISystemProcessOperationRunRuleContext ruleContext, IUniverseEquityMarketCacheFactory equityMarketCacheFactory, IUniverseFixedIncomeMarketCacheFactory fixedIncomeMarketCacheFactory, IUniverseAlertStream alertStream, IUniverseDataRequestsSubscriber dataRequestSubscriber, IMarketTradingHoursService tradingHoursService, RuleRunMode runMode, ILogger logger, ILogger <TradingHistoryStack> tradingStackLogger) : base( TimeSpan.FromHours(24), TimeSpan.FromHours(24), TimeSpan.Zero, Domain.Surveillance.Scheduling.Rules.PlacingOrderWithNoIntentToExecute, EquityRulePlacingOrdersWithoutIntentToExecuteFactory.Version, "Placing Orders With No Intent To Execute Rule", ruleContext, equityMarketCacheFactory, fixedIncomeMarketCacheFactory, runMode, logger, tradingStackLogger) { this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); this.ruleContext = ruleContext ?? throw new ArgumentNullException(nameof(ruleContext)); this.alertStream = alertStream ?? throw new ArgumentNullException(nameof(alertStream)); this.dataRequestSubscriber = dataRequestSubscriber ?? throw new ArgumentNullException(nameof(dataRequestSubscriber)); this.orderFilter = orderFilter ?? throw new ArgumentNullException(nameof(orderFilter)); this.parameters = parameters ?? throw new ArgumentNullException(nameof(parameters)); this.tradingHoursService = tradingHoursService ?? throw new ArgumentNullException(nameof(tradingHoursService)); }
public void Setup() { this._ruleCtx = A.Fake <ISystemProcessOperationRunRuleContext>(); this._apiRepository = A.Fake <IExchangeRateApiCachingDecorator>(); this._logger = A.Fake <ILogger <CurrencyConverterService> >(); this._currency = new Currency("USD"); this._conversionTime = new DateTime(2017, 8, 31); }
/// <summary> /// Initializes a new instance of the <see cref="FixedIncomeHighProfitsStreamRule"/> class. /// Constructor for the high profits stream rule /// </summary> /// <param name="fixedIncomeParameters"> /// parameters from the client service user interface /// </param> /// <param name="ruleContext"> /// auditing helper /// </param> /// <param name="costCalculatorFactory"> /// cost logic service factory /// </param> /// <param name="revenueCalculatorFactory"> /// revenue logic service factory /// </param> /// <param name="exchangeRateProfitCalculator"> /// exchange rate service /// </param> /// <param name="orderFilter"> /// classification financial instruments filtering service /// </param> /// <param name="equityMarketCacheFactory"> /// time bar cache factory /// </param> /// /// <param name="fixedIncomeMarketCacheFactory"> /// time bar cache factory /// </param> /// <param name="marketDataCacheFactory"> /// market time bar cache factory /// </param> /// <param name="dataRequestSubscriber"> /// data fetch pattern helper /// </param> /// <param name="judgementService"> /// rule analysis service /// </param> /// <param name="runMode"> /// forced or validation /// </param> /// <param name="logger"> /// logging helper /// </param> /// <param name="tradingHistoryLogger"> /// logging helper for trading history /// </param> public FixedIncomeHighProfitsStreamRule( IHighProfitsRuleFixedIncomeParameters fixedIncomeParameters, ISystemProcessOperationRunRuleContext ruleContext, ICostCalculatorFactory costCalculatorFactory, IRevenueCalculatorFactory revenueCalculatorFactory, IExchangeRateProfitCalculator exchangeRateProfitCalculator, IUniverseFixedIncomeOrderFilterService orderFilter, IUniverseEquityMarketCacheFactory equityMarketCacheFactory, IUniverseFixedIncomeMarketCacheFactory fixedIncomeMarketCacheFactory, IFixedIncomeMarketDataCacheStrategyFactory marketDataCacheFactory, IUniverseDataRequestsSubscriber dataRequestSubscriber, IFixedIncomeHighProfitJudgementService judgementService, ICurrencyConverterService currencyService, RuleRunMode runMode, ILogger <FixedIncomeHighProfitsRule> logger, ILogger <TradingHistoryStack> tradingHistoryLogger) : base( fixedIncomeParameters?.Windows?.BackwardWindowSize ?? TimeSpan.FromHours(8), fixedIncomeParameters?.Windows?.BackwardWindowSize ?? TimeSpan.FromHours(8), fixedIncomeParameters?.Windows?.FutureWindowSize ?? TimeSpan.Zero, Domain.Surveillance.Scheduling.Rules.FixedIncomeHighProfits, FixedIncomeHighProfitFactory.Version, "Fixed Income High Profit Rule", ruleContext, equityMarketCacheFactory, fixedIncomeMarketCacheFactory, runMode, logger, tradingHistoryLogger) { this.FixedIncomeParameters = fixedIncomeParameters ?? throw new ArgumentNullException(nameof(fixedIncomeParameters)); this.RuleCtx = ruleContext ?? throw new ArgumentNullException(nameof(ruleContext)); this.costCalculatorFactory = costCalculatorFactory ?? throw new ArgumentNullException(nameof(costCalculatorFactory)); this.revenueCalculatorFactory = revenueCalculatorFactory ?? throw new ArgumentNullException(nameof(revenueCalculatorFactory)); this.marketDataCacheFactory = marketDataCacheFactory ?? throw new ArgumentNullException(nameof(marketDataCacheFactory)); this.exchangeRateProfitCalculator = exchangeRateProfitCalculator ?? throw new ArgumentNullException( nameof(exchangeRateProfitCalculator)); this.orderFilter = orderFilter ?? throw new ArgumentNullException(nameof(orderFilter)); this.dataRequestSubscriber = dataRequestSubscriber ?? throw new ArgumentNullException(nameof(dataRequestSubscriber)); this.JudgementService = judgementService ?? throw new ArgumentNullException(nameof(judgementService)); this.currencyConverterService = currencyService ?? throw new ArgumentNullException(nameof(currencyService)); this.Logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
/// <summary> /// Initializes a new instance of the <see cref="BaseUniverseRule"/> class. /// </summary> /// <param name="tradeBackwardWindowSize"> /// The trade backward window size. /// </param> /// <param name="marketBackwardWindowSize"> /// The market backward window size. /// </param> /// <param name="forwardWindowSize"> /// The forward window size. /// </param> /// <param name="rules"> /// The rules. /// </param> /// <param name="version"> /// The version. /// </param> /// <param name="name"> /// The name. /// </param> /// <param name="ruleContext"> /// The rule context. /// </param> /// <param name="equityFactory"> /// The equity factory. /// </param> /// <param name="fixedIncomeFactory"> /// The fixed income factory. /// </param> /// <param name="runMode"> /// The run mode. /// </param> /// <param name="logger"> /// The logger. /// </param> /// <param name="tradingStackLogger"> /// The trading stack logger. /// </param> protected BaseUniverseRule( TimeSpan tradeBackwardWindowSize, TimeSpan marketBackwardWindowSize, TimeSpan forwardWindowSize, Rules rules, string version, string name, ISystemProcessOperationRunRuleContext ruleContext, IUniverseEquityMarketCacheFactory equityFactory, IUniverseFixedIncomeMarketCacheFactory fixedIncomeFactory, RuleRunMode runMode, ILogger logger, ILogger <TradingHistoryStack> tradingStackLogger) { this.TradeBackwardWindowSize = tradeBackwardWindowSize; this.ForwardWindowSize = forwardWindowSize; this.Rule = rules; this.Version = version ?? string.Empty; this.UniverseEquityIntradayCache = equityFactory?.BuildIntraday(marketBackwardWindowSize, runMode) ?? throw new ArgumentNullException(nameof(equityFactory)); this.FutureUniverseEquityIntradayCache = equityFactory?.BuildIntraday(forwardWindowSize, runMode) ?? throw new ArgumentNullException(nameof(equityFactory)); this.UniverseEquityInterdayCache = equityFactory?.BuildInterday(runMode) ?? throw new ArgumentNullException(nameof(equityFactory)); this.UniverseFixedIncomeIntradayCache = fixedIncomeFactory?.BuildIntraday(marketBackwardWindowSize, runMode) ?? throw new ArgumentNullException(nameof(fixedIncomeFactory)); this.FutureUniverseFixedIncomeIntradayCache = fixedIncomeFactory?.BuildIntraday(forwardWindowSize, runMode) ?? throw new ArgumentNullException(nameof(fixedIncomeFactory)); this.UniverseFixedIncomeInterdayCache = fixedIncomeFactory?.BuildInterday(runMode) ?? throw new ArgumentNullException(nameof(fixedIncomeFactory)); this.TradingHistory = new ConcurrentDictionary <InstrumentIdentifiers, ITradingHistoryStack>(); this.TradingFillsHistory = new ConcurrentDictionary <InstrumentIdentifiers, ITradingHistoryStack>(); this.TradingInitialHistory = new ConcurrentDictionary <InstrumentIdentifiers, ITradingHistoryStack>(); this.DelayedTradingHistory = new ConcurrentDictionary <InstrumentIdentifiers, ITradingHistoryStack>(); this.DelayedTradingFillsHistory = new ConcurrentDictionary <InstrumentIdentifiers, ITradingHistoryStack>(); this.DelayedTradingInitialHistory = new ConcurrentDictionary <InstrumentIdentifiers, ITradingHistoryStack>(); this.RuleCtx = ruleContext ?? throw new ArgumentNullException(nameof(ruleContext)); this.name = name ?? "Unnamed rule"; this.RunMode = runMode; this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); this.tradingStackLogger = tradingStackLogger ?? throw new ArgumentNullException(nameof(tradingStackLogger)); }
private Money?TryIndirectConversion( IReadOnlyCollection <ExchangeRateDto> exchangeRates, Money initialMoney, Currency targetCurrency, DateTime dayOfConversion, ISystemProcessOperationRunRuleContext ruleCtx) { var initialExchangeRate = this.GetExchangeRates(exchangeRates, initialMoney.Currency); var targetExchangeRate = this.GetExchangeRates(exchangeRates, targetCurrency); var sharedVariableRateInitial = initialExchangeRate.FirstOrDefault( ier => targetExchangeRate.Select(ter => ter.VariableCurrency).Contains(ier.VariableCurrency)); if (sharedVariableRateInitial == null) { this._logger.LogError( $"could not find a shared common currency using a one step approach for {initialMoney.Currency.Code} and {targetCurrency.Code} on {dayOfConversion}"); ruleCtx.EventException( $"could not find a shared common currency using a one step approach for {initialMoney.Currency.Code} and {targetCurrency.Code} on {dayOfConversion}"); return(null); } var sharedVariableRateTarget = targetExchangeRate.FirstOrDefault( tec => string.Equals( tec.VariableCurrency, sharedVariableRateInitial.VariableCurrency, StringComparison.InvariantCultureIgnoreCase)); if (sharedVariableRateTarget == null) { this._logger.LogError( $"could not find a shared common currency using a one step approach for {initialMoney.Currency.Code} and {targetCurrency.Code} on {dayOfConversion}"); ruleCtx.EventException( $"could not find a shared common currency using a one step approach for {initialMoney.Currency.Code} and {targetCurrency.Code} on {dayOfConversion}"); return(null); } var variableCurrencyInitial = new Money( initialMoney.Value * (decimal)sharedVariableRateInitial.Rate, sharedVariableRateInitial.VariableCurrency); var reciprocalExchangeRate = // ReSharper disable once CompareOfFloatsByEqualityOperator sharedVariableRateTarget.Rate != 0 ? 1 / (decimal)sharedVariableRateTarget.Rate : 0; var fixedTargetCurrencyInitial = new Money( variableCurrencyInitial.Value * reciprocalExchangeRate, targetCurrency); return(fixedTargetCurrencyInitial); }
private ExchangeRateDto TryIndirectConversion( IReadOnlyCollection <ExchangeRateDto> exchangeRates, Currency fixedCurrency, Currency variableCurrency, DateTime dayOfConversion, ISystemProcessOperationRunRuleContext ruleCtx) { var fixedExchangeRates = this.GetExchangeRates(exchangeRates, fixedCurrency); var variableExchangeRates = this.GetExchangeRates(exchangeRates, variableCurrency); var sharedVariableRateInitial = fixedExchangeRates.FirstOrDefault( ier => variableExchangeRates.Select(ter => ter.VariableCurrency).Contains(ier.VariableCurrency)); if (sharedVariableRateInitial == null) { this._logger.LogError( $"could not find a shared common currency using a one step approach for {fixedCurrency.Code} and {variableCurrency.Code} on {dayOfConversion}"); ruleCtx.EventException( $"could not find a shared common currency using a one step approach for {fixedCurrency.Code} and {variableCurrency.Code} on {dayOfConversion}"); return(null); } var sharedVariableRateTarget = variableExchangeRates.FirstOrDefault( tec => string.Equals( tec.VariableCurrency, sharedVariableRateInitial.VariableCurrency, StringComparison.InvariantCultureIgnoreCase)); if (sharedVariableRateTarget == null) { this._logger.LogError( $"could not find a shared common currency using a one step approach for {fixedCurrency.Code} and {variableCurrency.Code} on {dayOfConversion}"); ruleCtx.EventException( $"could not find a shared common currency using a one step approach for {fixedCurrency.Code} and {variableCurrency.Code} on {dayOfConversion}"); return(null); } var reciprocalExchangeRate = // ReSharper disable once CompareOfFloatsByEqualityOperator sharedVariableRateTarget.Rate != 0 ? 1 / (decimal)sharedVariableRateTarget.Rate : 0; var completeRate = (double)reciprocalExchangeRate * sharedVariableRateInitial.Rate; return(new ExchangeRateDto { DateTime = sharedVariableRateTarget.DateTime, FixedCurrency = fixedCurrency.Code, VariableCurrency = variableCurrency.Code, Rate = completeRate }); }
public void Setup() { this.parameters = A.Fake <IHighVolumeIssuanceRuleFixedIncomeParameters>(); this.fixedIncomeOrderFile = A.Fake <IUniverseFixedIncomeOrderFilterService>(); this.ruleContext = A.Fake <ISystemProcessOperationRunRuleContext>(); this.equityMarketCacheFactory = A.Fake <IUniverseEquityMarketCacheFactory>(); this.fixedIncomeMarketCacheFactory = A.Fake <IUniverseFixedIncomeMarketCacheFactory>(); this.marketTradingHoursService = A.Fake <IMarketTradingHoursService>(); this.tradingStackLogger = new NullLogger <TradingHistoryStack>(); }