Пример #1
0
 public DeployerContext(ISimultaneousKeys keys, IProjectSelector projectSelect,
                        ICharDisplay lcd,
                        IIndicators indicatorRefresh, ISound sound, IWebUtility netio, INetwork network,
                        IWebRequestFactory webFactory, IGarbage garbage,
                        IConfigurationService configurationService)
 {
     _keys                 = keys;
     _projectSelect        = projectSelect;
     _lcd                  = lcd;
     _indicatorRefresh     = indicatorRefresh;
     _sound                = sound;
     _netio                = netio;
     _network              = network;
     _webFactory           = webFactory;
     _garbage              = garbage;
     _configurationService = configurationService;
 }
Пример #2
0
 public DeployerContext(ISimultaneousKeys keys, IProjectSelector projectSelect,
                        ICharDisplay lcd,
                        IIndicators indicatorRefresh, ISound sound, IWebUtility netio, INetwork network,
                        IWebRequestFactory webFactory, IGarbage garbage,
                        IConfigurationService configurationService)
 {
     _keys = keys;
     _projectSelect = projectSelect;
     _lcd = lcd;
     _indicatorRefresh = indicatorRefresh;
     _sound = sound;
     _netio = netio;
     _network = network;
     _webFactory = webFactory;
     _garbage = garbage;
     _configurationService = configurationService;
 }
        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();
            }
        }