Пример #1
0
        public BfOrderBookStream(RealtimeBoardSnapshotSource snapshot, RealtimeBoardSource update)
        {
            _source = Observable.Create <BfOrderBook>(observer =>
            {
                var orderBook  = new BfOrderBook();
                var disposable =
                    snapshot.Select(e => (orders: e, isreset: true))
                    .Merge(
                        update.Select(e => (orders: e, isreset: false))
                        )
                    .Subscribe(e =>
                {
                    if (e.isreset)
                    {
                        orderBook.Reset(e.orders);
                    }
                    else
                    {
                        orderBook.UpdateDelta(e.orders);
                    }

                    observer.OnNext(orderBook);
                });

                return(() => { disposable.Dispose(); });
            });
        }
Пример #2
0
        public IObservable <BfBoard> GetBoardSource(BfProductCode productCode)
        {
            TryOpen();
            var symbol = _availableMarkets[productCode];

            return(_boardSources.GetOrAdd(symbol, _ =>
            {
                var source = new RealtimeBoardSource(_webSocket, _jsonSettings, symbol);
                _webSocketSources[source.Channel] = source;
                return source.Publish().RefCount();
            }));
        }
Пример #3
0
        public IObservable <BfOrderBook> GetOrderBookSource(BfProductCode productCode)
        {
            TryOpen();
            var symbol = _availableMarkets[productCode];

            return(_orderBookSnapshotSources.GetOrAdd(symbol, _ =>
            {
                var snapshot = new RealtimeBoardSnapshotSource(_webSocket, _jsonSettings, symbol);
                var update = new RealtimeBoardSource(_webSocket, _jsonSettings, symbol);
                _webSocketSources[snapshot.Channel] = snapshot;
                _webSocketSources[update.Channel] = update;
                var source = new BfOrderBookStream(snapshot, update);
                return source.Publish().RefCount();
            }));
        }