From 5c402c4799509fa1fead624e9e96080808efbdd7 Mon Sep 17 00:00:00 2001 From: Zac Charles Date: Sun, 29 Apr 2018 02:43:41 +0100 Subject: [PATCH] [Bug] Create new IWebSocketFeed when reconnecting (#117) --- GDAXSharp/GDAXClient.cs | 5 +++-- GDAXSharp/WebSocket/WebSocket.cs | 9 ++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/GDAXSharp/GDAXClient.cs b/GDAXSharp/GDAXClient.cs index c114fc2c..2f063708 100644 --- a/GDAXSharp/GDAXClient.cs +++ b/GDAXSharp/GDAXClient.cs @@ -1,4 +1,5 @@ using GDAXSharp.Network.Authentication; +using System; using GDAXSharp.Network.HttpClient; using GDAXSharp.Network.HttpRequest; using GDAXSharp.Services.Accounts; @@ -36,7 +37,7 @@ public GDAXClient( { var clock = new Clock(); var httpRequestMessageService = new HttpRequestMessageService(authenticator, clock, sandBox); - var webSocketFeed = new WebSocketFeed(sandBox); + var createWebSocketFeed = (Func)(() => new WebSocketFeed(sandBox)); var queryBuilder = new QueryBuilder(); AccountsService = new AccountsService(httpClient, httpRequestMessageService); @@ -51,7 +52,7 @@ public GDAXClient( FundingsService = new FundingsService(httpClient, httpRequestMessageService, queryBuilder); ReportsService = new ReportsService(httpClient, httpRequestMessageService); UserAccountService = new UserAccountService(httpClient, httpRequestMessageService); - WebSocket = new WebSocket.WebSocket(webSocketFeed, authenticator, clock); + WebSocket = new WebSocket.WebSocket(createWebSocketFeed, authenticator, clock); } public AccountsService AccountsService { get; } diff --git a/GDAXSharp/WebSocket/WebSocket.cs b/GDAXSharp/WebSocket/WebSocket.cs index c19d1d02..7b563950 100644 --- a/GDAXSharp/WebSocket/WebSocket.cs +++ b/GDAXSharp/WebSocket/WebSocket.cs @@ -18,7 +18,7 @@ namespace GDAXSharp.WebSocket { public class WebSocket { - private readonly IWebSocketFeed webSocketFeed; + private readonly Func createWebSocketFeed; private readonly IAuthenticator authenticator; @@ -30,14 +30,16 @@ public class WebSocket private List channelTypes; + private IWebSocketFeed webSocketFeed; + public WebSocketState State => webSocketFeed.State; public WebSocket( - IWebSocketFeed webSocketFeed, + Func createWebSocketFeed, IAuthenticator authenticator, IClock clock) { - this.webSocketFeed = webSocketFeed; + this.createWebSocketFeed = createWebSocketFeed; this.authenticator = authenticator; this.clock = clock; } @@ -62,6 +64,7 @@ public void Start( productTypes = providedProductTypes; channelTypes = providedChannelTypes; + webSocketFeed = createWebSocketFeed(); webSocketFeed.Closed += WebSocket_Closed; webSocketFeed.Error += WebSocket_Error; webSocketFeed.MessageReceived += WebSocket_MessageReceived;