mirror of
https://github.com/JKorf/CryptoExchange.Net.git
synced 2026-08-12 00:43:03 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 277be7ab9b | |||
| 45f3459f59 | |||
| 98dad4a8ed | |||
| 1e5f19271b | |||
| 8abeeb4cf0 | |||
| cae0cd9ead | |||
| 811574ae01 |
@@ -132,7 +132,7 @@ namespace CryptoExchange.Net.Converters
|
||||
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
|
||||
{
|
||||
var stringValue = GetString(value);
|
||||
writer.WriteRawValue(stringValue);
|
||||
writer.WriteValue(stringValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,16 +6,16 @@
|
||||
<PackageId>CryptoExchange.Net</PackageId>
|
||||
<Authors>JKorf</Authors>
|
||||
<Description>A base package for implementing cryptocurrency API's</Description>
|
||||
<PackageVersion>5.2.3</PackageVersion>
|
||||
<AssemblyVersion>5.2.3</AssemblyVersion>
|
||||
<FileVersion>5.2.3</FileVersion>
|
||||
<PackageVersion>5.2.4</PackageVersion>
|
||||
<AssemblyVersion>5.2.4</AssemblyVersion>
|
||||
<FileVersion>5.2.4</FileVersion>
|
||||
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<RepositoryUrl>https://github.com/JKorf/CryptoExchange.Net.git</RepositoryUrl>
|
||||
<PackageProjectUrl>https://github.com/JKorf/CryptoExchange.Net</PackageProjectUrl>
|
||||
<NeutralLanguage>en</NeutralLanguage>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<PackageReleaseNotes>5.2.3 - Fixed socket getting disconnected when `no data` timeout is reached instead of being reconnected</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>
|
||||
<LangVersion>9.0</LangVersion>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
|
||||
@@ -9,6 +9,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.WebSockets;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -43,6 +44,7 @@ namespace CryptoExchange.Net.Sockets
|
||||
private bool _stopRequested;
|
||||
private bool _disposed;
|
||||
private ProcessState _processState;
|
||||
private DateTime _lastReconnectTime;
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -155,13 +157,22 @@ namespace CryptoExchange.Net.Sockets
|
||||
cookieContainer.Add(new Cookie(cookie.Key, cookie.Value));
|
||||
|
||||
var socket = new ClientWebSocket();
|
||||
socket.Options.Cookies = cookieContainer;
|
||||
foreach (var header in Parameters.Headers)
|
||||
socket.Options.SetRequestHeader(header.Key, header.Value);
|
||||
socket.Options.KeepAliveInterval = Parameters.KeepAliveInterval ?? TimeSpan.Zero;
|
||||
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);
|
||||
try
|
||||
{
|
||||
socket.Options.Cookies = cookieContainer;
|
||||
foreach (var header in Parameters.Headers)
|
||||
socket.Options.SetRequestHeader(header.Key, header.Value);
|
||||
socket.Options.KeepAliveInterval = Parameters.KeepAliveInterval ?? TimeSpan.Zero;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -216,6 +227,10 @@ namespace CryptoExchange.Net.Sockets
|
||||
OnReconnecting?.Invoke();
|
||||
}
|
||||
|
||||
var sinceLastReconnect = DateTime.UtcNow - _lastReconnectTime;
|
||||
if (sinceLastReconnect < Parameters.ReconnectInterval)
|
||||
await Task.Delay(Parameters.ReconnectInterval - sinceLastReconnect).ConfigureAwait(false);
|
||||
|
||||
while (!_stopRequested)
|
||||
{
|
||||
_log.Write(LogLevel.Debug, $"Socket {Id} attempting to reconnect");
|
||||
@@ -242,6 +257,7 @@ namespace CryptoExchange.Net.Sockets
|
||||
continue;
|
||||
}
|
||||
|
||||
_lastReconnectTime = DateTime.UtcNow;
|
||||
OnReconnected?.Invoke();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,12 @@ namespace CryptoExchange.Net.Sockets
|
||||
/// </summary>
|
||||
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;
|
||||
Timestamp = timestamp;
|
||||
|
||||
@@ -8,16 +8,37 @@ CryptoExchange.Net is a base package which can be used to easily implement crypt
|
||||
## 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.
|
||||
|
||||
## Donate / Sponsor
|
||||
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.
|
||||
## Support the project
|
||||
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
|
||||
**Eth**: 0x069176ca1a4b1d6e0b7901a6bc0dbf3bb0bf5cc2
|
||||
**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
|
||||
* 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
|
||||
|
||||
|
||||
+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.*
|
||||
|
||||
### 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
|
||||
|
||||
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
|
||||
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
|
||||
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.
|
||||
## Support the project
|
||||
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
|
||||
**Eth**: 0x069176ca1a4b1d6e0b7901a6bc0dbf3bb0bf5cc2
|
||||
**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