Skip to content

Commit

Permalink
[Bug] Create new IWebSocketFeed when reconnecting (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
zaccharles authored and dougdellolio committed Apr 29, 2018
1 parent 2f98ee0 commit 5c402c4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 3 additions & 2 deletions GDAXSharp/GDAXClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using GDAXSharp.Network.Authentication;
using System;
using GDAXSharp.Network.HttpClient;
using GDAXSharp.Network.HttpRequest;
using GDAXSharp.Services.Accounts;
Expand Down Expand Up @@ -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<IWebSocketFeed>)(() => new WebSocketFeed(sandBox));
var queryBuilder = new QueryBuilder();

AccountsService = new AccountsService(httpClient, httpRequestMessageService);
Expand All @@ -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; }
Expand Down
9 changes: 6 additions & 3 deletions GDAXSharp/WebSocket/WebSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace GDAXSharp.WebSocket
{
public class WebSocket
{
private readonly IWebSocketFeed webSocketFeed;
private readonly Func<IWebSocketFeed> createWebSocketFeed;

private readonly IAuthenticator authenticator;

Expand All @@ -30,14 +30,16 @@ public class WebSocket

private List<ChannelType> channelTypes;

private IWebSocketFeed webSocketFeed;

public WebSocketState State => webSocketFeed.State;

public WebSocket(
IWebSocketFeed webSocketFeed,
Func<IWebSocketFeed> createWebSocketFeed,
IAuthenticator authenticator,
IClock clock)
{
this.webSocketFeed = webSocketFeed;
this.createWebSocketFeed = createWebSocketFeed;
this.authenticator = authenticator;
this.clock = clock;
}
Expand All @@ -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;
Expand Down

0 comments on commit 5c402c4

Please sign in to comment.