Beispiel #1
0
        private void RefreshCharts()
        {
            if (Dispatcher.CheckAccess())
            {
                _dataThreadActions.Add(RefreshCharts);
                return;
            }

            this.GuiSync(() =>
            {
                Chart.ClearAreas();

                _areaComb = new ChartArea();

                var yAxis = _areaComb.YAxises.First();

                yAxis.AutoRange    = true;
                Chart.IsAutoRange  = true;
                Chart.IsAutoScroll = true;

                Chart.AddArea(_areaComb);

                var id = (SecurityId)Securities.SelectedItem;

                _security = new Security
                {
                    Id        = id.ToStringId(),
                    Code      = id.SecurityCode,
                    Type      = SecurityTypes.Future,
                    PriceStep = id.SecurityCode.StartsWith("RI", StringComparison.InvariantCultureIgnoreCase) ? 10 :
                                id.SecurityCode.Contains("ES") ? 0.25m :
                                0.01m,
                    Board = ExchangeBoard.Associated
                };

                _securityProvider.Clear();
                _securityProvider.Add(_security);

                _tradeGenerator = new RandomWalkTradeGenerator(id);
                _tradeGenerator.Init();
                _tradeGenerator.Process(_security.ToMessage());

                var series = new CandleSeries(
                    SeriesEditor.Settings.CandleType,
                    _security,
                    SeriesEditor.Settings.Arg)
                {
                    IsCalcVolumeProfile = true
                };

                _candleElement = new ChartCandleElement {
                    FullTitle = "Candles"
                };
                Chart.AddElement(_areaComb, _candleElement, series);
            });
        }
Beispiel #2
0
        private void RefreshCharts()
        {
            Chart.ClearAreas();

            _areaComb = new ChartArea();

            var yAxis = _areaComb.YAxises.First();

            yAxis.AutoRange    = true;
            Chart.IsAutoRange  = true;
            Chart.IsAutoScroll = true;

            Chart.AddArea(_areaComb);

            _timeframe = TimeSpan.FromMinutes(((ComboBoxItem)Timeframe.SelectedItem).Tag.To <int>());

            var id = (SecurityId)Securities.SelectedItem;

            _security = new Security
            {
                Id        = id.ToStringId(),
                PriceStep = id.SecurityCode.StartsWith("RI", StringComparison.InvariantCultureIgnoreCase) ? 10 :
                            id.SecurityCode.Contains("ES") ? 0.25m :
                            0.01m,
                Board = ExchangeBoard.Associated
            };

            _tradeGenerator = new RandomWalkTradeGenerator(id);
            _tradeGenerator.Init();
            _tradeGenerator.Process(_security.ToMessage());

            var series = new CandleSeries(
                typeof(TimeFrameCandle),
                _security,
                _timeframe);

            _candleElement = new ChartCandleElement {
                FullTitle = "Candles"
            };
            Chart.AddElement(_areaComb, _candleElement, series);

            LoadData(_security);
        }
Beispiel #3
0
        private void LoadData(CandleSeries series)
        {
            var msgType = series.CandleType.ToCandleMessageType();

            _transactionId = _transactionIdGenerator.GetNextId();
            _holder.Clear();
            _holder.CreateCandleSeries(_transactionId, series);

            _candleTransform.Process(new ResetMessage());
            _candleBuilder = _builderProvider.Get(msgType.ToCandleMarketDataType());

            var storage = new StorageRegistry();

            BusyIndicator.IsBusy = true;

            var path    = HistoryPath.Folder;
            var isBuild = BuildFromTicks.IsChecked == true;
            var format  = Format.SelectedFormat;

            var maxDays = (isBuild || series.CandleType != typeof(TimeFrameCandle))
                                ? 2
                                : 30 * (int)((TimeSpan)series.Arg).TotalMinutes;

            _mdMsg = series.ToMarketDataMessage(true);

            Task.Factory.StartNew(() =>
            {
                var date = DateTime.MinValue;

                if (isBuild)
                {
                    foreach (var tick in storage.GetTickMessageStorage(series.Security, new LocalMarketDataDrive(path), format).Load())
                    {
                        _tradeGenerator.Process(tick);

                        if (_candleTransform.Process(tick))
                        {
                            var candles = _candleBuilder.Process(_mdMsg, _currCandle, _candleTransform);

                            foreach (var candle in candles)
                            {
                                _currCandle = candle;
                                _updatedCandles.Add((CandleMessage)candle.Clone());
                            }
                        }

                        _lastTime = tick.ServerTime;

                        if (date != tick.ServerTime.Date)
                        {
                            date = tick.ServerTime.Date;

                            var str = date.To <string>();
                            this.GuiAsync(() => BusyIndicator.BusyContent = str);

                            maxDays--;

                            if (maxDays == 0)
                            {
                                break;
                            }
                        }
                    }
                }
                else
                {
                    foreach (var candleMsg in storage.GetCandleMessageStorage(msgType, series.Security, series.Arg, new LocalMarketDataDrive(path), format).Load())
                    {
                        if (candleMsg.State != CandleStates.Finished)
                        {
                            candleMsg.State = CandleStates.Finished;
                        }

                        _currCandle = candleMsg;
                        _updatedCandles.Add(candleMsg);

                        _lastTime = candleMsg.OpenTime;

                        if (candleMsg is TimeFrameCandleMessage)
                        {
                            _lastTime += (TimeSpan)series.Arg;
                        }

                        _tradeGenerator.Process(new ExecutionMessage
                        {
                            ExecutionType = ExecutionTypes.Tick,
                            SecurityId    = series.Security.ToSecurityId(),
                            ServerTime    = _lastTime,
                            TradePrice    = candleMsg.ClosePrice,
                        });

                        if (date != candleMsg.OpenTime.Date)
                        {
                            date = candleMsg.OpenTime.Date;

                            var str = date.To <string>();
                            this.GuiAsync(() => BusyIndicator.BusyContent = str);

                            maxDays--;

                            if (maxDays == 0)
                            {
                                break;
                            }
                        }
                    }
                }

                _historyLoaded = true;
            })
            .ContinueWith(t =>
            {
                if (t.Exception != null)
                {
                    Error(t.Exception.Message);
                }

                BusyIndicator.IsBusy          = false;
                Chart.IsAutoRange             = false;
                ModifyAnnotationBtn.IsEnabled = true;
                NewAnnotationBtn.IsEnabled    = true;
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
        private void LoadData(Security security)
        {
            _candle    = null;
            _lastPrice = 0m;
            _allCandles.Clear();

            Chart.Reset(new IChartElement[] { _candleElement });

            var storage = new StorageRegistry();

            BusyIndicator.IsBusy = true;

            var path    = HistoryPath.Folder;
            var isBuild = BuildFromTicks.IsChecked == true;
            var format  = Format.SelectedFormat;

            var maxDays = isBuild ? 2 : 30 * (int)_timeframe.TotalMinutes;

            Task.Factory.StartNew(() =>
            {
                var date = DateTime.MinValue;

                if (isBuild)
                {
                    foreach (var tick in storage.GetTickMessageStorage(security, new LocalMarketDataDrive(path), format).Load())
                    {
                        AppendTick(security, tick);

                        _lastTime = tick.ServerTime;

                        if (date != tick.ServerTime.Date)
                        {
                            date = tick.ServerTime.Date;

                            var str = date.To <string>();
                            this.GuiAsync(() => BusyIndicator.BusyContent = str);

                            maxDays--;

                            if (maxDays == 0)
                            {
                                break;
                            }
                        }
                    }
                }
                else
                {
                    foreach (var candle in storage.GetCandleStorage(typeof(TimeFrameCandle), security, _timeframe, new LocalMarketDataDrive(path), format).Load())
                    {
                        lock (_updatedCandles.SyncRoot)
                            _updatedCandles[candle.OpenTime] = _candle = (TimeFrameCandle)candle;

                        _lastTime  = candle.OpenTime + _timeframe;
                        _lastPrice = _candle.ClosePrice;

                        _tradeGenerator.Process(new ExecutionMessage
                        {
                            ExecutionType = ExecutionTypes.Tick,
                            SecurityId    = security.ToSecurityId(),
                            ServerTime    = _lastTime,
                            TradePrice    = _lastPrice,
                        });

                        if (date != candle.OpenTime.Date)
                        {
                            date = candle.OpenTime.Date;

                            var str = date.To <string>();
                            this.GuiAsync(() => BusyIndicator.BusyContent = str);

                            maxDays--;

                            if (maxDays == 0)
                            {
                                break;
                            }
                        }
                    }
                }
            })
            .ContinueWith(t =>
            {
                if (t.Exception != null)
                {
                    Error(t.Exception.Message);
                }

                this.GuiAsync(() =>
                {
                    BusyIndicator.IsBusy = false;
                    Chart.IsAutoRange    = false;
                    //_areaComb.YAxises.First().AutoRange = false;
                });
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
Beispiel #5
0
        private void LoadData(CandleSeries series)
        {
            _currCandle    = null;
            _historyLoaded = false;
            _allCandles.Clear();

            _candleTransform.Process(new ResetMessage());
            _candleBuilder = series.CandleType.ToCandleMessageType().ToCandleMarketDataType().CreateCandleBuilder();

            Chart.Reset(new IChartElement[] { _candleElement });

            var storage = new StorageRegistry();

            BusyIndicator.IsBusy = true;

            var path    = HistoryPath.Folder;
            var isBuild = BuildFromTicks.IsChecked == true;
            var format  = Format.SelectedFormat;

            var maxDays = (isBuild || series.CandleType != typeof(TimeFrameCandle))
                                ? 5
                                : 30 * (int)((TimeSpan)series.Arg).TotalMinutes;

            _mdMsg = series.ToMarketDataMessage(true);

            Task.Factory.StartNew(() =>
            {
                var date = DateTime.MinValue;

                if (isBuild)
                {
                    foreach (var tick in storage.GetTickMessageStorage(series.Security, new LocalMarketDataDrive(path), format).Load())
                    {
                        _tradeGenerator.Process(tick);

                        if (_candleTransform.Process(tick))
                        {
                            var candles = _candleBuilder.Process(_mdMsg, _currCandle, _candleTransform);

                            lock (_lock)
                            {
                                foreach (var candle in candles)
                                {
                                    _currCandle = candle;
                                    _updatedCandles[candle.OpenTime] = Tuple.Create(candle, candle.State == CandleStates.Finished);
                                }
                            }
                        }

                        _lastTime = tick.ServerTime;

                        if (date != tick.ServerTime.Date)
                        {
                            date = tick.ServerTime.Date;

                            var str = date.To <string>();
                            this.GuiAsync(() => BusyIndicator.BusyContent = str);

                            maxDays--;

                            if (maxDays == 0)
                            {
                                break;
                            }
                        }
                    }
                }
                else
                {
                    foreach (var candleMsg in storage.GetCandleMessageStorage(series.CandleType.ToCandleMessageType(), series.Security, series.Arg, new LocalMarketDataDrive(path), format).Load())
                    {
                        lock (_updatedCandles.SyncRoot)
                        {
                            _currCandle = candleMsg;
                            _updatedCandles[candleMsg.OpenTime] = Tuple.Create(candleMsg, true);
                        }

                        _lastTime = candleMsg.OpenTime;

                        if (candleMsg is TimeFrameCandleMessage)
                        {
                            _lastTime += (TimeSpan)series.Arg;
                        }

                        _tradeGenerator.Process(new ExecutionMessage
                        {
                            ExecutionType = ExecutionTypes.Tick,
                            SecurityId    = series.Security.ToSecurityId(),
                            ServerTime    = _lastTime,
                            TradePrice    = candleMsg.ClosePrice,
                        });

                        if (date != candleMsg.OpenTime.Date)
                        {
                            date = candleMsg.OpenTime.Date;

                            var str = date.To <string>();
                            this.GuiAsync(() => BusyIndicator.BusyContent = str);

                            maxDays--;

                            if (maxDays == 0)
                            {
                                break;
                            }
                        }
                    }
                }

                _historyLoaded = true;
            })
            .ContinueWith(t =>
            {
                if (t.Exception != null)
                {
                    Error(t.Exception.Message);
                }

                this.GuiAsync(() =>
                {
                    BusyIndicator.IsBusy = false;
                    Chart.IsAutoRange    = false;
                    //_areaComb.YAxises.First().AutoRange = false;
                });
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }