Пример #1
0
        //private static string[] assemblies = { "Interop.SmartCOM3Lib.dll", "TRL.Common.dll", "TRL.Connect.Smartcom.dll" };

        /// <summary>
        /// пример
        /// </summary>
        /// <param name="args"></param>
        public void SetupStrategy(string[] args)
        {
            ///TODO 91. вопрос как изолировать стратегию от процесса инициализации параметров стратегии и AppSettings
            //AddStrategySettings();
            //TradingData.Instance.Get<ICollection<Strategy>>().Add(strategyHeader);
            //TradingData.Instance.Get<ICollection<BarSettings>>().Add(barSettings);
            //TradingData.Instance.Get<ICollection<ProfitPointsSettings>>().Add(ppSettings);
            //TradingData.Instance.Get<ICollection<TakeProfitOrderSettings>>().Add(poSettings);
            //TradingData.Instance.Get<ICollection<StopPointsSettings>>().Add(spSettings);
            //TradingData.Instance.Get<ICollection<StopLossOrderSettings>>().Add(soSettings);

            //SMASettings smaSettings = new SMASettings(strategyHeader, 7, 14);
            int         maf         = AppSettings.GetValue <int>("MaFast");
            int         mas         = AppSettings.GetValue <int>("MaSlow");
            SMASettings smaSettings = new SMASettings(strategyHeader, maf, mas);

            TradingData.Instance.Get <ICollection <SMASettings> >().Add(smaSettings);

            //ReversMaOnBar reversHandler =
            //    new ReversMaOnBar(strategyHeader,
            //        TradingData.Instance,
            //        SignalQueue.Instance,
            //        DefaultLogger.Instance);

            //MakeRangeBarsOnTick updateBarsHandler;
            updateBarsHandler = new MakeRangeBarsOnTick(barSettings,
                                                        new TimeTracker(),
                                                        TradingData.Instance,
                                                        DefaultLogger.Instance);

            //IndicatorOnBar2Ma indicatorsOnBar;
            indicatorsOnBar = new IndicatorOnBar2Ma(strategyHeader,
                                                    TradingData.Instance,
                                                    SignalQueue.Instance,
                                                    DefaultLogger.Instance);

            indicatorsOnBar.AddMa1Handler(TradeConsole.ConsoleWriteLineValueDouble);
            indicatorsOnBar.AddMa2Handler(TradeConsole.ConsoleWriteLineValueDouble);
            indicatorsOnBar.AddCrossUpHandler(TradeConsole.ConsoleWriteLineValueBool);
            indicatorsOnBar.AddCrossDnHandler(TradeConsole.ConsoleWriteLineValueBool);

            //Отправляем данные клиентам
            {
                //SetupHubHandlers();
                if (AppSettings.GetValue <bool>("SignalHub"))
                {
                    //отправляем через signalR
                    indicatorsOnBar.AddMa1Handler(TradeHubStarter.sendValueDouble1);
                    indicatorsOnBar.AddMa2Handler(TradeHubStarter.sendValueDouble2);
                    indicatorsOnBar.AddCrossUpHandler(TradeHubStarter.sendValueBool);
                    indicatorsOnBar.AddCrossDnHandler(TradeHubStarter.sendValueBool);

                    //reversHandler.AddMa1Handler(TradeHubStarter.sendIndicator1);
                    //reversHandler.AddMa2Handler(TradeHubStarter.sendIndicator2);
                }
            }
        }
Пример #2
0
        //private static string[] assemblies = { "Interop.SmartCOM3Lib.dll", "TRL.Common.dll", "TRL.Connect.Smartcom.dll" };

        /// <summary>
        /// пример
        /// </summary>
        /// <param name="args"></param>
        public void SetupStrategy(string[] args)
        {
            //TradingData.Instance.Get<ICollection<Strategy>>().Add(strategyHeader);
            //TradingData.Instance.Get<ICollection<BarSettings>>().Add(barSettings);
            //TradingData.Instance.Get<ICollection<ProfitPointsSettings>>().Add(ppSettings);
            //TradingData.Instance.Get<ICollection<TakeProfitOrderSettings>>().Add(poSettings);
            //TradingData.Instance.Get<ICollection<StopPointsSettings>>().Add(spSettings);
            //TradingData.Instance.Get<ICollection<StopLossOrderSettings>>().Add(soSettings);

            //SMASettings smaSettings = new SMASettings(strategyHeader, 7, 14);
            int         maf         = AppSettings.GetValue <int>("MaFast");
            int         mas         = AppSettings.GetValue <int>("MaSlow");
            SMASettings smaSettings = new SMASettings(strategyHeader, maf, mas);

            TradingData.Instance.Get <ICollection <SMASettings> >().Add(smaSettings);

            //MakeRangeBarsOnTick updateBarsHandler;
            updateBarsHandler = new MakeRangeBarsOnTick(barSettings,
                                                        new TimeTracker(),
                                                        TradingData.Instance,
                                                        DefaultLogger.Instance);

            //IndicatorOnBar2Ma indicatorsOnBar;
            indicatorsOnBar = new IndicatorOnBar2Ma(strategyHeader,
                                                    TradingData.Instance,
                                                    SignalQueue.Instance,
                                                    DefaultLogger.Instance);

            indicatorsOnBar.AddMa1Handler(TradeConsole.ConsoleWriteLineValueDouble);
            indicatorsOnBar.AddMa2Handler(TradeConsole.ConsoleWriteLineValueDouble);
            indicatorsOnBar.AddCrossUpHandler(TradeConsole.ConsoleWriteLineValueBool);
            indicatorsOnBar.AddCrossDnHandler(TradeConsole.ConsoleWriteLineValueBool);

            //Отправляем данные клиентам
            {
                //SetupHubHandlers();
                if (AppSettings.GetValue <bool>("SignalHub"))
                {
                    //отправляем через signalR
                    indicatorsOnBar.AddMa1Handler(TradeHubStarter.sendValueDouble1);
                    indicatorsOnBar.AddMa2Handler(TradeHubStarter.sendValueDouble2);
                    indicatorsOnBar.AddCrossUpHandler(TradeHubStarter.sendValueBool);
                    indicatorsOnBar.AddCrossDnHandler(TradeHubStarter.sendValueBool);

                    //reversHandler.AddMa1Handler(TradeHubStarter.sendIndicator1);
                    //reversHandler.AddMa2Handler(TradeHubStarter.sendIndicator2);
                }
                else
                {
                    Console.WriteLine(String.Format("SignalHub is off"));
                }
            }

            //ReversMaOnBar reversHandler =
            reversHandler = new ReversMaOnBar(strategyHeader,
                                              TradingData.Instance,
                                              SignalQueue.Instance,
                                              DefaultLogger.Instance)
            {
                IndicatorsOnBar = indicatorsOnBar
            };

            double pp = AppSettings.GetValue <double>("ProfitPoints");

            //TakeProfitOnBar takeProfitOnBar =
            takeProfitOnBar =
                new TakeProfitOnBar(strategyHeader,
                                    200,
                                    TradingData.Instance,
                                    SignalQueue.Instance,
                                    DefaultLogger.Instance);

            //StopLossOnBar stopLossOnBar =
            stopLossOnBar =
                new StopLossOnBar(strategyHeader,
                                  100,
                                  TradingData.Instance,
                                  SignalQueue.Instance,
                                  DefaultLogger.Instance);
        }
Пример #3
0
        /// <summary>
        /// пример
        /// </summary>
        private void SetupRevers()
        {
            //AddStrategySettings();
            {
                TradingData.Instance.Get <ICollection <StrategyHeader> >().Add(strategyHeader);
                TradingData.Instance.Get <ICollection <BarSettings> >().Add(barSettings);

                //TradingData.Instance.Get<ICollection<ProfitPointsSettings>>().Add(ppSettings);
                //TradingData.Instance.Get<ICollection<TakeProfitOrderSettings>>().Add(poSettings);
                //TradingData.Instance.Get<ICollection<StopPointsSettings>>().Add(spSettings);
                //TradingData.Instance.Get<ICollection<StopLossOrderSettings>>().Add(soSettings);

                //SMASettings smaSettings = new SMASettings(strategyHeader, 7, 14);
                int         mafast      = AppSettings.GetValue <int>("MaFast");
                int         maslow      = AppSettings.GetValue <int>("MaSlow");
                SMASettings smaSettings = new SMASettings(strategyHeader, mafast, maslow);
                TradingData.Instance.Get <ICollection <SMASettings> >().Add(smaSettings);
            }

            //SmartComHandlers.Instance.Add<_IStClient_DisconnectedEventHandler>(IsDisconnected);
            //SmartComHandlers.Instance.Add<_IStClient_ConnectedEventHandler>(IsConnected);

            MakeRangeBarsOnTick updateBarsHandler =
                new MakeRangeBarsOnTick(barSettings,
                                        new TimeTracker(),
                                        TradingData.Instance,
                                        DefaultLogger.Instance);

            SendItemOnBar barItemSender =
                new SendItemOnBar(barSettings,
                                  TradingData.Instance);
            //barItemSender.AddItemHandler(TradeConsole.ConsoleWriteLineBar);

            IndicatorOnBar2Ma indicatorsOnBar =
                new IndicatorOnBar2Ma(strategyHeader,
                                      TradingData.Instance,
                                      SignalQueue.Instance,
                                      DefaultLogger.Instance);

            indicatorsOnBar.AddMa1Handler(TradeConsole.ConsoleWriteLineValueDouble);
            indicatorsOnBar.AddMa2Handler(TradeConsole.ConsoleWriteLineValueDouble);
            indicatorsOnBar.AddCrossUpHandler(TradeConsole.ConsoleWriteLineValueBool);
            indicatorsOnBar.AddCrossDnHandler(TradeConsole.ConsoleWriteLineValueBool);

            ReversMaOnBar reversHandler =
                new ReversMaOnBar(strategyHeader,
                                  TradingData.Instance,
                                  SignalQueue.Instance,
                                  DefaultLogger.Instance)
            {
                IndicatorsOnBar = indicatorsOnBar
            };

            SendItemOnTrade tradeItemSender =
                new SendItemOnTrade(TradingData.Instance, DefaultLogger.Instance);
            //tradeItemSender.AddItemHandler(TradeConsole.ConsoleWriteLineTrade);

            //SendItemOnOrder senderItemOrder =
            //    new SendItemOnOrder(TradingData.Instance.Get<ObservableQueue<Order>>());
            //senderItemOrder.AddedItemHandler(TradeHubStarter.sendOrder);

            //AddStrategySubscriptions();
            {
                DefaultSubscriber.Instance.Portfolios.Add(strategyHeader.Portfolio);
                DefaultSubscriber.Instance.BidsAndAsks.Add(strategyHeader.Symbol);
                DefaultSubscriber.Instance.Ticks.Add(strategyHeader.Symbol);
            }

            //Отправляем данные клиентам
            {
                barItemSender.AddItemHandler(TradeConsole.ConsoleWriteLineBar);
                tradeItemSender.AddItemHandler(TradeConsole.ConsoleWriteLineTrade);
                //senderItemOrder.AddedItemHandler(TradeHubStarter.sendOrder);

                //SetupHubHandlers();
                if (AppSettings.GetValue <bool>("SignalHub"))
                {
                    //отправляем через signalR
                    barItemSender.AddItemHandler(TradeHubStarter.sendBar);
                    tradeItemSender.AddItemHandler(TradeHubStarter.sendTrade);
                    indicatorsOnBar.AddMa1Handler(TradeHubStarter.sendValueDouble1);
                    indicatorsOnBar.AddMa2Handler(TradeHubStarter.sendValueDouble2);
                    indicatorsOnBar.AddCrossUpHandler(TradeHubStarter.sendValueBool);
                    indicatorsOnBar.AddCrossDnHandler(TradeHubStarter.sendValueBool);

                    //reversHandler.AddMa1Handler(TradeHubStarter.sendIndicator1);
                    //reversHandler.AddMa2Handler(TradeHubStarter.sendIndicator2);
                }
            }
        }