mirror of
https://github.com/JKorf/CryptoExchange.Net.git
synced 2026-08-20 12:53:02 +00:00
Squashed commit of the following:
commit9450d447b9Author: Jkorf <jankorf91@gmail.com> Date: Fri Feb 18 11:05:46 2022 +0100 Updated version commitbc0b55f337Author: Jkorf <jankorf91@gmail.com> Date: Fri Feb 18 10:09:26 2022 +0100 Added clientOrderId parameter to common clients commit31111006c7Author: Jkorf <jankorf91@gmail.com> Date: Thu Feb 17 16:32:53 2022 +0100 Update SpotClient.razor commite7400ce334Author: Jkorf <jankorf91@gmail.com> Date: Thu Feb 17 16:10:49 2022 +0100 Made some names more generic commit9bdef400daAuthor: Jkorf <jankorf91@gmail.com> Date: Tue Feb 15 11:38:41 2022 +0100 Updated vesrion commit3b80a945eeAuthor: Jkorf <jankorf91@gmail.com> Date: Tue Feb 15 11:34:50 2022 +0100 docs commit0268e211e9Author: Jkorf <jankorf91@gmail.com> Date: Tue Feb 15 09:56:45 2022 +0100 Immediate initial reconnect attempt when connection is lost commit6eb43c5218Author: Jkorf <jankorf91@gmail.com> Date: Fri Feb 11 13:59:05 2022 +0100 Re-added recalculation interval commit1df63ab60cAuthor: Jkorf <jankorf91@gmail.com> Date: Wed Feb 9 14:32:00 2022 +0100 Updated version commit9461b57daaAuthor: Jkorf <jankorf91@gmail.com> Date: Wed Feb 9 13:37:12 2022 +0100 Fix for time offset calculation not updating when offset is < 500ms commit105547d6b1Author: Jan Korf <jankorf91@gmail.com> Date: Sat Feb 5 21:05:10 2022 +0100 Updated version commit379ded6832Author: Jan Korf <jankorf91@gmail.com> Date: Sat Feb 5 20:29:57 2022 +0100 Fixed tests commitb18204a52dAuthor: Jan Korf <jankorf91@gmail.com> Date: Sat Feb 5 20:28:08 2022 +0100 Added CancellationToken support on Common client interface and SymbolOrderBook, improved SymbolOrderBook start/stop robustness commitbaa23c2eccAuthor: Jan Korf <jankorf91@gmail.com> Date: Sat Feb 5 14:56:32 2022 +0100 Added GetSubscriptionByRequest method on socket connection commit7aad9482a5Author: Jkorf <jankorf91@gmail.com> Date: Wed Feb 2 10:57:06 2022 +0100 Updated version commit6e4d9d225eAuthor: Jkorf <jankorf91@gmail.com> Date: Wed Feb 2 09:42:22 2022 +0100 Fixed exception when deserializing non-nullable datetime value '0' in .net framework commitfd1a2bbda9Author: Jkorf <jankorf91@gmail.com> Date: Tue Jan 25 13:19:10 2022 +0100 Updated version commit2ece04dd58Author: Jkorf <jankorf91@gmail.com> Date: Tue Jan 25 13:17:25 2022 +0100 Refactored use of AutoResetEvent to AsyncResetEvent in SymbolOrderBook commit893d0c723dAuthor: Jkorf <jankorf91@gmail.com> Date: Tue Jan 25 13:01:21 2022 +0100 Fixed DateTime converter for nanosecond times in string format commit2c43ee7554Author: Jkorf <jankorf91@gmail.com> Date: Mon Jan 24 15:56:24 2022 +0100 Updated version version; fixed dependencies commit100a34d1a0Author: Jkorf <jankorf91@gmail.com> Date: Mon Jan 24 14:37:15 2022 +0100 Updated version commitbb1071472fAuthor: Jkorf <jankorf91@gmail.com> Date: Mon Jan 24 14:31:57 2022 +0100 Re-added Common prefix for common enums to avoid conflicts with library namespaces commit37b1d18104Author: Jkorf <jankorf91@gmail.com> Date: Fri Jan 21 15:25:33 2022 +0100 Updated version commit325389cdf8Author: Jan Korf <jankorf91@gmail.com> Date: Thu Jan 20 21:08:51 2022 +0100 Added FTX to console example commit3e23882572Author: Jkorf <jankorf91@gmail.com> Date: Thu Jan 20 16:21:42 2022 +0100 Replaced Debug.WriteLine with Trace.WriteLine commit3cf5480cadAuthor: Jan Korf <jankorf91@gmail.com> Date: Wed Jan 19 22:07:22 2022 +0100 Example commitfe31cf156dAuthor: Jkorf <jankorf91@gmail.com> Date: Wed Jan 19 16:35:08 2022 +0100 Examples commit7427914cb7Author: Jkorf <jankorf91@gmail.com> Date: Tue Jan 18 16:46:43 2022 +0100 Update index.md commit1bc6225814Author: Jkorf <jankorf91@gmail.com> Date: Tue Jan 18 16:45:10 2022 +0100 docs commit259fe6bfd1Author: Jkorf <jankorf91@gmail.com> Date: Tue Jan 18 14:25:20 2022 +0100 Update index.md commit5f9c075ac7Author: Jkorf <jankorf91@gmail.com> Date: Tue Jan 18 14:22:33 2022 +0100 Update index.md commita26514016aAuthor: Jkorf <jankorf91@gmail.com> Date: Tue Jan 18 14:13:35 2022 +0100 Update index.md commit01a97412bfAuthor: Jkorf <jankorf91@gmail.com> Date: Tue Jan 18 14:12:02 2022 +0100 docs commit24b503ca8cAuthor: Jkorf <jankorf91@gmail.com> Date: Tue Jan 18 13:42:12 2022 +0100 docs commit008b15b055Author: Jkorf <jankorf91@gmail.com> Date: Tue Jan 18 13:32:55 2022 +0100 docs commit66fce6cb84Author: Jan Korf <jankorf91@gmail.com> Date: Mon Jan 17 21:31:53 2022 +0100 docs commit0f65701f90Author: Jan Korf <jankorf91@gmail.com> Date: Mon Jan 17 21:25:33 2022 +0100 docs commitf7a405a2e6Author: Jkorf <jankorf91@gmail.com> Date: Mon Jan 17 16:32:50 2022 +0100 docs commit55284c0549Author: Jkorf <jankorf91@gmail.com> Date: Mon Jan 17 15:51:03 2022 +0100 docs commit5bfbcca25bAuthor: Jkorf <jankorf91@gmail.com> Date: Mon Jan 17 14:04:08 2022 +0100 docs commitcdbc0ba215Author: Jkorf <jankorf91@gmail.com> Date: Mon Jan 17 13:58:51 2022 +0100 docs commite33e7c6775Author: Jkorf <jankorf91@gmail.com> Date: Mon Jan 17 13:47:58 2022 +0100 docs commitb65669659dAuthor: Jkorf <jankorf91@gmail.com> Date: Mon Jan 17 13:44:45 2022 +0100 docs commite51b863242Merge:dbfe34f088f35dAuthor: Jkorf <jankorf91@gmail.com> Date: Mon Jan 17 13:36:51 2022 +0100 Merge branch 'feature/new-cc' of https://github.com/JKorf/CryptoExchange.Net into feature/new-cc commitdbfe34f534Author: Jkorf <jankorf91@gmail.com> Date: Mon Jan 17 13:35:46 2022 +0100 Docs commit088f35d420Author: Jan Korf <jankorf91@gmail.com> Date: Mon Jan 17 13:34:40 2022 +0100 Set theme jekyll-theme-cayman commite77add4d1cAuthor: Jan Korf <jankorf91@gmail.com> Date: Sat Jan 15 15:26:38 2022 +0100 Updated version commita37a2d6e31Author: Jan Korf <jankorf91@gmail.com> Date: Sat Jan 15 15:23:52 2022 +0100 Added CallResult tests, fixed response time not set commit8f6e853e13Author: Jkorf <jankorf91@gmail.com> Date: Fri Jan 14 16:47:49 2022 +0100 Added Request info and ResponseTime to WebCallResult, refactored CallResult ctors commitc6bf0d67a4Author: Jkorf <jankorf91@gmail.com> Date: Fri Jan 7 16:30:02 2022 +0100 Fix typo commit996f3c2cedAuthor: Jkorf <jankorf91@gmail.com> Date: Fri Jan 7 16:23:42 2022 +0100 Some options logging commitfb9e9f9aa6Author: Jkorf <jankorf91@gmail.com> Date: Fri Jan 7 15:10:27 2022 +0100 Updated version commit52ebacaa21Author: Jkorf <jankorf91@gmail.com> Date: Fri Jan 7 15:05:51 2022 +0100 Fixed symbol order book tostring not locking thread, Potential fix for request timeout showing unclear message commit6b45859934Author: Jkorf <jankorf91@gmail.com> Date: Mon Jan 3 14:08:35 2022 +0100 Updated example commitebe332b724Author: Jkorf <jankorf91@gmail.com> Date: Mon Jan 3 12:05:47 2022 +0100 Updated version commit8c24b46fb3Author: Jkorf <jankorf91@gmail.com> Date: Mon Jan 3 11:33:07 2022 +0100 Fixed typo Comon -> Common commit7a195f662cAuthor: Jkorf <jankorf91@gmail.com> Date: Mon Jan 3 09:37:50 2022 +0100 Updated example, removed global.json commit120132c45bAuthor: Jan Korf <jankorf91@gmail.com> Date: Sat Jan 1 20:30:35 2022 +0100 Reverted conditional refs commitb3b4ed3f3fAuthor: Jan Korf <jankorf91@gmail.com> Date: Sat Jan 1 19:45:59 2022 +0100 Updated version commitf4b4c93e64Author: Jan Korf <jankorf91@gmail.com> Date: Sat Jan 1 19:40:50 2022 +0100 Added new shared interface implementation commitf8c3b37cdfAuthor: Jan Korf <jankorf91@gmail.com> Date: Tue Dec 28 14:14:15 2021 +0100 wip example commit0117737dfaAuthor: Jan Korf <jankorf91@gmail.com> Date: Tue Dec 28 14:13:14 2021 +0100 Added conditional refs for Microsoft.Extensions, added DependencyInjection.Abstractions to support extension method on IServiceCollection commit02c1f874e1Author: Jan Korf <jankorf91@gmail.com> Date: Mon Dec 27 15:32:07 2021 +0100 Updated version commitb212842ec8Author: Jan Korf <jankorf91@gmail.com> Date: Mon Dec 27 15:27:14 2021 +0100 Added ExchangeName to IExchangeClient interface commitc96e75d6c3Author: Jkorf <jankorf91@gmail.com> Date: Tue Dec 21 16:22:51 2021 +0100 Updated version commitc62fbda3d7Author: Jkorf <jankorf91@gmail.com> Date: Fri Dec 17 14:17:30 2021 +0100 Added ApiClients list for managing api credentials, requests made and dispose commit04b43257a5Author: Jkorf <jankorf91@gmail.com> Date: Thu Dec 16 16:17:26 2021 +0100 Update .gitignore commit8ba0ded16dAuthor: Jkorf <jankorf91@gmail.com> Date: Mon Dec 13 12:57:31 2021 +0100 Fixed api credentials getting disposed, fixed DateTimeConverter losing precision commit5c665ad54cAuthor: Jkorf <jankorf91@gmail.com> Date: Fri Dec 10 16:35:42 2021 +0100 Refactoring and comments commitb7cd6a866aAuthor: Jan Korf <jankorf91@gmail.com> Date: Wed Dec 8 21:49:25 2021 +0100 Auth work commitc2105fe690Author: Jkorf <jankorf91@gmail.com> Date: Wed Dec 8 16:20:44 2021 +0100 Wip, support for time syncing, refactoring authentication commit8b479547abAuthor: Jkorf <jankorf91@gmail.com> Date: Tue Dec 7 15:47:55 2021 +0100 Fixed release name commit2ab032b871Author: Jkorf <jankorf91@gmail.com> Date: Tue Dec 7 15:47:14 2021 +0100 Updated version commit48baaeb2d8Author: Jkorf <jankorf91@gmail.com> Date: Mon Dec 6 16:18:18 2021 +0100 Added periodic identifier commit60ec18919aAuthor: Jan Korf <jankorf91@gmail.com> Date: Sun Dec 5 17:26:55 2021 +0100 Added quotes to log commit0818c6277bAuthor: Jkorf <jankorf91@gmail.com> Date: Fri Dec 3 16:23:05 2021 +0100 Small changes commit6d0120d564Author: Jkorf <jankorf91@gmail.com> Date: Wed Dec 1 16:26:34 2021 +0100 Comments, fix test commit3c3b5639f5Author: Jkorf <jankorf91@gmail.com> Date: Wed Dec 1 13:31:54 2021 +0100 Refactor clients/options commit49de7e89ccAuthor: Jkorf <jankorf91@gmail.com> Date: Tue Nov 30 10:31:45 2021 +0100 Disposable changes, fixed tests commit69a6fabb79Author: Jkorf <jankorf91@gmail.com> Date: Mon Nov 29 16:43:27 2021 +0100 Restruct commit9a266e44ceAuthor: Jkorf <jankorf91@gmail.com> Date: Fri Nov 26 09:32:26 2021 +0100 Added enum converter commit78f81393a4Author: Jkorf <jankorf91@gmail.com> Date: Thu Nov 25 10:25:56 2021 +0100 Removed old timestamp converters commit9ebe5de825Author: Jan Korf <jankorf91@gmail.com> Date: Wed Nov 24 19:32:37 2021 +0100 Added AppendPath method commit8b619e82f2Author: Jkorf <jankorf91@gmail.com> Date: Wed Nov 24 16:39:14 2021 +0100 Added DateTimeConverter as replacement for individual converters, fix for not closing socket when auth fails commit7ac7a11dfeAuthor: Jkorf <jankorf91@gmail.com> Date: Wed Nov 17 10:23:01 2021 +0100 Resolved some code issues commit3784b0c62bAuthor: Jkorf <jankorf91@gmail.com> Date: Mon Nov 15 16:36:30 2021 +0100 Ratelimiter rework commitcb1826da7aAuthor: Jkorf <jankorf91@gmail.com> Date: Fri Nov 12 09:40:42 2021 +0100 Documentation commitf7445543f2Author: Jkorf <jankorf91@gmail.com> Date: Wed Nov 10 16:44:46 2021 +0100 Exposed order book id commit6c3462403fAuthor: Jkorf <jankorf91@gmail.com> Date: Wed Nov 10 13:18:52 2021 +0100 Fixed tests commitf83127590aAuthor: Jkorf <jankorf91@gmail.com> Date: Wed Nov 3 08:27:03 2021 +0100 wip commit23bbf0ef88Author: Jkorf <jankorf91@gmail.com> Date: Wed Oct 27 12:57:23 2021 +0200 Added cancellation token support for socket subscriptions commitb7f1619aecMerge:6ce6a46f6af235Author: Jkorf <jankorf91@gmail.com> Date: Tue Oct 26 15:39:52 2021 +0200 Merge branch 'master' of https://github.com/JKorf/CryptoExchange.Net commit6ce6a46ca3Author: Jkorf <jankorf91@gmail.com> Date: Tue Oct 26 15:39:50 2021 +0200 Some renames
This commit is contained in:
@@ -3,93 +3,7 @@
|
||||
|
||||
CryptoExchange.Net is a base package which can be used to easily implement crypto currency exchange API's in C#. This library offers base classes for creating rest and websocket clients, and includes additional features like an automatically synchronizing order book implementation, error handling and automatic reconnects on websocket connections.
|
||||
|
||||
## Implementations
|
||||
By me:
|
||||
<table>
|
||||
<tr>
|
||||
<td><a href="https://github.com/JKorf/Binance.Net"><img src="https://github.com/JKorf/Binance.Net/blob/master/Binance.Net/Icon/icon.png?raw=true"></a>
|
||||
<br />
|
||||
<a href="https://github.com/JKorf/Binance.Net">Binance</a>
|
||||
</td>
|
||||
<td><a href="https://github.com/JKorf/Bittrex.Net"><img src="https://github.com/JKorf/Bittrex.Net/blob/master/Bittrex.Net/Icon/icon.png?raw=true"></a>
|
||||
<br />
|
||||
<a href="https://github.com/JKorf/Bittrex.Net">Bittrex</a>
|
||||
</td>
|
||||
<td><a href="https://github.com/JKorf/Bitfinex.Net"><img src="https://github.com/JKorf/Bitfinex.Net/blob/master/Bitfinex.Net/Icon/icon.png?raw=true"></a>
|
||||
<br />
|
||||
<a href="https://github.com/JKorf/Bitfinex.Net">Bitfinex</a>
|
||||
</td>
|
||||
<td><a href="https://github.com/JKorf/CoinEx.Net"><img src="https://github.com/JKorf/CoinEx.Net/blob/master/CoinEx.Net/Icon/icon.png?raw=true"></a>
|
||||
<br />
|
||||
<a href="https://github.com/JKorf/CoinEx.Net">CoinEx</a>
|
||||
</td>
|
||||
<td><a href="https://github.com/JKorf/Huobi.Net"><img src="https://github.com/JKorf/Huobi.Net/blob/master/Huobi.Net/Icon/icon.png?raw=true"></a>
|
||||
<br />
|
||||
<a href="https://github.com/JKorf/Huobi.Net">Huobi</a>
|
||||
</td>
|
||||
<td><a href="https://github.com/JKorf/Kucoin.Net"><img src="https://github.com/JKorf/Kucoin.Net/blob/master/Kucoin.Net/Icon/icon.png?raw=true"></a>
|
||||
<br />
|
||||
<a href="https://github.com/JKorf/Kucoin.Net">Kucoin</a>
|
||||
</td>
|
||||
<td><a href="https://github.com/JKorf/Kraken.Net"><img src="https://github.com/JKorf/Kraken.Net/blob/master/Kraken.Net/Icon/icon.png?raw=true"></a>
|
||||
<br />
|
||||
<a href="https://github.com/JKorf/Kraken.Net">Kraken</a>
|
||||
</td>
|
||||
<td><a href="https://github.com/JKorf/FTX.Net"><img src="https://github.com/JKorf/FTX.Net/blob/main/FTX.Net/Icon/icon.png?raw=true"></a>
|
||||
<br />
|
||||
<a href="https://github.com/JKorf/FTX.Net">FTX</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
By third parties:
|
||||
<table>
|
||||
<tr>
|
||||
<td><a href="https://github.com/Zaliro/Switcheo.Net"><img src="https://github.com/Zaliro/Switcheo.Net/blob/master/Resources/switcheo-coin.png?raw=true"></a>
|
||||
<br />
|
||||
<a href="https://github.com/Zaliro/Switcheo.Net">Switcheo</a>
|
||||
</td>
|
||||
<td><a href="https://github.com/ridicoulous/LiquidQuoine.Net"><img src="https://github.com/ridicoulous/LiquidQuoine.Net/blob/master/Resources/icon.png?raw=true"></a>
|
||||
<br />
|
||||
<a href="https://github.com/ridicoulous/LiquidQuoine.Net">Liquid</a>
|
||||
</td>
|
||||
<td><a href="https://github.com/ridicoulous/Bitmex.Net"><img src="https://github.com/ridicoulous/Bitmex.Net/blob/master/Bitmex.Net/Icon/icon.png?raw=true"></a>
|
||||
<br />
|
||||
<a href="https://github.com/ridicoulous/Bitmex.Net">Bitmex</a>
|
||||
</td>
|
||||
<td><a href="https://github.com/intelligences/HitBTC.Net"><img src="https://github.com/intelligences/HitBTC.Net/blob/master/src/HitBTC.Net/Icon/icon.png?raw=true"></a>
|
||||
<br />
|
||||
<a href="https://github.com/intelligences/HitBTC.Net">HitBTC</a>
|
||||
</td>
|
||||
<td><a href="https://github.com/EricGarnier/LiveCoin.Net"><img src="https://github.com/EricGarnier/LiveCoin.Net/blob/master/LiveCoin.Net/Icon/icon.png?raw=true"></a>
|
||||
<br />
|
||||
<a href="https://github.com/EricGarnier/LiveCoin.Net">LiveCoin</a>
|
||||
</td>
|
||||
<td><a href="https://github.com/burakoner/OKEx.Net"><img src="https://github.com/burakoner/OKEx.Net/blob/master/Okex.Net/Icon/icon.png?raw=true"></a>
|
||||
<br />
|
||||
<a href="https://github.com/burakoner/OKEx.Net">OKEx</a>
|
||||
</td>
|
||||
<td><a href="https://github.com/burakoner/Chiliz.Net"><img src="https://github.com/burakoner/Chiliz.Net/blob/master/Chiliz.Net/Icon/icon.png?raw=true"></a>
|
||||
<br />
|
||||
<a href="https://github.com/burakoner/Chiliz.Net">Chiliz</a>
|
||||
</td>
|
||||
<td><a href="https://github.com/burakoner/BtcTurk.Net"><img src="https://github.com/burakoner/BtcTurk.Net/blob/master/BtcTurk.Net/Icon/icon.png?raw=true"></a>
|
||||
<br />
|
||||
<a href="https://github.com/burakoner/BtcTurk.Net">BtcTurk</a>
|
||||
</td>
|
||||
<td><a href="https://github.com/burakoner/Thodex.Net"><img src="https://github.com/burakoner/Thodex.Net/blob/master/Thodex.Net/Icon/icon.png?raw=true"></a>
|
||||
<br />
|
||||
<a href="https://github.com/burakoner/Thodex.Net">Thodex</a>
|
||||
</td>
|
||||
<td><a href="https://github.com/d-ugarov/Exante.Net"><img src="https://github.com/d-ugarov/Exante.Net/blob/master/Exante.Net/Icon/icon.png?raw=true"></a>
|
||||
<br />
|
||||
<a href="https://github.com/d-ugarov/Exante.Net">Exante</a>
|
||||
</td>
|
||||
<td><a href="https://github.com/rodrigobelo/wootrade-dotnet"><img src="https://github.com/rodrigobelo/wootrade-dotnet/blob/main/wootrade-dotnet-icon.png?raw=true"></a>
|
||||
<br />
|
||||
<a href="https://github.com/rodrigobelo/wootrade-dotnet">Wootrade</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
[Documentation](https://jkorf.github.io/CryptoExchange.Net/)
|
||||
|
||||
## 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.
|
||||
@@ -103,229 +17,23 @@ I develop and maintain this package on my own for free in my spare time. Donatio
|
||||
|
||||
Alternatively, sponsor me on Github using [Github Sponsors](https://github.com/sponsors/JKorf)
|
||||
|
||||
## Implementation usage
|
||||
### Clients
|
||||
The CryptoExchange.Net library offers 2 base clients which should be implemented in each implementation library. The `RestClient` and the `SocketClient`.
|
||||
|
||||
**RestClient**
|
||||
|
||||
The `RestClient`, as the name suggests, handles requests to the exchange REST API. Typically the `RestClient` implementation name is [ExchangeName]Client. So for the Binance exchange this would be called the `BinanceClient`, and for Bittrex the client type name is `BittrexClient`.
|
||||
|
||||
The `RestClient` implementations can be used in either a `using` or with a static instance:
|
||||
````C#
|
||||
using (var binanceClient = new BinanceClient())
|
||||
{
|
||||
var exchangeInfoResult = binanceClient.Spot.System.GetExchangeInfoAsync();
|
||||
}
|
||||
````
|
||||
or
|
||||
````C#
|
||||
var client = new BinanceClient();
|
||||
var exchangeInfoResult = client.Spot.System.GetExchangeInfoAsync();
|
||||
````
|
||||
If you're opting for the `using` syntax, a `HttpClient` should be provided in the client options to prevent each client creating it's own `HttpClient` instance.
|
||||
|
||||
Calls made on the `RestClient` will return a `WebCallResult<T>` object which will contain the following properties:
|
||||
|Property|Description|Available when
|
||||
|---|---|---|
|
||||
|`Success`|Whether or not the call was successfully executed.|Always
|
||||
|`Data`|The data the server sent us as response.| When `Success` is `true`
|
||||
|`Error`|Details on the error that happened during the call.| When `Success` is `false`
|
||||
|`OriginalData`|The originally received Json data which was received before being deserialized into an object.| When `OutputOriginalData` is enabled in the client options
|
||||
|`ResponseStatusCode`|The Http status code received as answer on the request.|Always
|
||||
|`ResponseHeaders`|The headers received in the response.|Always
|
||||
|
||||
The `RestClient` implementation should implement the `IExchangeClient` interface, which offers some basic methods for interacting with an exchange without having to know the implementation.
|
||||
|
||||
**SocketClient**
|
||||
|
||||
The `SocketClient` can be used to connect to websocket streams offered by the API, and receive callbacks whenever new data is received. `SocketClient` implementations are typically named [ExchangeName]SocketClient, so in case of Binance this would be `BinanceSocketClient`.
|
||||
|
||||
To use the `SocketClient` to connect to a stream simply call the `SubscribeXXX` method for the data you're interested in and pass in a delegate for handling updates. For example, to subscribe to the Binance ticker stream call `SubscribeToAllSymbolTickerUpdatesAsync` method:
|
||||
````C#
|
||||
var socketClient = new BinanceSocketClient();
|
||||
var subscribeResult = socketClient.Spot.SubscribeToAllSymbolTickerUpdatesAsync(data => {
|
||||
// Handle updates received here
|
||||
});
|
||||
````
|
||||
or
|
||||
````C#
|
||||
var socketClient = new BinanceSocketClient();
|
||||
var subscribeResult = socketClient.Spot.SubscribeToAllSymbolTickerUpdatesAsync(HandleData);
|
||||
|
||||
private void HandleData(DataEvent<IEnumerable<BinanceTick>> data)
|
||||
{
|
||||
// Handle updates received here
|
||||
}
|
||||
````
|
||||
|
||||
Make sure to check the result of the subscribe call to ensure it was successful. The Subscribe methods will return a `CallResult<UpdateSubscription>` object with the following properties:
|
||||
|Property|Description|Available when
|
||||
|---|---|---|
|
||||
|`Success`|Whether or not the call was successfully executed.|Always
|
||||
|`Data`|The `UpdateSubscription` object for this stream. This can be used to for listening to connection changed events and unsubscribing | When `Success` is `true`
|
||||
|`Error`|Details on the error that happened during the subscription. | When `Success` is `false`
|
||||
|
||||
To unsubscribe from a stream `Unsubscribe()` method can be used, with the `UpdateSubscription` received in the `SubscribeXXX` call as parameter, or use the `UnsubscribeAll()` method to close all subscriptions:
|
||||
````C#
|
||||
// Subscribe
|
||||
var client = new BinanceSocketClient();
|
||||
var subResult = client.Spot.SubscribeToOrderBookUpdates("BTCUSDT", data => {});
|
||||
|
||||
// Unsubscribe
|
||||
client.Unsubscribe(subResult.Data);
|
||||
````
|
||||
The `SocketClient` handles connection management to the server internally and will close a connection if there are no more subscriptions on that connection.
|
||||
|
||||
*[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.*
|
||||
|
||||
### Client options
|
||||
Options for a client can be provided in the constructor or using the static SetDefaultOptions method.
|
||||
````C#
|
||||
var client = new BinanceClient(new BinanceClientOptions()
|
||||
{
|
||||
});
|
||||
````
|
||||
or
|
||||
````C#
|
||||
BinanceClient.SetDefaultOptions(new BinanceClientOptions()
|
||||
{
|
||||
});
|
||||
````
|
||||
When providing options in the constructor the options will only apply for that specific client. When using the `SetDefaultOptions` method the options will be applied to any client created after that call which doesn't have any options provided to it via the constructor. Providing options in the constructor means any options set using the `SetDefaultOptions` method will be reset to default unless overwritten in the provided options.
|
||||
|
||||
**Options for all clients**
|
||||
|
||||
| Property | Description | Default |
|
||||
| ----------- | ----------- | ---------|
|
||||
| `LogWriters`| A list of `ILogger`s to handle log messages. | `new List<ILogger> { new DebugLogger() }` |
|
||||
| `LogLevel`| The minimum log level before passing messages to the `LogWriters`. Messages with a more verbose level than the one specified here will be ignored. Setting this to `null` will pass all messages to the `LogWriters`.| `LogLevel.Information`
|
||||
|`OutputOriginalData`|If set to `true` the originally received Json data will be output as well as the deserialized object. For `RestClient` calls the data will be in the `WebCallResult<T>.OriginalData` property, for `SocketClient` subscriptions the data will be available in the `DataEvent<T>.OriginalData` property when receiving an update. | `false`
|
||||
|`BaseAddress`|The base address to the API. All calls to the API will use this base address as basis for the endpoints. This allows for swapping to test API's or swapping to a different cluster for example.| Depends on implementation
|
||||
|`ApiCredentials`| The API credentials to use for accessing protected endpoints. Typically a key/secret combination.| `null`
|
||||
|`Proxy`|The proxy to use for connecting to the API.| `null`
|
||||
|
||||
**Options for RestClients**
|
||||
| Property | Description | Default |
|
||||
| ----------- | ----------- | ---------|
|
||||
| `RateLimiters`| A list of `IRateLimiter`s to use.| `new List<IRateLimiter>()` |
|
||||
| `RateLimitingBehaviour`| What should happen when a rate limit is reached.| `RateLimitingBehaviour.Wait` |
|
||||
| `RequestTimeout`| The time out to use for requests.| `TimeSpan.FromSeconds(30)` |
|
||||
| `HttpClient`| The `HttpClient` instance to use for making requests. When creating multiple `RestClient` instances a single `HttpClient` should be provided to prevent each client instance from creating its own. *[WARNING] When providing the `HttpClient` instance in the options both the `RequestTimeout` and `Proxy` client options will be ignored and should be set on the provided `HttpClient` instance.*| `null` |
|
||||
|
||||
**Options for SocketClients**
|
||||
| Property | Description | Default |
|
||||
| ----------- | ----------- | ---------|
|
||||
|`AutoReconnect`|Whether or not the socket should automatically reconnect when disconnected.|`true`
|
||||
|`ReconnectInterval`|The time to wait between connection tries when reconnecting.|`TimeSpan.FromSeconds(5)`
|
||||
|`SocketResponseTimeout`|The time in which a response is expected on a request before giving a timeout.|`TimeSpan.FromSeconds(10)`
|
||||
|`SocketNoDataTimeout`|If no data is received after this timespan then assume the connection is dropped. This is mainly used for API's which have some sort of ping/keepalive system. For example; the Bitfinex API will sent a heartbeat message every 15 seconds, so the `SocketNoDataTimeout` could be set to 20 seconds. On API's without such a mechanism this might not work because there just might not be any update while still being fully connected. | `default(TimeSpan)` (no timeout)
|
||||
|`SocketSubscriptionsCombineTarget`|The amount of subscriptions that should be made on a single socket connection. Not all exchanges support multiple subscriptions on a single socket. Setting this to a higher number increases subscription speed because not every subscription needs to connect to the server, but having more subscriptions on a single connection will also increase the amount of traffic on that single connection, potentially leading to issues.| Depends on implementation
|
||||
|`MaxReconnectTries`|The maximum amount of tries for reconnecting|`null` (infinite)
|
||||
|`MaxResubscribeTries`|The maximum amount of tries for resubscribing after successfully reconnecting the socket|5
|
||||
|`MaxConcurrentResubscriptionsPerSocket`|The maximum number of concurrent resubscriptions per socket when resubscribing after reconnecting|5
|
||||
|
||||
### Order book
|
||||
The library implementations provide a `SymbolOrderBook` implementation. This implementation can be used to keep an updated order book without having to think about synchronization. This example is from the Binance.Net library, but the implementation is similar for each library:
|
||||
````C#
|
||||
var orderBook = new BinanceSymbolOrderBook("BTCUSDT", new BinanceOrderBookOptions(20));
|
||||
orderBook.OnStatusChange += (oldStatus, newStatus) => Console.WriteLine($"Book state changed from {oldStatus} to {newStatus}");
|
||||
orderBook.OnOrderBookUpdate += ((changedBids, changedAsks)) => Console.WriteLine("Book updated");
|
||||
var startResult = await orderBook.StartAsync();
|
||||
if(!startResult.Success)
|
||||
{
|
||||
Console.WriteLine("Error starting order book synchronization: " + startResult.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
var status = orderBook.Status; // The current status. Note that the order book is only up to date when the status is Synced
|
||||
var askCount = orderBook.AskCount; // The current number of asks in the book
|
||||
var bidCount = orderBook.BidCount; // The current number of bids in the book
|
||||
var asks = orderBook.Asks; // All asks
|
||||
var bids = orderBook.Bids; // All bids
|
||||
var bestBid = orderBook.BestBid; // The best bid available in the book
|
||||
var bestAsk = orderBook.BestAsk; // The best ask available in the book
|
||||
````
|
||||
The order book will automatically reconnect when the connection is lost and resync if it detects that it is out of sync. Make sure to check the Status property to see it the book is currently in sync.
|
||||
|
||||
To stop synchronizing an order book use the `Stop` method.
|
||||
|
||||
## Helper methods
|
||||
The static `ExchangeHelpers` class offers some helper methods for adjusting value like rounding and adjusting values to fit a certain step size or precision.
|
||||
|
||||
## Creating an implementation
|
||||
Implementations should implement at least the following:
|
||||
**[Exchange]Client based on the RestClient base class**
|
||||
Containing calls to the different endpoints, internally using the `SendRequest<T>` method of the `RestClient`.
|
||||
|
||||
**[Exchange]SocketClient based on the SocketClient base class**
|
||||
Containing methods to subscribe to different streams using the `Subscribe<T>` method of the `SocketClient`.
|
||||
Implement exchange specific handling of requests/messages by overriding these methods:
|
||||
`HandleQueryResponse`: Check if the data received from the websocket matches the sent query.
|
||||
`HandleSubscriptionResponse`: Check if the data received from the websocket matches the subscription request.
|
||||
`MessageMatchesHandler`: Check if the data received from the websocket matches the handler/subscription.
|
||||
`AuthenticateSocket`: Authenticate the connection to be able to subscribe to protected streams.
|
||||
`Unsubscribe`: Unsubscribe from a stream, typically by sending an Unsubscribe message.
|
||||
|
||||
**[Exchange]SymbolOrderBook based on the SymbolOrderBook base class**
|
||||
An implementation of an automatically synchronized order book. Implement exchange specific behavior by implementing these methods:
|
||||
`DoStart`: Start the order book and sync process
|
||||
`DoResync`: Resync the order book after a reconnection
|
||||
`DoReset`: Reset the state of the orderbook, called when the connection is lost.
|
||||
`DoChecksum`: [Optional] Validate the order book with a checksum.
|
||||
|
||||
**[Exchange]AuthenticationProvider**
|
||||
An implementation of the AuthenticationProvider base class. Should contain the logic for authenticating requests from the RestClient on protected endpoints. Override these methods as needed:
|
||||
`AddAuthenticationToParameters`: Will be called before `AddAuthenticationToHeaders`, allows the implementation to add specific parameters to the request which are needed for protected endpoints.
|
||||
`AddAuthenticationToHeaders`: Will be called after `AddAuthenticationToParameters`, allows the implementation to add specific headers to the request message.
|
||||
If you have any issues or questions regarding implementing an exchange using CryptoExchange.Net hop into the Discord or open an issue.
|
||||
|
||||
## FAQ
|
||||
**I sometimes get NullReferenceException, what's wrong?**
|
||||
You probably don't check the result status of a call and just assume the data is always there. `NullReferenceExecption`s will happen when you have code like this `var symbol = client.GetTickersAync().Result.Data.Symbol` because the `Data` property is null when the call fails. Instead check if the call is successful like this:
|
||||
````C#
|
||||
var tickerResult = await client.GetTickersAync();
|
||||
if(!tickerResult.Success)
|
||||
{
|
||||
// Handle error
|
||||
}
|
||||
else
|
||||
{
|
||||
// Handle data, it is now safe to access the data
|
||||
var symbol = tickerResult.Data.Symbol;
|
||||
}
|
||||
````
|
||||
**The socket client stops sending updates after a little while**
|
||||
You probably didn't keep a reference to the socket client and it got disposed.
|
||||
Instead of subscribing like this:
|
||||
````C#
|
||||
private void SomeMethod()
|
||||
{
|
||||
var socketClient = new BinanceSocketClient();
|
||||
socketClient.Spot.SubscribeToOrderBookUpdates("BTCUSDT", data => {
|
||||
// Handle data
|
||||
});
|
||||
}
|
||||
````
|
||||
Subscribe like this:
|
||||
````C#
|
||||
private BinanceSocketClient _socketClient;
|
||||
|
||||
// .. rest of the class
|
||||
|
||||
private void SomeMethod()
|
||||
{
|
||||
if(_socketClient == null)
|
||||
_socketClient = new BinanceSocketClient();
|
||||
|
||||
_socketClient.Spot.SubscribeToOrderBookUpdates("BTCUSDT", data => {
|
||||
// Handle data
|
||||
});
|
||||
}
|
||||
|
||||
````
|
||||
|
||||
## Release notes
|
||||
* Version 5.0.0
|
||||
* Added Github.io page for documentation: https://jkorf.github.io/CryptoExchange.Net/
|
||||
* Added single DateTimeConverter replacing the different timestamp converters
|
||||
* Added additional request related properties to WebCallResult
|
||||
* Added CancelationToken support for websockets
|
||||
* Added CancelationToken support for SymbolOrderBook starting
|
||||
* Added TimeSync support
|
||||
* Refactored base client classes into BaseClient and ApiClient to provide a more defined client structure
|
||||
* Refactored client options to have better control over each different ApiClient
|
||||
* Refactored authentication provider to be more flexible
|
||||
* Refactored rate limiter implementation
|
||||
* Refactored IExchangeClient interface to ISpotClient and IFuturesClient
|
||||
* Refactored socket reconnection to immediately try to reconnect before waiting the ReconnectTimeout
|
||||
* Improved SymbolOrderBook stability
|
||||
* Updated code docs
|
||||
|
||||
* Version 4.2.8 - 08 Oct 2021
|
||||
* Fixed deadlock in socket receive
|
||||
* Fixed issue in reconnection handling when the client is disconnected again during resubscribing
|
||||
|
||||
Reference in New Issue
Block a user