예제 #1
0
        protected override void DoWork(double pollinterval)
        {
            ConcurrentDictionary <string, bool> bag;

            if (!PollIntervals.TryGetValue(pollinterval, out bag))
            {
                return;
            }

            BetfairServerResponse <List <MarketBook> > book;

            try
            {
                book = _client.ListMarketBook(bag.Keys, _priceProjection, _orderProjection, _matchProjection).Result;
            }
            catch (AggregateException ex)
            {
                foreach (var e in ex.Flatten().InnerExceptions)
                {
                    _logger.Invoke(e, $"pollInterval {pollinterval}");
                }

                return;
            }

            if (book.HasError)
            {
                foreach (var observer in Observers.Where(k => bag.Keys.Contains(k.Key)))
                {
                    observer.Value.OnError(book.Error);
                }
                return;
            }

            // we may have fresher data than the response to this pollinterval request
            Poller p;

            if (!Pollers.TryGetValue(pollinterval, out p))
            {
                return;
            }

            if (book.RequestStart < p.LatestDataRequestStart && book.LastByte > p.LatestDataRequestFinish)
            {
                return;
            }

            lock (LockObj)
            {
                p.LatestDataRequestStart  = book.RequestStart;
                p.LatestDataRequestFinish = book.LastByte;
            }

            UpdateObservers(book.Response);
        }
        protected sealed override void DoWork(double pollinterval)
        {
            ConcurrentDictionary <string, bool> mpi;

            if (!PollIntervals.TryGetValue(pollinterval, out mpi))
            {
                return;
            }

            UpdateObservers(_listMarketBook(mpi.Keys));
        }