mirror of
https://github.com/JKorf/CryptoExchange.Net.git
synced 2026-08-12 17:03:10 +00:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 277be7ab9b | |||
| 45f3459f59 | |||
| 98dad4a8ed | |||
| 1e5f19271b | |||
| 8abeeb4cf0 | |||
| cae0cd9ead | |||
| 811574ae01 | |||
| 0ddecf7f8d | |||
| 5bcf50fb4d | |||
| 9f0654815d | |||
| 465e9f04f4 |
@@ -13,11 +13,15 @@ namespace CryptoExchange.Net.UnitTests.TestImplementations
|
|||||||
public bool Connected { get; set; }
|
public bool Connected { get; set; }
|
||||||
|
|
||||||
public event Action OnClose;
|
public event Action OnClose;
|
||||||
|
|
||||||
|
#pragma warning disable 0067
|
||||||
public event Action OnReconnected;
|
public event Action OnReconnected;
|
||||||
public event Action OnReconnecting;
|
public event Action OnReconnecting;
|
||||||
|
#pragma warning restore 0067
|
||||||
public event Action<string> OnMessage;
|
public event Action<string> OnMessage;
|
||||||
public event Action<Exception> OnError;
|
public event Action<Exception> OnError;
|
||||||
public event Action OnOpen;
|
public event Action OnOpen;
|
||||||
|
public Func<Task<Uri>> GetReconnectionUrl { get; set; }
|
||||||
|
|
||||||
public int Id { get; }
|
public int Id { get; }
|
||||||
public bool ShouldReconnect { get; set; }
|
public bool ShouldReconnect { get; set; }
|
||||||
|
|||||||
@@ -543,6 +543,17 @@ namespace CryptoExchange.Net
|
|||||||
return Task.FromResult(new CallResult<string?>(address));
|
return Task.FromResult(new CallResult<string?>(address));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the url to reconnect to after losing a connection
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="apiClient"></param>
|
||||||
|
/// <param name="connection"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual Task<Uri?> GetReconnectUriAsync(SocketApiClient apiClient, SocketConnection connection)
|
||||||
|
{
|
||||||
|
return Task.FromResult<Uri?>(connection.ConnectionUri);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a connection for a new subscription or query. Can be an existing if there are open position or a new one.
|
/// Gets a connection for a new subscription or query. Can be an existing if there are open position or a new one.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ namespace CryptoExchange.Net.Converters
|
|||||||
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
|
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
|
||||||
{
|
{
|
||||||
var stringValue = GetString(value);
|
var stringValue = GetString(value);
|
||||||
writer.WriteRawValue(stringValue);
|
writer.WriteValue(stringValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,16 +6,16 @@
|
|||||||
<PackageId>CryptoExchange.Net</PackageId>
|
<PackageId>CryptoExchange.Net</PackageId>
|
||||||
<Authors>JKorf</Authors>
|
<Authors>JKorf</Authors>
|
||||||
<Description>A base package for implementing cryptocurrency API's</Description>
|
<Description>A base package for implementing cryptocurrency API's</Description>
|
||||||
<PackageVersion>5.2.1</PackageVersion>
|
<PackageVersion>5.2.4</PackageVersion>
|
||||||
<AssemblyVersion>5.2.1</AssemblyVersion>
|
<AssemblyVersion>5.2.4</AssemblyVersion>
|
||||||
<FileVersion>5.2.1</FileVersion>
|
<FileVersion>5.2.4</FileVersion>
|
||||||
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
|
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
|
||||||
<RepositoryType>git</RepositoryType>
|
<RepositoryType>git</RepositoryType>
|
||||||
<RepositoryUrl>https://github.com/JKorf/CryptoExchange.Net.git</RepositoryUrl>
|
<RepositoryUrl>https://github.com/JKorf/CryptoExchange.Net.git</RepositoryUrl>
|
||||||
<PackageProjectUrl>https://github.com/JKorf/CryptoExchange.Net</PackageProjectUrl>
|
<PackageProjectUrl>https://github.com/JKorf/CryptoExchange.Net</PackageProjectUrl>
|
||||||
<NeutralLanguage>en</NeutralLanguage>
|
<NeutralLanguage>en</NeutralLanguage>
|
||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
<PackageReleaseNotes>5.2.1 - Fixed socket reconnect issue, Fixed `message not handled` messages after unsubscribing, Fixed error returning for non-json error responses</PackageReleaseNotes>
|
<PackageReleaseNotes>5.2.4 - Added handling of PlatformNotSupportedException when trying to use websocket from WebAssembly, Changed DataEvent to have a public constructor for testing purposes, Fixed EnumConverter serializing values without proper quotes, Fixed websocket connection reconnecting too quickly when resubscribing/reauthenticating fails</PackageReleaseNotes>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<LangVersion>9.0</LangVersion>
|
<LangVersion>9.0</LangVersion>
|
||||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using CryptoExchange.Net.Objects;
|
using CryptoExchange.Net.Objects;
|
||||||
|
using CryptoExchange.Net.Sockets;
|
||||||
using System;
|
using System;
|
||||||
using System.Security.Authentication;
|
using System.Security.Authentication;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -35,6 +36,10 @@ namespace CryptoExchange.Net.Interfaces
|
|||||||
/// Websocket has reconnected to the server
|
/// Websocket has reconnected to the server
|
||||||
/// </summary>
|
/// </summary>
|
||||||
event Action OnReconnected;
|
event Action OnReconnected;
|
||||||
|
/// <summary>
|
||||||
|
/// Get reconntion url
|
||||||
|
/// </summary>
|
||||||
|
Func<Task<Uri?>> GetReconnectionUrl { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Unique id for this socket
|
/// Unique id for this socket
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.WebSockets;
|
using System.Net.WebSockets;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@@ -33,7 +34,6 @@ namespace CryptoExchange.Net.Sockets
|
|||||||
private readonly AsyncResetEvent _sendEvent;
|
private readonly AsyncResetEvent _sendEvent;
|
||||||
private readonly ConcurrentQueue<byte[]> _sendBuffer;
|
private readonly ConcurrentQueue<byte[]> _sendBuffer;
|
||||||
private readonly SemaphoreSlim _closeSem;
|
private readonly SemaphoreSlim _closeSem;
|
||||||
private readonly WebSocketParameters _parameters;
|
|
||||||
private readonly List<DateTime> _outgoingMessages;
|
private readonly List<DateTime> _outgoingMessages;
|
||||||
|
|
||||||
private ClientWebSocket _socket;
|
private ClientWebSocket _socket;
|
||||||
@@ -44,6 +44,7 @@ namespace CryptoExchange.Net.Sockets
|
|||||||
private bool _stopRequested;
|
private bool _stopRequested;
|
||||||
private bool _disposed;
|
private bool _disposed;
|
||||||
private ProcessState _processState;
|
private ProcessState _processState;
|
||||||
|
private DateTime _lastReconnectTime;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -64,13 +65,16 @@ namespace CryptoExchange.Net.Sockets
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public int Id { get; }
|
public int Id { get; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public WebSocketParameters Parameters { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The timestamp this socket has been active for the last time
|
/// The timestamp this socket has been active for the last time
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTime LastActionTime { get; private set; }
|
public DateTime LastActionTime { get; private set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public Uri Uri => _parameters.Uri;
|
public Uri Uri => Parameters.Uri;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool IsClosed => _socket.State == WebSocketState.Closed;
|
public bool IsClosed => _socket.State == WebSocketState.Closed;
|
||||||
@@ -107,6 +111,8 @@ namespace CryptoExchange.Net.Sockets
|
|||||||
public event Action? OnReconnecting;
|
public event Action? OnReconnecting;
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public event Action? OnReconnected;
|
public event Action? OnReconnected;
|
||||||
|
/// <inheritdoc />
|
||||||
|
public Func<Task<Uri?>>? GetReconnectionUrl { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ctor
|
/// ctor
|
||||||
@@ -118,7 +124,7 @@ namespace CryptoExchange.Net.Sockets
|
|||||||
Id = NextStreamId();
|
Id = NextStreamId();
|
||||||
_log = log;
|
_log = log;
|
||||||
|
|
||||||
_parameters = websocketParameters;
|
Parameters = websocketParameters;
|
||||||
_outgoingMessages = new List<DateTime>();
|
_outgoingMessages = new List<DateTime>();
|
||||||
_receivedMessages = new List<ReceiveItem>();
|
_receivedMessages = new List<ReceiveItem>();
|
||||||
_sendEvent = new AsyncResetEvent();
|
_sendEvent = new AsyncResetEvent();
|
||||||
@@ -147,17 +153,26 @@ namespace CryptoExchange.Net.Sockets
|
|||||||
private ClientWebSocket CreateSocket()
|
private ClientWebSocket CreateSocket()
|
||||||
{
|
{
|
||||||
var cookieContainer = new CookieContainer();
|
var cookieContainer = new CookieContainer();
|
||||||
foreach (var cookie in _parameters.Cookies)
|
foreach (var cookie in Parameters.Cookies)
|
||||||
cookieContainer.Add(new Cookie(cookie.Key, cookie.Value));
|
cookieContainer.Add(new Cookie(cookie.Key, cookie.Value));
|
||||||
|
|
||||||
var socket = new ClientWebSocket();
|
var socket = new ClientWebSocket();
|
||||||
socket.Options.Cookies = cookieContainer;
|
try
|
||||||
foreach (var header in _parameters.Headers)
|
{
|
||||||
socket.Options.SetRequestHeader(header.Key, header.Value);
|
socket.Options.Cookies = cookieContainer;
|
||||||
socket.Options.KeepAliveInterval = _parameters.KeepAliveInterval ?? TimeSpan.Zero;
|
foreach (var header in Parameters.Headers)
|
||||||
socket.Options.SetBuffer(65536, 65536); // Setting it to anything bigger than 65536 throws an exception in .net framework
|
socket.Options.SetRequestHeader(header.Key, header.Value);
|
||||||
if (_parameters.Proxy != null)
|
socket.Options.KeepAliveInterval = Parameters.KeepAliveInterval ?? TimeSpan.Zero;
|
||||||
SetProxy(_parameters.Proxy);
|
socket.Options.SetBuffer(65536, 65536); // Setting it to anything bigger than 65536 throws an exception in .net framework
|
||||||
|
if (Parameters.Proxy != null)
|
||||||
|
SetProxy(Parameters.Proxy);
|
||||||
|
}
|
||||||
|
catch (PlatformNotSupportedException)
|
||||||
|
{
|
||||||
|
// Options are not supported on certain platforms (WebAssembly for instance)
|
||||||
|
// best we can do it try to connect without setting options.
|
||||||
|
}
|
||||||
|
|
||||||
return socket;
|
return socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,7 +203,7 @@ namespace CryptoExchange.Net.Sockets
|
|||||||
_processState = ProcessState.Processing;
|
_processState = ProcessState.Processing;
|
||||||
var sendTask = SendLoopAsync();
|
var sendTask = SendLoopAsync();
|
||||||
var receiveTask = ReceiveLoopAsync();
|
var receiveTask = ReceiveLoopAsync();
|
||||||
var timeoutTask = _parameters.Timeout != null && _parameters.Timeout > TimeSpan.FromSeconds(0) ? CheckTimeoutAsync() : Task.CompletedTask;
|
var timeoutTask = Parameters.Timeout != null && Parameters.Timeout > TimeSpan.FromSeconds(0) ? CheckTimeoutAsync() : Task.CompletedTask;
|
||||||
await Task.WhenAll(sendTask, receiveTask, timeoutTask).ConfigureAwait(false);
|
await Task.WhenAll(sendTask, receiveTask, timeoutTask).ConfigureAwait(false);
|
||||||
_log.Write(LogLevel.Debug, $"Socket {Id} processing tasks finished");
|
_log.Write(LogLevel.Debug, $"Socket {Id} processing tasks finished");
|
||||||
|
|
||||||
@@ -199,7 +214,7 @@ namespace CryptoExchange.Net.Sockets
|
|||||||
await _closeTask.ConfigureAwait(false);
|
await _closeTask.ConfigureAwait(false);
|
||||||
_closeTask = null;
|
_closeTask = null;
|
||||||
|
|
||||||
if (!_parameters.AutoReconnect)
|
if (!Parameters.AutoReconnect)
|
||||||
{
|
{
|
||||||
_processState = ProcessState.Idle;
|
_processState = ProcessState.Idle;
|
||||||
OnClose?.Invoke();
|
OnClose?.Invoke();
|
||||||
@@ -209,12 +224,27 @@ namespace CryptoExchange.Net.Sockets
|
|||||||
if (!_stopRequested)
|
if (!_stopRequested)
|
||||||
{
|
{
|
||||||
_processState = ProcessState.Reconnecting;
|
_processState = ProcessState.Reconnecting;
|
||||||
OnReconnecting?.Invoke();
|
OnReconnecting?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var sinceLastReconnect = DateTime.UtcNow - _lastReconnectTime;
|
||||||
|
if (sinceLastReconnect < Parameters.ReconnectInterval)
|
||||||
|
await Task.Delay(Parameters.ReconnectInterval - sinceLastReconnect).ConfigureAwait(false);
|
||||||
|
|
||||||
while (!_stopRequested)
|
while (!_stopRequested)
|
||||||
{
|
{
|
||||||
_log.Write(LogLevel.Debug, $"Socket {Id} attempting to reconnect");
|
_log.Write(LogLevel.Debug, $"Socket {Id} attempting to reconnect");
|
||||||
|
var task = GetReconnectionUrl?.Invoke();
|
||||||
|
if (task != null)
|
||||||
|
{
|
||||||
|
var reconnectUri = await task.ConfigureAwait(false);
|
||||||
|
if (reconnectUri != null && Parameters.Uri != reconnectUri)
|
||||||
|
{
|
||||||
|
_log.Write(LogLevel.Debug, $"Socket {Id} reconnect URI set to {reconnectUri}");
|
||||||
|
Parameters.Uri = reconnectUri;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_socket = CreateSocket();
|
_socket = CreateSocket();
|
||||||
_ctsSource.Dispose();
|
_ctsSource.Dispose();
|
||||||
_ctsSource = new CancellationTokenSource();
|
_ctsSource = new CancellationTokenSource();
|
||||||
@@ -223,10 +253,11 @@ namespace CryptoExchange.Net.Sockets
|
|||||||
var connected = await ConnectInternalAsync().ConfigureAwait(false);
|
var connected = await ConnectInternalAsync().ConfigureAwait(false);
|
||||||
if (!connected)
|
if (!connected)
|
||||||
{
|
{
|
||||||
await Task.Delay(_parameters.ReconnectInterval).ConfigureAwait(false);
|
await Task.Delay(Parameters.ReconnectInterval).ConfigureAwait(false);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_lastReconnectTime = DateTime.UtcNow;
|
||||||
OnReconnected?.Invoke();
|
OnReconnected?.Invoke();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -241,7 +272,7 @@ namespace CryptoExchange.Net.Sockets
|
|||||||
if (_ctsSource.IsCancellationRequested)
|
if (_ctsSource.IsCancellationRequested)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var bytes = _parameters.Encoding.GetBytes(data);
|
var bytes = Parameters.Encoding.GetBytes(data);
|
||||||
_log.Write(LogLevel.Trace, $"Socket {Id} Adding {bytes.Length} to sent buffer");
|
_log.Write(LogLevel.Trace, $"Socket {Id} Adding {bytes.Length} to sent buffer");
|
||||||
_sendBuffer.Enqueue(bytes);
|
_sendBuffer.Enqueue(bytes);
|
||||||
_sendEvent.Set();
|
_sendEvent.Set();
|
||||||
@@ -370,11 +401,11 @@ namespace CryptoExchange.Net.Sockets
|
|||||||
|
|
||||||
while (_sendBuffer.TryDequeue(out var data))
|
while (_sendBuffer.TryDequeue(out var data))
|
||||||
{
|
{
|
||||||
if (_parameters.RatelimitPerSecond != null)
|
if (Parameters.RatelimitPerSecond != null)
|
||||||
{
|
{
|
||||||
// Wait for rate limit
|
// Wait for rate limit
|
||||||
DateTime? start = null;
|
DateTime? start = null;
|
||||||
while (MessagesSentLastSecond() >= _parameters.RatelimitPerSecond)
|
while (MessagesSentLastSecond() >= Parameters.RatelimitPerSecond)
|
||||||
{
|
{
|
||||||
start ??= DateTime.UtcNow;
|
start ??= DateTime.UtcNow;
|
||||||
await Task.Delay(50).ConfigureAwait(false);
|
await Task.Delay(50).ConfigureAwait(false);
|
||||||
@@ -549,14 +580,14 @@ namespace CryptoExchange.Net.Sockets
|
|||||||
string strData;
|
string strData;
|
||||||
if (messageType == WebSocketMessageType.Binary)
|
if (messageType == WebSocketMessageType.Binary)
|
||||||
{
|
{
|
||||||
if (_parameters.DataInterpreterBytes == null)
|
if (Parameters.DataInterpreterBytes == null)
|
||||||
throw new Exception("Byte interpreter not set while receiving byte data");
|
throw new Exception("Byte interpreter not set while receiving byte data");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var relevantData = new byte[count];
|
var relevantData = new byte[count];
|
||||||
Array.Copy(data, offset, relevantData, 0, count);
|
Array.Copy(data, offset, relevantData, 0, count);
|
||||||
strData = _parameters.DataInterpreterBytes(relevantData);
|
strData = Parameters.DataInterpreterBytes(relevantData);
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
@@ -565,13 +596,13 @@ namespace CryptoExchange.Net.Sockets
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
strData = _parameters.Encoding.GetString(data, offset, count);
|
strData = Parameters.Encoding.GetString(data, offset, count);
|
||||||
|
|
||||||
if (_parameters.DataInterpreterString != null)
|
if (Parameters.DataInterpreterString != null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
strData = _parameters.DataInterpreterString(strData);
|
strData = Parameters.DataInterpreterString(strData);
|
||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
@@ -633,7 +664,7 @@ namespace CryptoExchange.Net.Sockets
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
protected async Task CheckTimeoutAsync()
|
protected async Task CheckTimeoutAsync()
|
||||||
{
|
{
|
||||||
_log.Write(LogLevel.Debug, $"Socket {Id} Starting task checking for no data received for {_parameters.Timeout}");
|
_log.Write(LogLevel.Debug, $"Socket {Id} Starting task checking for no data received for {Parameters.Timeout}");
|
||||||
LastActionTime = DateTime.UtcNow;
|
LastActionTime = DateTime.UtcNow;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -642,10 +673,10 @@ namespace CryptoExchange.Net.Sockets
|
|||||||
if (_ctsSource.IsCancellationRequested)
|
if (_ctsSource.IsCancellationRequested)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (DateTime.UtcNow - LastActionTime > _parameters.Timeout)
|
if (DateTime.UtcNow - LastActionTime > Parameters.Timeout)
|
||||||
{
|
{
|
||||||
_log.Write(LogLevel.Warning, $"Socket {Id} No data received for {_parameters.Timeout}, reconnecting socket");
|
_log.Write(LogLevel.Warning, $"Socket {Id} No data received for {Parameters.Timeout}, reconnecting socket");
|
||||||
_ = CloseAsync().ConfigureAwait(false);
|
_ = ReconnectAsync().ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -25,7 +25,12 @@ namespace CryptoExchange.Net.Sockets
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public T Data { get; set; }
|
public T Data { get; set; }
|
||||||
|
|
||||||
internal DataEvent(T data, DateTime timestamp)
|
/// <summary>
|
||||||
|
/// Ctor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data"></param>
|
||||||
|
/// <param name="timestamp"></param>
|
||||||
|
public DataEvent(T data, DateTime timestamp)
|
||||||
{
|
{
|
||||||
Data = data;
|
Data = data;
|
||||||
Timestamp = timestamp;
|
Timestamp = timestamp;
|
||||||
|
|||||||
@@ -184,6 +184,7 @@ namespace CryptoExchange.Net.Sockets
|
|||||||
_socket.OnReconnecting += HandleReconnecting;
|
_socket.OnReconnecting += HandleReconnecting;
|
||||||
_socket.OnReconnected += HandleReconnected;
|
_socket.OnReconnected += HandleReconnected;
|
||||||
_socket.OnError += HandleError;
|
_socket.OnError += HandleError;
|
||||||
|
_socket.GetReconnectionUrl = GetReconnectionUrlAsync;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -223,7 +224,17 @@ namespace CryptoExchange.Net.Sockets
|
|||||||
foreach (var sub in subscriptions)
|
foreach (var sub in subscriptions)
|
||||||
sub.Confirmed = false;
|
sub.Confirmed = false;
|
||||||
}
|
}
|
||||||
Task.Run(() => ConnectionLost?.Invoke());
|
|
||||||
|
_ = Task.Run(() => ConnectionLost?.Invoke());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the url to connect to when reconnecting
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
protected virtual async Task<Uri?> GetReconnectionUrlAsync()
|
||||||
|
{
|
||||||
|
return await socketClient.GetReconnectUriAsync(ApiClient, this).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace CryptoExchange.Net.Sockets
|
namespace CryptoExchange.Net.Sockets
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,16 +8,43 @@ CryptoExchange.Net is a base package which can be used to easily implement crypt
|
|||||||
## Discord
|
## Discord
|
||||||
A Discord server is available [here](https://discord.gg/MSpeEtSY8t). Feel free to join for discussion and/or questions around the CryptoExchange.Net and implementation libraries.
|
A Discord server is available [here](https://discord.gg/MSpeEtSY8t). Feel free to join for discussion and/or questions around the CryptoExchange.Net and implementation libraries.
|
||||||
|
|
||||||
## Donate / Sponsor
|
## Support the project
|
||||||
I develop and maintain this package on my own for free in my spare time. Donations are greatly appreciated. If you prefer to donate any other currency please contact me.
|
I develop and maintain this package on my own for free in my spare time, any support is greatly appreciated.
|
||||||
|
|
||||||
|
### Referral link
|
||||||
|
Use one of the following following referral links to signup to a new exchange to pay a small percentage of the trading fees you pay to support the project instead of paying them straight to the exchange. This doesn't cost you a thing!
|
||||||
|
[Binance](https://accounts.binance.com/en/register?ref=10153680)
|
||||||
|
[Bitfinex](https://www.bitfinex.com/sign-up?refcode=kCCe-CNBO)
|
||||||
|
[Bittrex](https://bittrex.com/discover/join?referralCode=TST-DJM-CSX)
|
||||||
|
[Bybit](https://partner.bybit.com/b/jkorf)
|
||||||
|
[CoinEx](https://www.coinex.com/register?refer_code=hd6gn)
|
||||||
|
[FTX](https://ftx.com/referrals#a=31620192)
|
||||||
|
[Huobi](https://www.huobi.com/en-us/v/register/double-invite/?inviter_id=11343840&invite_code=fxp93)
|
||||||
|
[Kucoin](https://www.kucoin.com/ucenter/signup?rcode=RguMux)
|
||||||
|
|
||||||
|
### Donate
|
||||||
|
Make a one time donation in a crypto currency of your choice. If you prefer to donate a currency not listed here please contact me.
|
||||||
|
|
||||||
**Btc**: 12KwZk3r2Y3JZ2uMULcjqqBvXmpDwjhhQS
|
**Btc**: 12KwZk3r2Y3JZ2uMULcjqqBvXmpDwjhhQS
|
||||||
**Eth**: 0x069176ca1a4b1d6e0b7901a6bc0dbf3bb0bf5cc2
|
**Eth**: 0x069176ca1a4b1d6e0b7901a6bc0dbf3bb0bf5cc2
|
||||||
**Nano**: xrb_1ocs3hbp561ef76eoctjwg85w5ugr8wgimkj8mfhoyqbx4s1pbc74zggw7gs
|
**Nano**: xrb_1ocs3hbp561ef76eoctjwg85w5ugr8wgimkj8mfhoyqbx4s1pbc74zggw7gs
|
||||||
|
|
||||||
Alternatively, sponsor me on Github using [Github Sponsors](https://github.com/sponsors/JKorf)
|
### Sponsor
|
||||||
|
Alternatively, sponsor me on Github using [Github Sponsors](https://github.com/sponsors/JKorf).
|
||||||
|
|
||||||
## Release notes
|
## Release notes
|
||||||
|
* Version 5.2.4 - 31 Jul 2022
|
||||||
|
* Added handling of PlatformNotSupportedException when trying to use websocket from WebAssembly
|
||||||
|
* Changed DataEvent to have a public constructor for testing purposes
|
||||||
|
* Fixed EnumConverter serializing values without proper quotes
|
||||||
|
* Fixed websocket connection reconnecting too quickly when resubscribing/reauthenticating fails
|
||||||
|
|
||||||
|
* Version 5.2.3 - 19 Jul 2022
|
||||||
|
* Fixed socket getting disconnected when `no data` timeout is reached instead of being reconnected
|
||||||
|
|
||||||
|
* Version 5.2.2 - 17 Jul 2022
|
||||||
|
* Added support for retrieving a new url when socket connection is lost and reconnection will happen
|
||||||
|
|
||||||
* Version 5.2.1 - 16 Jul 2022
|
* Version 5.2.1 - 16 Jul 2022
|
||||||
* Fixed socket reconnect issue
|
* Fixed socket reconnect issue
|
||||||
* Fixed `message not handled` messages after unsubscribing
|
* Fixed `message not handled` messages after unsubscribing
|
||||||
|
|||||||
+1
-1
@@ -105,7 +105,7 @@ All updates are wrapped in a `DataEvent<>` object, which contain a `Timestamp`,
|
|||||||
*[WARNING] Do not use `using` statements in combination with constructing a `SocketClient`. Doing so will dispose the `SocketClient` instance when the subscription is done, which will result in the connection getting closed. Instead assign the socket client to a variable outside of the method scope.*
|
*[WARNING] Do not use `using` statements in combination with constructing a `SocketClient`. Doing so will dispose the `SocketClient` instance when the subscription is done, which will result in the connection getting closed. Instead assign the socket client to a variable outside of the method scope.*
|
||||||
|
|
||||||
### Processing subscribe responses
|
### Processing subscribe responses
|
||||||
Subscribing to a stream will return a `CallResult<UpdateSubscription>` object. This should be checked for success the same was as the [rest client](#processing-request-responses). The `UpdateSubscription` object can be used to listen for connection events of the socket connection.
|
Subscribing to a stream will return a `CallResult<UpdateSubscription>` object. This should be checked for success the same way as the [rest client](#processing-request-responses). The `UpdateSubscription` object can be used to listen for connection events of the socket connection.
|
||||||
```csharp
|
```csharp
|
||||||
|
|
||||||
var subscriptionResult = await kucoinSocketClient.SpotStreams.SubscribeToAllTickerUpdatesAsync(DataHandler);
|
var subscriptionResult = await kucoinSocketClient.SpotStreams.SubscribeToAllTickerUpdatesAsync(DataHandler);
|
||||||
|
|||||||
+18
-3
@@ -42,11 +42,26 @@ These might not be compatible with other libraries, make sure to check the Crypt
|
|||||||
## Discord
|
## Discord
|
||||||
A Discord server is available [here](https://discord.gg/MSpeEtSY8t). Feel free to join for discussion and/or questions around the CryptoExchange.Net and implementation libraries.
|
A Discord server is available [here](https://discord.gg/MSpeEtSY8t). Feel free to join for discussion and/or questions around the CryptoExchange.Net and implementation libraries.
|
||||||
|
|
||||||
## Donate / Sponsor
|
## Support the project
|
||||||
I develop and maintain this package on my own for free in my spare time. Donations are greatly appreciated. If you prefer to donate any other currency please contact me.
|
I develop and maintain this package on my own for free in my spare time, any support is greatly appreciated.
|
||||||
|
|
||||||
|
### Referral link
|
||||||
|
Use one of the following following referral links to signup to a new exchange to pay a small percentage of the trading fees you pay to support the project instead of paying them straight to the exchange. This doesn't cost you a thing!
|
||||||
|
[Binance](https://accounts.binance.com/en/register?ref=10153680)
|
||||||
|
[Bitfinex](https://www.bitfinex.com/sign-up?refcode=kCCe-CNBO)
|
||||||
|
[Bittrex](https://bittrex.com/discover/join?referralCode=TST-DJM-CSX)
|
||||||
|
[Bybit](https://partner.bybit.com/b/jkorf)
|
||||||
|
[CoinEx](https://www.coinex.com/register?refer_code=hd6gn)
|
||||||
|
[FTX](https://ftx.com/referrals#a=31620192)
|
||||||
|
[Huobi](https://www.huobi.com/en-us/v/register/double-invite/?inviter_id=11343840&invite_code=fxp93)
|
||||||
|
[Kucoin](https://www.kucoin.com/ucenter/signup?rcode=RguMux)
|
||||||
|
|
||||||
|
### Donate
|
||||||
|
Make a one time donation in a crypto currency of your choice. If you prefer to donate a currency not listed here please contact me.
|
||||||
|
|
||||||
**Btc**: 12KwZk3r2Y3JZ2uMULcjqqBvXmpDwjhhQS
|
**Btc**: 12KwZk3r2Y3JZ2uMULcjqqBvXmpDwjhhQS
|
||||||
**Eth**: 0x069176ca1a4b1d6e0b7901a6bc0dbf3bb0bf5cc2
|
**Eth**: 0x069176ca1a4b1d6e0b7901a6bc0dbf3bb0bf5cc2
|
||||||
**Nano**: xrb_1ocs3hbp561ef76eoctjwg85w5ugr8wgimkj8mfhoyqbx4s1pbc74zggw7gs
|
**Nano**: xrb_1ocs3hbp561ef76eoctjwg85w5ugr8wgimkj8mfhoyqbx4s1pbc74zggw7gs
|
||||||
|
|
||||||
Alternatively, sponsor me on Github using [Github Sponsors](https://github.com/sponsors/JKorf)
|
### Sponsor
|
||||||
|
Alternatively, sponsor me on Github using [Github Sponsors](https://github.com/sponsors/JKorf).
|
||||||
Reference in New Issue
Block a user