From 2e4ed4fe8d02a181f215b4c9705a6493043943f5 Mon Sep 17 00:00:00 2001 From: chrisw000 <18504164+chrisw000@users.noreply.github.com> Date: Sat, 16 Mar 2019 00:04:48 +0000 Subject: [PATCH] [Bug] Fix possible null exception when calling websocket stop (#191) --- CoinbasePro/Network/Authentication/Authenticator.cs | 7 +++++++ CoinbasePro/Services/Products/ProductsService.cs | 5 +++++ CoinbasePro/WebSocket/WebSocket.cs | 8 +++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CoinbasePro/Network/Authentication/Authenticator.cs b/CoinbasePro/Network/Authentication/Authenticator.cs index 11321175..a9453ad8 100644 --- a/CoinbasePro/Network/Authentication/Authenticator.cs +++ b/CoinbasePro/Network/Authentication/Authenticator.cs @@ -13,6 +13,13 @@ public Authenticator( string unsignedSignature, string passphrase) { + if (string.IsNullOrEmpty(apiKey) || string.IsNullOrEmpty(unsignedSignature) || + string.IsNullOrEmpty(passphrase)) + { + throw new ArgumentException( + $"{nameof(Authenticator)} requires parameters {nameof(apiKey)}, {nameof(unsignedSignature)} and {nameof(passphrase)} to be populated."); + } + ApiKey = apiKey; UnsignedSignature = unsignedSignature; Passphrase = passphrase; diff --git a/CoinbasePro/Services/Products/ProductsService.cs b/CoinbasePro/Services/Products/ProductsService.cs index dc7ee85f..089b0edc 100644 --- a/CoinbasePro/Services/Products/ProductsService.cs +++ b/CoinbasePro/Services/Products/ProductsService.cs @@ -89,8 +89,13 @@ public async Task> GetHistoricRatesAsync( candleList.AddRange(await GetHistoricRatesAsync(productPair, batchStart, batchEnd.Value, (int)granularity)); + var previousBatchEnd = batchEnd; batchEnd = candleList.LastOrDefault()?.Time; + if (previousBatchEnd == batchEnd) { + break; + } + } while (batchStart > start); return candleList; diff --git a/CoinbasePro/WebSocket/WebSocket.cs b/CoinbasePro/WebSocket/WebSocket.cs index 21384bba..b8d6eef4 100644 --- a/CoinbasePro/WebSocket/WebSocket.cs +++ b/CoinbasePro/WebSocket/WebSocket.cs @@ -36,7 +36,7 @@ public class WebSocket : IWebSocket private IWebSocketFeed webSocketFeed; - public WebSocketState State => webSocketFeed.State; + public WebSocketState State => webSocketFeed?.State ?? WebSocketState.None; public WebSocket( Func createWebSocketFeed, @@ -92,6 +92,12 @@ public void Start( public void Stop() { + if (webSocketFeed == null) + { + Log.Warning("Websocket did not attempt to stop as the feed has not been started yet"); + return; + } + if (webSocketFeed.State != WebSocketState.Open) { throw new CoinbaseProWebSocketException(