DeriSock 1.1.1
dotnet add package DeriSock --version 1.1.1
NuGet\Install-Package DeriSock -Version 1.1.1
<PackageReference Include="DeriSock" Version="1.1.1" />
paket add DeriSock --version 1.1.1
#r "nuget: DeriSock, 1.1.1"
// Install DeriSock as a Cake Addin
#addin nuget:?package=DeriSock&version=1.1.1
// Install DeriSock as a Cake Tool
#tool nuget:?package=DeriSock&version=1.1.1
DeriSock
DeriSock is a client library that connects to the Deribit API via WebSocket.
All methods and subscriptions found on https://docs.deribit.com are supported.
Getting Started
To connect to the Deribit Network just instantiate a new instance of the DeribitClient
class and call the Connect
method to connect and the Disconnect
method to disconnect.
<a id='snippet-readme-connect-disconnect'></a>
var client = new DeribitClient(EndpointType.Testnet);
await client.Connect();
// do something
await client.Disconnect();
<sup><a href='/src/DeriSock.DevTools/Snippets.cs#L12-L20' title='Snippet source file'>snippet source</a> | <a href='#snippet-readme-connect-disconnect' title='Start of snippet'>anchor</a></sup>
The various methods are organized in categories (Authentication, Supporting, Market Data, ...) and scopes (Private, Public).
Example: Calling GetOrderBook
from the Public
scope.
<a id='snippet-readme-req-bbp-1'></a>
var response = await client.Public.GetOrderBook(
new PublicGetOrderBookRequest
{
InstrumentName = "BTC-PERPETUAL"
});
if (response.Error is not null) {
// Handle errors returned by the API
return;
}
if (response.Data is null) {
// Something unexpected happened. 'Data' should not be null if 'Error' is null
return;
}
var bestBidPrice = response.Data.BestBidPrice;
<sup><a href='/src/DeriSock.DevTools/Snippets.cs#L23-L42' title='Snippet source file'>snippet source</a> | <a href='#snippet-readme-req-bbp-1' title='Start of snippet'>anchor</a></sup>
Example: Calling GetOrderBook
from the MarketData
category.
<a id='snippet-readme-req-bbp-2'></a>
var response = await client.MarketData.PublicGetOrderBook(
new PublicGetOrderBookRequest
{
InstrumentName = "BTC-PERPETUAL"
});
if (response.Error is not null) {
// Handle errors returned by the API
return;
}
if (response.Data is null) {
// Something unexpected happened. 'Data' should not be null if 'Error' is null
return;
}
var bestBidPrice = response.Data.BestBidPrice;
<sup><a href='/src/DeriSock.DevTools/Snippets.cs#L46-L65' title='Snippet source file'>snippet source</a> | <a href='#snippet-readme-req-bbp-2' title='Start of snippet'>anchor</a></sup>
Authentication
The library supports authentication via credentials and signature
Authentication using Credentials
<a id='snippet-readme-auth-credentials'></a>
await client.Authentication.PublicLogin()
.WithClientCredentials(
"<client id",
"<client secret>",
"<optional state>",
"<optional scope>");
<sup><a href='/src/DeriSock.DevTools/Snippets.cs#L69-L77' title='Snippet source file'>snippet source</a> | <a href='#snippet-readme-auth-credentials' title='Start of snippet'>anchor</a></sup>
Authentication using Signature
<a id='snippet-readme-auth-signature'></a>
await client.Authentication.PublicLogin()
.WithClientSignature(
"<client id",
"<client secret>",
"<optional state>",
"<optional scope>");
<sup><a href='/src/DeriSock.DevTools/Snippets.cs#L81-L89' title='Snippet source file'>snippet source</a> | <a href='#snippet-readme-auth-signature' title='Start of snippet'>anchor</a></sup>
Logout
When authenticated, you can logout like this (this is the only synchroneous method):
<a id='snippet-readme-auth-logout'></a>
client.Authentication.PrivateLogout();
<sup><a href='/src/DeriSock.DevTools/Snippets.cs#L93-L96' title='Snippet source file'>snippet source</a> | <a href='#snippet-readme-auth-logout' title='Start of snippet'>anchor</a></sup>
Note: The server will automatically close the connection when you logout
Subscriptions
The subscription system will choose public/subscribe
or private/subscribe
automatically.
If the client is authenticated it will use private/subscribe
, if the client is not authenticated it will use public/subscribe
.
This is also the reason why the subscription methods are not present in the Public
or Private
scopes.
<a id='snippet-readme-subscribtion-usage'></a>
// Subscribe to one or more channels.
var subscriptionStream = await client.Subscriptions.SubscribeBookChanges(
new BookChangesChannel
{
InstrumentName = "BTC-PERPETUAL",
Interval = NotificationInterval2._100ms
},
new BookChangesChannel
{
InstrumentName = "ETH-PERPETUAL",
Interval = NotificationInterval2._100ms
});
// Create a CancellationTokenSource to be able to stop the stream
// (i.e. unsubscribe from the channel(s))
var cts = new CancellationTokenSource();
// An IAsyncEnumerable<T> stream that will listen to incoming notifications as long as
// cts.Cancel(); is not called.
await foreach (var notification in subscriptionStream.WithCancellation(cts.Token)) {
//Here you can do something with the received information.
var bookChangeId = notification.Data.ChangeId;
}
<sup><a href='/src/DeriSock.DevTools/Snippets.cs#L100-L125' title='Snippet source file'>snippet source</a> | <a href='#snippet-readme-subscribtion-usage' title='Start of snippet'>anchor</a></sup>
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Bcl.AsyncInterfaces (>= 6.0.0)
- Newtonsoft.Json (>= 13.0.1)
- Serilog (>= 2.11.0)
-
.NETStandard 2.1
- Newtonsoft.Json (>= 13.0.1)
- Serilog (>= 2.11.0)
-
net5.0
- Newtonsoft.Json (>= 13.0.1)
- Serilog (>= 2.11.0)
-
net6.0
- Newtonsoft.Json (>= 13.0.1)
- Serilog (>= 2.11.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.