public void InitiateTrading(IStockExchangeStream stockStream, IOrderStream <Order> tradeStream) { lock (this._stateTransition) { if (stockStream == null) { this.Logger.Log( LogLevel.Error, "Initiation attempt in order data generator with null stock stream"); return; } if (tradeStream == null) { this.Logger.Log( LogLevel.Error, "Initiation attempt in order data generator with null trade stream"); return; } if (this._generatorExecuting) { this.Logger.LogInformation("Initiating new trading with predecessor active"); this._TerminateTrading(); } this.Logger.LogInformation("Order data generator initiated with new stock stream"); this.StockStream = stockStream; this.TradeStream = tradeStream; this._unsubscriber = stockStream.Subscribe(this); this._generatorExecuting = true; this._InitiateTrading(); } }
public void ExecuteTradeStrategy(EquityIntraDayTimeBarCollection frame, IOrderStream <Order> tradeOrders) { if (tradeOrders == null) { this._logger.Log(LogLevel.Error, "Received a null trade orders in the markov trade strategy"); throw new ArgumentNullException(nameof(tradeOrders)); } if (frame == null) { this._logger.LogInformation("A null frame was passed to the markov trade strategy"); return; } if (frame.Securities == null || frame.Securities.All(sec => sec == null)) { this._logger.LogInformation( "No securities were present on the exchange frame in the markov trade strategy"); return; } var tradableSecurities = frame.Securities.Where(sec => sec != null).ToList(); var numberOfTradeOrders = this._tradeVolumeStrategy.CalculateSecuritiesToTrade(tradableSecurities); if (numberOfTradeOrders <= 0) { this._logger.LogInformation("Markov trading strategy decided not to trade on this frame"); return; } this.GenerateAndSubmitTrades(frame, tradeOrders, numberOfTradeOrders); }
public void Setup() { this._unsubscriber = A.Fake <IDisposable>(); this._stockStream = A.Fake <IStockExchangeStream>(); this._tradeStream = A.Fake <IOrderStream <Order> >(); this._tradeStrategy = A.Fake <ITradeStrategy <Order> >(); this._logger = A.Fake <ILogger>(); A.CallTo(() => this._stockStream.Subscribe(A <IObserver <EquityIntraDayTimeBarCollection> > .Ignored)) .Returns(this._unsubscriber); }
/// <summary> /// Avoid dead locks with initiation terminating old trades /// </summary> private void _TerminateTrading() { this.Logger.LogInformation("Order data generator terminating trading"); this._unsubscriber?.Dispose(); this.StockStream = null; this.TradeStream = null; this._generatorExecuting = false; this._TerminateTradingStrategy(); }
private void GenerateAndSubmitTrades( EquityIntraDayTimeBarCollection frame, IOrderStream <Order> tradeOrders, int numberOfTradeOrders) { var securitiesToTradeIds = this.SecuritiesToTrade(frame, numberOfTradeOrders); var securitiesToTrade = securitiesToTradeIds.Select(sec => frame.Securities.ElementAt(sec)).ToList(); var trades = securitiesToTrade.Select(sec => this.GenerateTrade(sec, frame)).Where(trade => trade != null) .ToList(); foreach (var trade in trades) { tradeOrders.Add(trade); } this._logger.LogInformation($"Submitted {trades.Count} trade orders in frame"); }
public void InitiateTrading(IStockExchangeStream stockStream, IOrderStream <Order> tradeStream) { this._unsubscriber = stockStream.Subscribe(this); this._stream = this._streamFactory.Create(); this._baseGenerator.InitiateTrading(this._stream, tradeStream); }
public void ExecuteTradeStrategy(EquityIntraDayTimeBarCollection tick, IOrderStream <Order> tradeOrders) { }