mirror of
https://github.com/JKorf/CryptoExchange.Net.git
synced 2026-08-12 08:53:01 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 277be7ab9b | |||
| 45f3459f59 | |||
| 98dad4a8ed | |||
| 1e5f19271b | |||
| 8abeeb4cf0 | |||
| cae0cd9ead | |||
| 811574ae01 | |||
| 0ddecf7f8d | |||
| 5bcf50fb4d |
@@ -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.2</PackageVersion>
|
<PackageVersion>5.2.4</PackageVersion>
|
||||||
<AssemblyVersion>5.2.2</AssemblyVersion>
|
<AssemblyVersion>5.2.4</AssemblyVersion>
|
||||||
<FileVersion>5.2.2</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.2 - Added support for retrieving a new url when socket connection is lost and reconnection will happen</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>
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
@@ -43,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>
|
||||||
@@ -155,13 +157,22 @@ namespace CryptoExchange.Net.Sockets
|
|||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,6 +227,10 @@ namespace CryptoExchange.Net.Sockets
|
|||||||
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");
|
||||||
@@ -242,6 +257,7 @@ namespace CryptoExchange.Net.Sockets
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_lastReconnectTime = DateTime.UtcNow;
|
||||||
OnReconnected?.Invoke();
|
OnReconnected?.Invoke();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -660,7 +676,7 @@ namespace CryptoExchange.Net.Sockets
|
|||||||
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;
|
||||||
|
|||||||
@@ -8,16 +8,40 @@ 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
|
* Version 5.2.2 - 17 Jul 2022
|
||||||
* Added support for retrieving a new url when socket connection is lost and reconnection will happen
|
* Added support for retrieving a new url when socket connection is lost and reconnection will happen
|
||||||
|
|
||||||
|
|||||||
+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