Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PolygonDataQueueHandler"/> class
        /// </summary>
        public PolygonDataQueueHandler(bool streamingEnabled)
        {
            if (streamingEnabled)
            {
                foreach (var securityType in new[] { SecurityType.Equity, SecurityType.Forex, SecurityType.Crypto })
                {
                    var client = new PolygonWebSocketClientWrapper(_apiKey, _symbolMapper, securityType, OnMessage);
                    _webSocketClientWrappers.Add(securityType, client);
                }
            }

            var subscriber = new EventBasedDataQueueHandlerSubscriptionManager(t => t.ToString());

            subscriber.SubscribeImpl   += Subscribe;
            subscriber.UnsubscribeImpl += Unsubscribe;

            _subscriptionManager = subscriber;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FuncDataQueueHandler"/> class
        /// </summary>
        /// <param name="getNextTicksFunction">The functional implementation to get ticks function</param>
        /// <param name="timeProvider">The time provider to use</param>
        public FuncDataQueueHandler(Func <FuncDataQueueHandler, IEnumerable <BaseData> > getNextTicksFunction, ITimeProvider timeProvider)
        {
            _subscriptions           = new HashSet <SubscriptionDataConfig>();
            _cancellationTokenSource = new CancellationTokenSource();
            _aggregationManager      = new TestAggregationManager(timeProvider);
            _subscriptionManager     = new FakeDataQueuehandlerSubscriptionManager((t) => "quote-trade");

            Task.Factory.StartNew(() =>
            {
                while (!_cancellationTokenSource.IsCancellationRequested)
                {
                    var emitted = false;
                    try
                    {
                        foreach (var baseData in getNextTicksFunction(this))
                        {
                            if (_cancellationTokenSource.IsCancellationRequested)
                            {
                                break;
                            }
                            emitted = true;
                            _aggregationManager.Update(baseData);
                        }
                    }
                    catch (Exception exception)
                    {
                        if (exception is ObjectDisposedException)
                        {
                            return;
                        }
                        Log.Error(exception);
                    }

                    if (!emitted)
                    {
                        Thread.Sleep(50);
                    }
                    else
                    {
                        Thread.Sleep(10);
                    }
                }
            }, TaskCreationOptions.LongRunning);
        }
Beispiel #3
0
 public void SetUp()
 {
     _subscriptionManager = new FakeDataQueuehandlerSubscriptionManager((t) => "quote-trade");
 }