diff --git a/CryptoExchange.Net/OrderBook/SymbolOrderBook.cs b/CryptoExchange.Net/OrderBook/SymbolOrderBook.cs index 8ef7ccb..9b62eb2 100644 --- a/CryptoExchange.Net/OrderBook/SymbolOrderBook.cs +++ b/CryptoExchange.Net/OrderBook/SymbolOrderBook.cs @@ -643,19 +643,20 @@ namespace CryptoExchange.Net.OrderBook /// /// Wait until an update has been buffered /// - /// Max wait time + /// Min wait time + /// Max wait time /// Cancellation token /// - protected async Task> WaitUntilFirstUpdateBufferedAsync(TimeSpan timeout, CancellationToken ct) + protected async Task WaitUntilFirstUpdateBufferedAsync(TimeSpan? minWait, TimeSpan maxWait, CancellationToken ct) { var startWait = DateTime.UtcNow; while (_processBuffer.Count == 0) { if (ct.IsCancellationRequested) - return new CallResult(new CancellationRequestedError()); + return new CallResult(new CancellationRequestedError()); - if (DateTime.UtcNow - startWait > timeout) - return new CallResult(new ServerError(new ErrorInfo(ErrorType.OrderBookTimeout, "Timeout while waiting for data"))); + if (DateTime.UtcNow - startWait > maxWait) + return new CallResult(new ServerError(new ErrorInfo(ErrorType.OrderBookTimeout, "Timeout while waiting for data"))); try { @@ -665,7 +666,14 @@ namespace CryptoExchange.Net.OrderBook { } } - return new CallResult(true); + if (minWait != null) + { + var dif = DateTime.UtcNow - startWait; + if (dif < minWait) + await Task.Delay(minWait.Value - dif).ConfigureAwait(false); + } + + return CallResult.SuccessResult; } ///