protected override void OnStart() { ///<summary> /// Initialsise parameters from input data and pass to the factory which returns the object identified by IndicatorType /// </summary> var factoryParameters = new FactoryParameters { Bot = this, IndicatorType = "MA", MAType = MAType, FastPeriods = FastPeriods, SlowPeriods = SlowPeriods, SourceSeries = SourceSeries }; _indicator = new IndicatorFactory().GetIndicator(factoryParameters); ///<summary> /// Create instances of API objects to decouple API functions from the main logic in order to /// support unit testing and mocking /// </summary> _getOpenPositions = new GetOpenPositions(this); _closeOrders = new CloseOrders(this); _executeOrders = new ExecuteOrders(this); _manageOrders = new ManageOrders(); }
///<summary> /// This method receives initialised API objects and calls their methods buy, sell and close /// orders on the trading server. /// </summary> public void ExecuteBuyOrSellOrderOnSignal(IIndicators indicators, GetOpenPositions getOpenPositions, CloseOrders closeOrders, ExecuteOrders executeOrders) { if (indicators.IndicatorAlert() == "AlertLong" && getOpenPositions.LongPositions() == null) { if (getOpenPositions.ShortPositions() != null) { closeOrders.ClosePosition(getOpenPositions.ShortPositions()); } executeOrders.ExecuteBuyOrder(); } else if (indicators.IndicatorAlert() == "AlertShort" && getOpenPositions.ShortPositions() == null) { if (getOpenPositions.LongPositions() != null) { closeOrders.ClosePosition(getOpenPositions.LongPositions()); } executeOrders.ExecuteSellOrder(); } }