Skip to content

Commit

Permalink
[Bug] Fix possible null exception when calling websocket stop (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisw000 authored and dougdellolio committed Mar 16, 2019
1 parent b59ffbb commit 2e4ed4f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CoinbasePro/Network/Authentication/Authenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions CoinbasePro/Services/Products/ProductsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,13 @@ public async Task<IList<Candle>> 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;
Expand Down
8 changes: 7 additions & 1 deletion CoinbasePro/WebSocket/WebSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IWebSocketFeed> createWebSocketFeed,
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 2e4ed4f

Please sign in to comment.