/// <inheritdoc />
        protected override async Task <CallResult <UpdateSubscription> > DoStartAsync()
        {
            CallResult <UpdateSubscription> subResult;

            if (Levels == null)
            {
                subResult = await _socketClient.Spot.SubscribeToOrderBookUpdatesAsync(Symbol, _updateInterval, HandleUpdate).ConfigureAwait(false);
            }
            else
            {
                subResult = await _socketClient.Spot.SubscribeToPartialOrderBookUpdatesAsync(Symbol, Levels.Value, _updateInterval, HandleUpdate).ConfigureAwait(false);
            }

            if (!subResult)
            {
                return(new CallResult <UpdateSubscription>(null, subResult.Error));
            }

            Status = OrderBookStatus.Syncing;
            if (Levels == null)
            {
                // Small delay to make sure the snapshot is from after our first stream update
                await Task.Delay(200).ConfigureAwait(false);

                var bookResult = await _restClient.Spot.Market.GetOrderBookAsync(Symbol, Levels ?? 5000).ConfigureAwait(false);

                if (!bookResult)
                {
                    log.Write(Microsoft.Extensions.Logging.LogLevel.Debug, $"{Id} order book {Symbol} failed to retrieve initial order book");
                    await _socketClient.UnsubscribeAsync(subResult.Data).ConfigureAwait(false);

                    return(new CallResult <UpdateSubscription>(null, bookResult.Error));
                }

                SetInitialOrderBook(bookResult.Data.LastUpdateId, bookResult.Data.Bids, bookResult.Data.Asks);
            }
            else
            {
                var setResult = await WaitForSetOrderBookAsync(10000).ConfigureAwait(false);

                return(setResult ? subResult : new CallResult <UpdateSubscription>(null, setResult.Error));
            }

            return(new CallResult <UpdateSubscription>(subResult.Data, null));
        }
Пример #2
0
 public async Task Unsubscribe(UpdateSubscription subscription)
 {
     await _socketClient.UnsubscribeAsync(subscription);
 }
Пример #3
0
 public async Task Stop()
 {
     await _socketClient.UnsubscribeAsync(_subscription);
 }