public void Setup()
        {
            this.tradingData                    = new TradingDataContext();
            this.signalQueue                    = new ObservableQueue <Signal>();
            this.strategiesCounter              = 5;
            this.profitPointsSettingsCounter    = 4;
            this.takeProfitOrderSettingsCounter = 3;

            MakeAndAddStrategiesToTradingDataContext(this.strategiesCounter);
            Assert.AreEqual(this.strategiesCounter, this.tradingData.Get <IEnumerable <StrategyHeader> >().Count());

            MakeAndAddProfitPointsSettingsToTradingDataContext(this.profitPointsSettingsCounter);
            Assert.AreEqual(this.profitPointsSettingsCounter, this.tradingData.Get <IEnumerable <ProfitPointsSettings> >().Count());

            MakeAndAddTakeProfitOrderSettingsToTradingDataContext(this.takeProfitOrderSettingsCounter);
            Assert.AreEqual(this.takeProfitOrderSettingsCounter, this.tradingData.Get <IEnumerable <TakeProfitOrderSettings> >().Count());

            this.handlers = new StrategiesTakeProfitByPointsOnTickHandlers(this.tradingData, this.signalQueue, new NullLogger());
        }
Esempio n. 2
0
File: Proboy.cs Progetto: w1r2p1/TRx
        static void Main(string[] args)
        {
            LogAssemblyInfo();

            AddStrategySettings();

            StrategiesPlaceStopLossByPointsOnTradeHandlers stopLossOnTradeHandlers =
                new StrategiesPlaceStopLossByPointsOnTradeHandlers(TradingData.Instance,
                                                                   SignalQueue.Instance,
                                                                   DefaultLogger.Instance,
                                                                   AppSettings.GetValue <bool>("MeasureStopFromSignalPrice"));

            StrategiesStopLossByPointsOnTickHandlers stopLossOnTickHandlers =
                new StrategiesStopLossByPointsOnTickHandlers(TradingData.Instance,
                                                             SignalQueue.Instance,
                                                             DefaultLogger.Instance,
                                                             AppSettings.GetValue <bool>("MeasureStopFromSignalPrice"));

            StrategiesPlaceTakeProfitByPointsOnTradeHandlers takeProfitOnTradeHandlers =
                new StrategiesPlaceTakeProfitByPointsOnTradeHandlers(TradingData.Instance,
                                                                     SignalQueue.Instance,
                                                                     DefaultLogger.Instance,
                                                                     AppSettings.GetValue <bool>("MeasureProfitFromSignalPrice"));

            StrategiesTakeProfitByPointsOnTickHandlers takeProfitOnTickHandlers =
                new StrategiesTakeProfitByPointsOnTickHandlers(TradingData.Instance,
                                                               SignalQueue.Instance,
                                                               DefaultLogger.Instance,
                                                               AppSettings.GetValue <bool>("MeasureProfitFromSignalPrice"));

            SmartComHandlers.Instance.Add <_IStClient_DisconnectedEventHandler>(ScalperIsDisconnected);
            SmartComHandlers.Instance.Add <_IStClient_ConnectedEventHandler>(ScalperIsConnected);

            BreakOutOnTick openHandler =
                new BreakOutOnTick(strategyHeader,
                                   TradingData.Instance,
                                   SignalQueue.Instance,
                                   DefaultLogger.Instance);

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

            AddStrategySubscriptions();

            adapter.Start();

            while (true)
            {
                try
                {
                    string command = Console.ReadLine();

                    if (command == "x")
                    {
                        adapter.Stop();

                        ExportData <Order>(AppSettings.GetValue <bool>("ExportOrdersOnExit"));
                        ExportData <Trade>(AppSettings.GetValue <bool>("ExportTradesOnExit"));

                        break;
                    }

                    if (command == "p")
                    {
                        Console.Clear();

                        Console.WriteLine(String.Format("Реализованный профит и лосс составляет {0} пунктов",
                                                        TradingData.Instance.GetProfitAndLossPoints(strategyHeader)));
                    }

                    if (command == "t")
                    {
                        Console.Clear();

                        foreach (Trade item in TradingData.Instance.Get <IEnumerable <Trade> >())
                        {
                            Console.WriteLine(item.ToString());
                        }
                    }

                    if (command == "b")
                    {
                        Console.Clear();

                        foreach (Bar item in TradingData.Instance.Get <IEnumerable <Bar> >())
                        {
                            Console.WriteLine(item.ToString());
                        }
                    }
                }
                catch (System.Runtime.InteropServices.COMException e)
                {
                    DefaultLogger.Instance.Log(e.Message);

                    adapter.Restart();
                }
            }
        }