Ошибки при рестарте подписки на свечи 4.3.13
Atom Ответить
30.05.2016


При повторной подписке на свечи того же инструмента и того же таймфрейма в лог начинают сыпаться ошибки вида

Код

2016/05/30 15:52:09.090| |None |0 iteration
2016/05/30 15:52:10.339| |None |1 iteration
2016/05/30 15:52:10.341|Error |SmartTrader|System.InvalidOperationException: Subscribing
2016/05/30 15:52:10.351|Error |None |_smartTrader.Error : at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
at System.Environment.get_StackTrace()
at VisualMacdTests.Tests.<>c__DisplayClass0_0.<MultipleCandleSubscription>b__3(Exception error) in E:\Projects\Exchange\StockSharpProjects\VisualMacd\VisualMacdTests\Tests.cs:line 53
at Ecng.Common.DelegateHelper.SafeInvoke[T](Action`1 handler, T arg)
at StockSharp.Algo.Connector.OnProcessMessage(Message message)
at Ecng.Common.DelegateHelper.SafeInvoke[T](Action`1 handler, T arg)
at StockSharp.Messages.InMemoryMessageChannel.<Open>b__1()
at Ecng.Common.Converter.<>c__DisplayClassf.<DoInCulture>b__e()
at Ecng.Common.Converter.DoInCulture[T](CultureInfo cultureInfo, Func`1 func)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
2016/05/30 15:52:11.358| |None |2 iteration
2016/05/30 15:52:11.359|Error |SmartTrader|System.InvalidOperationException: Subscribed
2016/05/30 15:52:11.360|Error |None |_smartTrader.Error : at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
at System.Environment.get_StackTrace()
at VisualMacdTests.Tests.<>c__DisplayClass0_0.<MultipleCandleSubscription>b__3(Exception error) in E:\Projects\Exchange\StockSharpProjects\VisualMacd\VisualMacdTests\Tests.cs:line 53
at Ecng.Common.DelegateHelper.SafeInvoke[T](Action`1 handler, T arg)
at StockSharp.Algo.Connector.OnProcessMessage(Message message)
at Ecng.Common.DelegateHelper.SafeInvoke[T](Action`1 handler, T arg)
at StockSharp.Messages.InMemoryMessageChannel.<Open>b__1()
at Ecng.Common.Converter.<>c__DisplayClassf.<DoInCulture>b__e()
at Ecng.Common.Converter.DoInCulture[T](CultureInfo cultureInfo, Func`1 func)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
2016/05/30 15:52:12.363| |None |3 iteration
2016/05/30 15:52:12.364|Error |SmartTrader|System.InvalidOperationException: Subscribed
2016/05/30 15:52:12.364|Error |None |_smartTrader.Error : at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
at System.Environment.get_StackTrace()
at VisualMacdTests.Tests.<>c__DisplayClass0_0.<MultipleCandleSubscription>b__3(Exception error) in E:\Projects\Exchange\StockSharpProjects\VisualMacd\VisualMacdTests\Tests.cs:line 53
at Ecng.Common.DelegateHelper.SafeInvoke[T](Action`1 handler, T arg)
at StockSharp.Algo.Connector.OnProcessMessage(Message message)
at Ecng.Common.DelegateHelper.SafeInvoke[T](Action`1 handler, T arg)
at StockSharp.Messages.InMemoryMessageChannel.<Open>b__1()
at Ecng.Common.Converter.<>c__DisplayClassf.<DoInCulture>b__e()
at Ecng.Common.Converter.DoInCulture[T](CultureInfo cultureInfo, Func`1 func)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
2016/05/30 15:52:13.370| |None |4 iteration
2016/05/30 15:52:13.371|Error |SmartTrader|System.InvalidOperationException: Subscribed
2016/05/30 15:52:13.371|Error |None |_smartTrader.Error : at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
at System.Environment.get_StackTrace()
at VisualMacdTests.Tests.<>c__DisplayClass0_0.<MultipleCandleSubscription>b__3(Exception error) in E:\Projects\Exchange\StockSharpProjects\VisualMacd\VisualMacdTests\Tests.cs:line 53
at Ecng.Common.DelegateHelper.SafeInvoke[T](Action`1 handler, T arg)
at StockSharp.Algo.Connector.OnProcessMessage(Message message)
at Ecng.Common.DelegateHelper.SafeInvoke[T](Action`1 handler, T arg)
at StockSharp.Messages.InMemoryMessageChannel.<Open>b__1()
at Ecng.Common.Converter.<>c__DisplayClassf.<DoInCulture>b__e()
at Ecng.Common.Converter.DoInCulture[T](CultureInfo cultureInfo, Func`1 func)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()


Чуть попозже добавляются ещё и следующие (но думаю к делу это мало относится):

Код

2016/05/30 15:52:18.521|Error |SmartTrader|System.InvalidOperationException: Series TimeFrameCandle_RIM6@FORTS_00-01-00 was not started earlier.
at StockSharp.Algo.Candles.CandleManagerContainer.AddCandle(CandleSeries series, Candle candle)
at System.Action`2.Invoke(T1 arg1, T2 arg2)
at Ecng.Common.DelegateHelper.SafeInvoke[T1,T2](Action`2 handler, T1 arg1, T2 arg2)
at StockSharp.Algo.Candles.CandleManager.ExternalCandleSource.OnNewCandles(CandleSeries series, IEnumerable`1 candles)
at Ecng.Common.DelegateHelper.SafeInvoke[T1,T2](Action`2 handler, T1 arg1, T2 arg2)
at StockSharp.SmartCom.SmartTrader.OnProcessMessage(Message message)
at Ecng.Common.DelegateHelper.SafeInvoke[T](Action`1 handler, T arg)
at StockSharp.Messages.InMemoryMessageChannel.<Open>b__1()


Код теста:

Код

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Ecng.Common;
using StockSharp.Algo.Candles;
using StockSharp.BusinessEntities;
using StockSharp.Logging;
using StockSharp.Messages;
using StockSharp.SmartCom;
using Xunit;

namespace VisualMacdTests
{
    public class Tests
    {
        [Fact]
        public async Task MultipleCandleSubscription()
        {
            var _logManager = new LogManager();
            _logManager.Listeners.Add(new FileLogListener("smartcom_logs.txt"));
            var _smartTrader = new SmartTrader()
            {
                Address = "mxdemo.ittrade.ru:8443".To<EndPoint>(),
                Login = "*******",
                Password = "*******",
            };
            _logManager.Sources.Add(_smartTrader);

            //_logManager.Application.AddInfoLog(WorkingTimeToString(ExchangeBoard.Forts.WorkingTime));
            // подписываемся на событие об успешном восстановлении соединения
            _smartTrader.Restored += () =>
            {
                _logManager.Application.AddInfoLog("_smartTrader.Restored");
            };

            // подписываемся на событие разрыва соединения
            _smartTrader.ConnectionError += error =>
            {
                _logManager.Application.AddErrorLog(error, "_smartTrader.ConnectionError");
            };

            _smartTrader.MarketDataSubscriptionFailed += (security, type, error) =>
            {
                _logManager.Application.AddErrorLog(error, $"_smartTrader.MarketDataSubscriptionFailed {security.Id} {type}");
            };

            // подписываемся на ошибку обработки данных (транзакций и маркет)
            _smartTrader.Error += error =>
            {
                _logManager.Application.AddErrorLog(error, $"_smartTrader.Error : {Environment.StackTrace}");
            };
            Security tool = null;
            _smartTrader.NewSecurities += securities =>
            {
                var rimSec = securities.FirstOrDefault(s => 
                    s.Type != null 
                    && s.Type.Value == SecurityTypes.Future
                    && s.Id.Contains("RIM6")
                );
                if (rimSec != null)
                    tool = rimSec;
            };

            _smartTrader.UpdateSecurityByLevel1 = true;
            _smartTrader.UpdateSecurityLastQuotes = true;

            _smartTrader.Connect();

            var _candleManager = new CandleManager(_smartTrader);

            while (tool == null)
                await Task.Delay(100);

            var tf = SmartComTimeFrames.Minute1;
            /*
            for (int i = 0; i < 10; i++)
            {
                _logManager.Application.AddInfoLog($"{i} iteration");
                var marketTime = _smartTrader.CurrentTime;
                var to = marketTime;
                var from = to.Subtract(TimeSpan.FromDays(7));
                var _currentSeries = new CandleSeries(typeof(TimeFrameCandle), tool, tf);
                _smartTrader.SubscribeCandles(_currentSeries, from, DateTimeOffset.MaxValue);
                await Task.Delay(1000);
                _smartTrader.UnSubscribeCandles(_currentSeries);
            }
            */
            
            for (int i = 0; i < 10; i++)
            {
                _logManager.Application.AddInfoLog($"{i} iteration");
                var marketTime = _smartTrader.CurrentTime;
                var to = marketTime;
                var from = to.Subtract(TimeSpan.FromDays(7));
                var _currentSeries = new CandleSeries(typeof(TimeFrameCandle), tool, tf);
                _candleManager.Start(_currentSeries, from, DateTimeOffset.MaxValue);
                await Task.Delay(1000);
                _candleManager.Stop(_currentSeries);
            }
            
            _smartTrader.Disconnect();
        }
    }
}


На первом цикле (закомментированный) ошибки те же, кажется проблемы именно в смартком коннекторе.

Задержка в виде "await Task.Delay(1000);" не важна - в реальном приложении всё успевало прогрузиться до реал тайма, вылетало там же.

Теги:


Спасибо:




1 Ответов
agat50

Фотография
Программист
Дата: 04.06.2016
Ответить


Переделка на ожидание события Stopped в виде:

Код

for (int i = 0; i < 10; i++)
{
_logManager.Application.AddInfoLog($"{i} iteration");
var marketTime = _smartTrader.CurrentTime;
var to = marketTime;
var from = to.Subtract(TimeSpan.FromDays(7));
var _currentSeries = new CandleSeries(typeof(TimeFrameCandle), tool, tf);
_candleManager.Start(_currentSeries, from, DateTimeOffset.MaxValue);
await Task.Delay(1000);
var tcs = new TaskCompletionSource<object>();
var a = (Action<CandleSeries>)(series => {
_logManager.Application.AddInfoLog($"Stopped event triggered {series.Security.Id}");
if (series == _currentSeries)
tcs.TrySetResult(null);
});
_candleManager.Stopped += a;
try
{
_candleManager.Stop(_currentSeries);
await tcs.Task;
}
finally
{
_candleManager.Stopped -= a;
}
await Task.Delay(1000);
}


ничего не меняет.
Автор топика
Спасибо:


Добавить файлы через драг-н-дроп, , или вставить из буфера обмена.

loading
clippy