4.1.1 Проблема с тиковыми свечками

4.1.1 Проблема с тиковыми свечками
Atom
5/30/2012
Moadip


В обработчик события СandleManager.Processing обновленные свечки приходят примерно раз в 1сек.

Если написать что то подобное


_candleManager.Processing += (series, candle) =>
                                    {
                                        if(candle.State == CandleStates.Finished)
                                        {
                                            this.GuiAsync(() => MessageBox.Show(this, "Свечка закончена"));
                                        }
                                    };

И воткнуть бряк в условие, то его срабатывание можно ждать долго и упорно.

С таймфреймовыми свечками все нормально.


Tags:


Thanks:


Alexander

Avatar
Date: 5/31/2012
Reply


Приведите полный код работы со свечками - создание менеджера, серий, и т.д.

Thanks:

Moadip

Avatar
Date: 5/31/2012
Reply


Полный код для воспроизведения ошибки

CS


using System;
using System.Linq;
using System.Windows;
using System.Windows.Forms;
using System.ComponentModel;
using Ecng.Common;
using Ecng.Xaml;
using StockSharp.BusinessEntities;
using StockSharp.Quik;
using StockSharp.Algo.Candles;
using StockSharp.Xaml;
using StockSharp.Algo.Logging;
using MessageBox = System.Windows.MessageBox;

namespace Candles
{
	public partial class MainWindow
	{
		QuikTrader _trader;

		private Security _instr1;
		const string _secCode1 = "RIM2";

        private CandleManager _candleManager;
	    private CandleSeries _series;

	    readonly TimeSpan _timeFrame = TimeSpan.FromMinutes(1);

	    private readonly LogManager _logManager; 

		public MainWindow()
		{
			InitializeComponent();
            Path.Text = "e:\\Program Files\\QUIK\\";

            _logManager = new LogManager();
            _logManager.Listeners.Add(new GuiLogListener(logcontrol));
		}
	  

		private void FindPath_Click(object sender, RoutedEventArgs e)
		{
			var dlg = new FolderBrowserDialog();

			if (!Path.Text.IsEmpty())
				dlg.SelectedPath = Path.Text;

			if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
			{
				Path.Text = dlg.SelectedPath;
			}
		}

		bool _isConnected;

		private void btnConnect_Click(object sender, RoutedEventArgs e)
		{
			if (!_isConnected)
			{
				if (Path.Text.IsEmpty())
					MessageBox.Show(this, "Путь к Quik не выбран");
				else
				{
					if (_trader == null)
					{
                        _trader = new QuikTrader(Path.Text);
                        _logManager.Sources.Add(_trader);
                        _trader.ReConnectionSettings.Interval = TimeSpan.FromSeconds(10);
                        _trader.ReConnectionSettings.WorkingTime = Exchange.Rts.WorkingTime;
                        _trader.ReConnectionSettings.ConnectionRestored += () => this.GuiAsync(() => MessageBox.Show(this, "Соединение восстановлено"));
                        _trader.MarketTimeOffset = TimeSpan.FromHours(-3);

						_isConnected = true;

					    btnExportDde.IsEnabled = true;

						_trader.NewSecurities += securities =>
						{
							if (_instr1 == null)
							{
								_instr1 = securities.FirstOrDefault(sec => sec.Code == _secCode1);
							}
						};

						_candleManager = new CandleManager(_trader);
                        _candleManager.Processing += DrawCandles;

					}

					_trader.Connect();

					_isConnected = true;
					btnConnect.Content = "Отключиться";
				}
			}
			else
			{
				_trader.Disconnect();

				_isConnected = false;
				btnConnect.Content = "Подключиться";
			}
		}

        private void btnStart_Click(object sender, RoutedEventArgs e)
        {
            //_series = new CandleSeries(typeof(TimeFrameCandle), _instr1, _timeFrame);
            _series = new CandleSeries(typeof(TickCandle), _instr1, 100);

            _candleManager.Start(_series);
            _trader.AddInfoLog("Запуск получения свечек");
        }


		private void DrawCandles(CandleSeries series, Candle candle)
		{
            if(candle.State == CandleStates.Finished) 
                _trader.AddInfoLog(string.Format("Свечка закончена. CloseTime = {0}", candle.CloseTime));
		}

        private void Window_Closing(object sender, CancelEventArgs e)
        {
            if (_trader != null)
            {
                if (_isDdeStarted) StopDde();
                _trader.Dispose();
            }
        }

        private void btnExportDde_Click(object sender, RoutedEventArgs e)
        {
            if (_isDdeStarted) StopDde();
            else StartDde();
        }

        bool _isDdeStarted;

        private void StartDde()
        {
            _trader.StartExport();
            _isDdeStarted = true;
        }

        private void StopDde()
        {
            _trader.StopExport();
            _isDdeStarted = false;
        }
    }
}

XAML


<Window x:Class="Candles.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:EcngTradingXaml="clr-namespace:StockSharp.Xaml;assembly=StockSharp.Xaml"
        Title="" Height="455" Width="614" Closing="Window_Closing" Topmost="True" WindowStartupLocation="CenterScreen">
    <Grid>
        <Grid  HorizontalAlignment="Left" Name="grid1" VerticalAlignment="Top" Margin="12,12,0,0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="72" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Button Content="Подключиться" Height="23" HorizontalAlignment="Left" Name="btnConnect" VerticalAlignment="Top" Width="100" Click="btnConnect_Click" Grid.Row="1" />
            <Button Content="Экспорт DDE" Height="23" HorizontalAlignment="Left" Name="btnExportDde" VerticalAlignment="Top" Width="100" Click="btnExportDde_Click" IsEnabled="False" Grid.Column="1" Grid.Row="1" />
            <Button Content="Старт" Height="23" Name="btnStart" VerticalAlignment="Top" Click="btnStart_Click" HorizontalAlignment="Left" Width="100" Grid.Column="2" Grid.ColumnSpan="2" Grid.Row="1" />
            <TextBox Height="23" HorizontalAlignment="Left" Name="Path" VerticalAlignment="Top" Width="272" Grid.ColumnSpan="3"/>
            <Button Content="..." Name="FindPath" Click="FindPath_Click" HorizontalAlignment="Left" Width="28" Height="23" VerticalAlignment="Top" Grid.Column="3" />
        </Grid>
        <EcngTradingXaml:LogControl Margin="12,64,10,12" Name="logcontrol"/>
    </Grid>
</Window>

Если таймфреймовые свечки, то вот так

Если тиковые, то глухо

Стояла одна из последних сборок 4.1 все было нормально. Обновился до 4.1.1, вылез этот баг, потом скачал 17411, тоже самое.

Thanks:

aspirant

Avatar
Date: 5/31/2012
Reply


В каждую точку времени у первой тиковой свечки статус CandleState.Started, у всех остальных CandleState.Changed.

Started: 10:00:00 TickCandle SPFB.RTS (O:156220,00000, H:156220,00000, L:156220,00000, C:156220,00000, V:0) Changed: 10:00:00 TickCandle SPFB.RTS (O:156220,00000, H:156220,00000, L:156220,00000, C:156220,00000, V:1) Changed: 10:00:00 TickCandle SPFB.RTS (O:156220,00000, H:156220,00000, L:156205,00000, C:156205,00000, V:2)

CandleState.Finished не появляется вообще, поэтому в DrawCandles ничего и не происходит

У меня схожая проблема: по этой же причине с тиковыми свечками не вызывается WhenCandlesFinished()

Thanks:

Alexander

Avatar
Date: 6/2/2012
Reply


Пофиксил, выложим на codeplex в ближайшие пару дней

Thanks:


Attach files by dragging & dropping, , or pasting from the clipboard.

loading
clippy