Пример #1
0
        private void Process(IStorageRegistry storageRegistry, Security security, StorageFormats format, IMarketDataDrive drive)
        {
            this.GuiSync(() =>
            {
                _visibleEntries.Clear();

                Columns.RemoveRange(_candleColumns.Values);
                _candleColumns.Values.ForEach(c => FormatRules.Remove(c));
                _candleColumns.Clear();
            });

            if (security == null)
            {
                return;
            }

            var dict = new Dictionary <DateTime, MarketDataEntry>();

            drive = drive ?? storageRegistry.DefaultDrive;

            var candles = new Dictionary <string, Tuple <Type, object> >();

            lock (_syncObject)
            {
                if (_isChanged)
                {
                    return;
                }
            }

            foreach (var tuple in drive.GetCandleTypes(security.ToSecurityId(), format))
            {
                foreach (var arg in tuple.Item2)
                {
                    var key = tuple.Item1.Name.Replace("CandleMessage", string.Empty) + " " + arg;
                    candles.Add(key, Tuple.Create(tuple.Item1, arg));
                }
            }

            var candleNames = candles.Keys.ToArray();

            if (candleNames.Length > 0)
            {
                this.GuiSync(() =>
                {
                    foreach (var candleName in candleNames)
                    {
                        var column = new DataGridTextColumn
                        {
                            Header  = candleName,
                            Binding = new Binding
                            {
                                Path      = new PropertyPath("Candles[{0}]".Put(candleName)),
                                Converter = new BoolToCheckMarkConverter()
                            }
                        };
                        //var cbElement = new FrameworkElementFactory(typeof(CheckBox));

                        //var column = new DataGridTemplateColumn
                        //{
                        //	Header = candle,
                        //	CellStyle = new Style(),
                        //	//SortMemberPath = "Candles[{0}]".Put(key)
                        //	CellTemplate = new DataTemplate(typeof(CheckBox))
                        //	{
                        //		VisualTree = cbElement,
                        //	}
                        //};

                        //var bind = new Binding { Path = new PropertyPath("Candles[{0}]".Put(candle)) };

                        //cbElement.SetBinding(ToggleButton.IsCheckedProperty, bind);
                        //cbElement.SetValue(IsHitTestVisibleProperty, false);
                        //cbElement.SetValue(HorizontalAlignmentProperty, HorizontalAlignment.Center);

                        Columns.Add(column);
                        _candleColumns.Add(candleName, column);

                        //ApplyFormatRules(column);
                    }

                    //ApplyFormatRules();
                });
            }

            Add(dict, storageRegistry.GetTickMessageStorage(security, drive, format).Dates, candleNames, e => e.IsTick         = true);
            Add(dict, storageRegistry.GetQuoteMessageStorage(security, drive, format).Dates, candleNames, e => e.IsDepth       = true);
            Add(dict, storageRegistry.GetLevel1MessageStorage(security, drive, format).Dates, candleNames, e => e.IsLevel1     = true);
            Add(dict, storageRegistry.GetOrderLogMessageStorage(security, drive, format).Dates, candleNames, e => e.IsOrderLog = true);

            foreach (var c in candleNames)
            {
                var candleName = c;

                lock (_syncObject)
                {
                    if (_isChanged)
                    {
                        return;
                    }
                }

                var tuple = candles[candleName];
                Add(dict, storageRegistry.GetCandleMessageStorage(tuple.Item1, security, tuple.Item2, drive, format).Dates, candleNames, e => e.Candles[candleName] = true);
            }

            if (dict.Count > 0)
            {
                // add gaps by working days
                var emptyDays = dict.Keys.Min().Range(dict.Keys.Max(), TimeSpan.FromDays(1))
                                .Where(d => !dict.ContainsKey(d) /* && security.Board.WorkingTime.IsTradeDate(d, true)*/)
                                .OrderBy()
                                .ToList();

                foreach (var monthGroup in emptyDays.ToArray().GroupBy(d => new DateTime(d.Year, d.Month, 1)))
                {
                    var firstDay = monthGroup.First();
                    var lastDay  = monthGroup.Last();

                    // whole month do not have any values
                    if (firstDay.Day == 1 && lastDay.Day == monthGroup.Key.DaysInMonth())
                    {
                        emptyDays.RemoveRange(monthGroup);
                    }
                }

                Add(dict, emptyDays, candleNames, e => { });
            }

            lock (_syncObject)
            {
                if (_isChanged)
                {
                    return;
                }
            }

            this.GuiSync(RefreshSort);
        }
Пример #2
0
        private void Process(IStorageRegistry storageRegistry, Security security, StorageFormats format, IMarketDataDrive drive)
        {
            this.GuiSync(() =>
            {
                _visibleEntries.Clear();

                Columns.RemoveRange(_candleColumns.Values);
                _candleColumns.Values.ForEach(c => FormatRules.Remove(c));
                _candleColumns.Clear();
            });

            if (security == null)
            {
                return;
            }

            var dict = new Dictionary <DateTime, MarketDataEntry>();

            drive = drive ?? storageRegistry.DefaultDrive;

            var candles = new Dictionary <string, Tuple <Type, object> >();

            lock (_syncObject)
            {
                if (_isChanged)
                {
                    return;
                }
            }

            foreach (var tuple in drive.GetCandleTypes(security.ToSecurityId(), format))
            {
                foreach (var arg in tuple.Item2)
                {
                    var key = tuple.Item1.Name.Replace("Candle", string.Empty) + " " + arg;
                    candles.Add(key, Tuple.Create(tuple.Item1, arg));
                }
            }

            var candleKeys = candles.Keys.ToArray();

            if (candleKeys.Length > 0)
            {
                this.GuiSync(() =>
                {
                    foreach (var candle in candleKeys)
                    {
                        var column = new DataGridTextColumn
                        {
                            Header  = candle,
                            Binding = new Binding
                            {
                                Path      = new PropertyPath("Candles[{0}]".Put(candle)),
                                Converter = new BoolToCheckMarkConverter()
                            }
                        };
                        //var cbElement = new FrameworkElementFactory(typeof(CheckBox));

                        //var column = new DataGridTemplateColumn
                        //{
                        //	Header = candle,
                        //	CellStyle = new Style(),
                        //	//SortMemberPath = "Candles[{0}]".Put(key)
                        //	CellTemplate = new DataTemplate(typeof(CheckBox))
                        //	{
                        //		VisualTree = cbElement,
                        //	}
                        //};

                        //var bind = new Binding { Path = new PropertyPath("Candles[{0}]".Put(candle)) };

                        //cbElement.SetBinding(ToggleButton.IsCheckedProperty, bind);
                        //cbElement.SetValue(IsHitTestVisibleProperty, false);
                        //cbElement.SetValue(HorizontalAlignmentProperty, HorizontalAlignment.Center);

                        Columns.Add(column);
                        _candleColumns.Add(candle, column);

                        //ApplyFormatRules(column);
                    }

                    //ApplyFormatRules();
                });
            }

            Add(dict, storageRegistry.GetTradeStorage(security, drive, format), candleKeys, e => e.IsTick           = true);
            Add(dict, storageRegistry.GetMarketDepthStorage(security, drive, format), candleKeys, e => e.IsDepth    = true);
            Add(dict, storageRegistry.GetLevel1MessageStorage(security, drive, format), candleKeys, e => e.IsLevel1 = true);
            Add(dict, storageRegistry.GetOrderLogStorage(security, drive, format), candleKeys, e => e.IsOrderLog    = true);

            foreach (var candle in candleKeys)
            {
                lock (_syncObject)
                {
                    if (_isChanged)
                    {
                        return;
                    }
                }

                var tuple = candles[candle];
                Add(dict, storageRegistry.GetCandleStorage(tuple.Item1, security, tuple.Item2, drive, format), candleKeys, e => e.Candles[candle] = true);
            }

            if (dict.Count > 0)
            {
                // добавляем рабочие дни, которые отсутствуют в данных
                var emptyDays = dict.Keys.Min().Range(dict.Keys.Max(), TimeSpan.FromDays(1))
                                .Where(d => security.Board.WorkingTime.IsTradeDate(d, true) && !dict.ContainsKey(d));

                foreach (var batch in emptyDays.Batch(10))
                {
                    lock (_syncObject)
                    {
                        if (_isChanged)
                        {
                            return;
                        }
                    }

                    TryAddEntries(dict, batch, candleKeys, e => {});
                }
            }

            lock (_syncObject)
            {
                if (_isChanged)
                {
                    return;
                }
            }

            this.GuiSync(RefreshSort);
        }