Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/ExchangeSharp/API/Exchanges/CryptoCom/ExchangeCryptoComApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected override async Task<IWebSocket> OnGetTradesWebSocketAsync(Func<KeyValu
{
marketSymbols = new string[] { "" };
}
return await ConnectPublicWebSocketAsync("/market", async (_socket, msg) =>
var ws = await ConnectPublicWebSocketAsync("/market", async (_socket, msg) =>
{
/*{
{{
Expand Down Expand Up @@ -74,9 +74,17 @@ protected override async Task<IWebSocket> OnGetTradesWebSocketAsync(Func<KeyValu
throw new APIException(token["code"].ToStringInvariant() + ": " + token["message"].ToStringInvariant());
}
else if (token["method"].ToStringInvariant() == "public/heartbeat")
{
{ /* For websocket connections, the system will send a heartbeat message to the client every 30 seconds.
* The client must respond back with the public/respond-heartbeat method, using the same matching id, within 5 seconds, or the connection will break. */
var hrResponse = new
{
id = token["id"].ConvertInvariant<long>(),
method = "public/respond-heartbeat",
};
await _socket.SendMessageAsync(hrResponse);

if (token["message"].ToStringInvariant() == "server did not receive any client heartbeat, going to disconnect soon")
throw new APIException(token["code"].ToStringInvariant() + ": " + token["message"].ToStringInvariant());
Logger.Warn(token["code"].ToStringInvariant() + ": " + token["message"].ToStringInvariant());
}
else if (token["method"].ToStringInvariant() == "subscribe" && token["result"] != null)
{
Expand Down Expand Up @@ -115,6 +123,7 @@ protected override async Task<IWebSocket> OnGetTradesWebSocketAsync(Func<KeyValu
var subscribeRequest = new
{
// + consider using id field in the future to differentiate between requests
//id = new Random().Next(),
method = "subscribe",
@params = new
{
Expand All @@ -124,6 +133,8 @@ protected override async Task<IWebSocket> OnGetTradesWebSocketAsync(Func<KeyValu
};
await _socket.SendMessageAsync(subscribeRequest);
});
ws.KeepAlive = new TimeSpan(0); // cryptocom throws bad request empty content msgs w/ keepalives
return ws;
}
}
public partial class ExchangeName { public const string CryptoCom = "CryptoCom"; }
Expand Down