/// <summary> /// Запустить таймер получения из переданного <paramref name="connector"/> свечек реального времени. /// </summary> /// <typeparam name="TConnector">Тип подключения, реализующего <see cref="IExternalCandleSource"/>.</typeparam> /// <param name="connector">Подключение, реализующее <see cref="IExternalCandleSource"/>.</param> /// <param name="registeredSeries">Все зарегистрированные серии свечек.</param> /// <param name="offset">Временной отступ для нового запроса получение новой свечи. Необходим для того, чтобы сервер успел сформировать данные в своем хранилище свечек.</param> /// <param name="requestNewCandles">Обработчик, получающий новые свечи.</param> /// <param name="interval">Периодичность обновления данных.</param> /// <returns>Созданный таймер.</returns> public static Timer StartRealTime <TConnector>(this TConnector connector, CachedSynchronizedSet <CandleSeries> registeredSeries, TimeSpan offset, Action <CandleSeries, Range <DateTimeOffset> > requestNewCandles, TimeSpan interval) where TConnector : class, IConnector, IExternalCandleSource { if (connector == null) { throw new ArgumentNullException("connector"); } if (registeredSeries == null) { throw new ArgumentNullException("registeredSeries"); } if (requestNewCandles == null) { throw new ArgumentNullException("requestNewCandles"); } return(ThreadingHelper.Timer(() => { if (connector.ConnectionState != ConnectionStates.Connected || connector.ExportState != ConnectionStates.Connected) { return; } lock (registeredSeries.SyncRoot) { foreach (var series in registeredSeries.Cache) { var tf = (TimeSpan)series.Arg; var time = connector.CurrentTime.LocalDateTime; var bounds = tf.GetCandleBounds(time, series.Security.Board); var beginTime = time - bounds.Min < offset ? bounds.Min - tf : bounds.Min; var finishTime = bounds.Max; requestNewCandles(series, new Range <DateTimeOffset>(beginTime, finishTime)); } } }) .Interval(interval)); }
/// <summary> /// Initializes a new instance of the <see cref="SecurityPicker"/>. /// </summary> public SecurityPicker() { InitializeComponent(); _counterMask = Counter.Text; GuiDispatcher.GlobalDispatcher.AddPeriodicalAction(() => { if (!_isDirty) { return; } _isDirty = false; FilterSecurities(); }); GuiDispatcher.GlobalDispatcher.AddPeriodicalAction(() => { if (!_isCounterDirty) { return; } _isCounterDirty = false; UpdateCounter(); }); _excludeSecurities = new CachedSynchronizedSet <Security>(); _excludeSecurities.Added += s => SecurityProviderOnSecuritiesChanged(true, NotifyCollectionChangedAction.Add, s); _excludeSecurities.Removed += s => SecurityProviderOnSecuritiesChanged(true, NotifyCollectionChangedAction.Remove, s); _excludeSecurities.Cleared += () => SecurityProviderOnSecuritiesChanged(true, NotifyCollectionChangedAction.Reset, null); SecurityProvider = null; SecuritiesCtrl.SelectionMode = _defaultSelectionMode; UpdateCounter(); SecurityTypeCtrl.NullItem.Description = LocalizedStrings.Str1569; }
public SubscriptionInfo(ISubscriptionMessage subscription) { Subscription = subscription ?? throw new ArgumentNullException(nameof(subscription)); Subscribers = new CachedSynchronizedSet <long>(); }
/// <summary> /// Initializes a new instance of the <see cref="SecurityPicker"/>. /// </summary> public SecurityPicker() { InitializeComponent(); _counterMask = Counter.Text; GuiDispatcher.GlobalDispatcher.AddPeriodicalAction(() => { if (!_isDirty) return; _isDirty = false; FilterSecurities(); }); GuiDispatcher.GlobalDispatcher.AddPeriodicalAction(() => { if (!_isCounterDirty) return; _isCounterDirty = false; UpdateCounter(); }); _excludeSecurities = new CachedSynchronizedSet<Security>(); _excludeSecurities.AddedRange += s => SecurityProviderOnSecuritiesChanged(true, NotifyCollectionChangedAction.Add, s); _excludeSecurities.RemovedRange += s => SecurityProviderOnSecuritiesChanged(true, NotifyCollectionChangedAction.Remove, s); _excludeSecurities.Cleared += () => SecurityProviderOnSecuritiesChanged(true, NotifyCollectionChangedAction.Reset, null); SecurityProvider = null; SecuritiesCtrl.SelectionMode = _defaultSelectionMode; UpdateCounter(); SecurityTypeCtrl.NullItem.Description = LocalizedStrings.Str1569; }