Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            _candleManager = new CandleManager();

            if (!GetSetings())
                return;

            var storageRegistry = new StorageRegistry();
            ((LocalMarketDataDrive)storageRegistry.DefaultDrive).Path = _historyPath;

            var cbs = new TradeStorageCandleBuilderSource { StorageRegistry = storageRegistry };
            _candleManager.Sources.OfType<TimeFrameCandleBuilder>().Single().Sources.Add(cbs);


            

            _candleManager.Processing += GetCandles;


            foreach (var Sec in listOfName)
            {
                foreach (var timeFrame in listOfTimeFrame)
                {
                  
                   

                _series = new CandleSeries(typeof(TimeFrameCandle), Sec, timeFrame);

                LisfStreamWriters.Add(_series.ToString(), new StreamWriter(GetFileName(_series), false));


                _candleManager.Start(_series, _startTime, _endTime);

                


 
    }

            }

     

            Console.ReadKey();

            // Закроем все потоки которые мы записывали

            foreach (var strim in LisfStreamWriters)
            {
                strim.Value.Close();   
            }

        

        }
Ejemplo n.º 2
0
        private void OnStartClick(object sender, RoutedEventArgs e)
        {
            if (_strategy != null && _strategy.ProcessState != ProcessStates.Stopped)
            {
                _strategy.Stop();
                return;
            }

            if (this.Portfolios.SelectedPortfolio == null)
            {
                this.Portfolios.SelectedIndex = this.Portfolios.Items.Count - 1;
            }

            this.InitGrids();

            _candleManager = new CandleManager(_trader);

            // Добавление в источник свечек TimeFrameCandleBuilder источник данных в виде файлов гидры
            var storageRegistry = new StorageRegistry();
            ((LocalMarketDataDrive) storageRegistry.DefaultDrive).Path = this.txtHistoryPath.Text;
            ((LocalMarketDataDrive) storageRegistry.DefaultDrive).UseAlphabeticPath = true;

            var cbs = new TradeStorageCandleBuilderSource { StorageRegistry = storageRegistry };
            _candleManager.Sources.OfType<TimeFrameCandleBuilder>().Single().Sources.Add(cbs);

            // регистрируем наш тайм-фрейм
            var series = new CandleSeries(typeof(TimeFrameCandle), _security, this.MainOptVarItem.TimeFrame);

            _strategy = new EMAEventModelStrategy(series,
                new ExponentialMovingAverage { Length = this.MainOptVarItem.FilterOptPeriod},
                new ExponentialMovingAverage { Length = this.MainOptVarItem.LongOptPeriods },
                new ExponentialMovingAverage { Length = this.MainOptVarItem.ShortOptPeriods },
                this.MainOptVarItem.TakeProfitUnit, this.MainOptVarItem.StopLossUnit)
            {
                Volume = this.Volume,
                Security = _security,
                Portfolio = this.Portfolios.SelectedPortfolio,
                Trader = _trader,
                UseQuoting = true //_trader is QuikTrader // hack to turn quoting off for RealTimeEmulationTrader
            };

            DateTime startTime;
            if (!DateTime.TryParse(txtHistoryRangeBegin.Text, out startTime))
            {
                startTime = DateTime.Now.AddDays(-3);
                txtHistoryRangeBegin.Text = startTime.ToString();
            }

            this.InitChart(_strategy);
            _candleManager.Processing += (candleSeries, candle) =>
            {
                if (candle.State == CandleStates.Finished)
                {
                    this.GuiAsync(() => DrawCandleAndEma(candle));
                }
            };
            _candleManager.Start(series, startTime, DateTime.MaxValue);

            // Subscribe UI to all strategy actions
            _strategy.Trader.NewOrders += orders => orders.ForEach(OnOrderRegistered);
            _strategy.Trader.NewMyTrades += OnNewTrades;
            _strategy.Trader.NewMyTrades += trades => this.GuiAsync(() => trades.ForEach(DrawTrade));
            _strategy.PropertyChanged += (o, args) => this.GuiAsync(() => OnStrategyPropertyChanged(o, args));
            _strategy.ProcessStateChanged += strategy =>
            {
                if (strategy.ProcessState == ProcessStates.Started)
                {
                    this.Start.Content = "Stop";
                }
                else if (strategy.ProcessState == ProcessStates.Stopped)
                {
                    this.Start.Content = "Start";
                }
            };

            _logManager.Sources.Add(_strategy);

            // запускаем процесс получения стакана, необходимый для работы алгоритма котирования
            _strategy.Start();

            this.Start.Content = "Stop";
        }