Bybit.Net
Bybit.Net is a strongly typed client library for accessing the Bybit REST and Websocket API. All data is mapped to readable models and enum values. Additional features include an implementation for maintaining a client side order book, easy integration with other exchange client libraries and more.
Supported Frameworks
The library is targeting both .NET Standard 2.0
and .NET Standard 2.1
for optimal compatibility
.NET implementation | Version Support |
---|---|
.NET Core | 2.0 and higher |
.NET Framework | 4.6.1 and higher |
Mono | 5.4 and higher |
Xamarin.iOS | 10.14 and higher |
Xamarin.Android | 8.0 and higher |
UWP | 10.0.16299 and higher |
Unity | 2018.1 and higher |
Discord
A Discord server is available here. Feel free to join for discussion and/or questions around the CryptoExchange.Net and implementation libraries.
Support the project
DonateMake 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: bc1q277a5n54s2l2mzlu778ef7lpkwhjhyvghuv8qf
Eth: 0xcb1b63aCF9fef2755eBf4a0506250074496Ad5b7
USDT (TRX): TKigKeJPXZYyMVDgMyXxMf17MWYia92Rjd
Alternatively, sponsor me on Github using Github Sponsors.
Getting Started
The packge is available on Nuget. After installing the package the Bybit API is available by using the BybitRestClient
and BybitSocketClient
.
Installation
Add the package via dotnet, or add it via the package manager.
dotnet add package Bybit.Net
API Access
Bybit.Net can be configured using Dotnet dependency injection, after which the clients can be injected into your services. It also correctly configures logging and HttpClient usage.
builder.Services.AddBybit(options => {
// Options can be configured here, for example:
options.ApiCredentials = new ApiCredentials("APIKEY", "APISECRET");
});
The IBybitRestClient
and IBybitSocketClient
can then be injected.
Alternatively the rest and socket client can be constructed directly
var restClient = new BybitRestClient(options => {
// Options can be configured here, for example:
options.ApiCredentials = new ApiCredentials("APIKEY", "APISECRET");
});
var socketClient = new BybitSocketClient();
Examples
Spot API
Get SymbolsGet a list of supported spot symbols
var bybitClient = new BybitRestClient();
var result = await bybitClient.V5Api.ExchangeData.GetSpotSymbolsAsync();
Get Symbol TickerGet the 24h price ticker of a spot symbol
var bybitClient = new BybitRestClient();
var result = await bybitClient.V5Api.ExchangeData.GetSpotTickersAsync("ETHUSDT");
Get Recent TradesGet the most recent trades for a spot symbol
var bybitClient = new BybitRestClient();
var result = await bybitClient.V5Api.ExchangeData.GetTradeHistoryAsync(Bybit.Net.Enums.Category.Spot, "ETHUSDT");
Get BalancesGet asset balances of the spot account
var bybitClient = new BybitRestClient(options => {
options.ApiCredentials = new ApiCredentials("KEY", "SECRET");
});
// If the account type is Unified:
var result = await bybitClient.V5Api.Account.GetBalancesAsync(Bybit.Net.Enums.AccountType.Unified);
// Else
var result = await bybitClient.V5Api.Account.GetBalancesAsync(Bybit.Net.Enums.AccountType.Spot);
Place Limit OrderPlace a new limit order for buying 0.1 ETH at a price of 2000 USDT
var bybitClient = new BybitRestClient(options => {
options.ApiCredentials = new ApiCredentials("KEY", "SECRET");
});
var result = await bybitClient.V5Api.Trading.PlaceOrderAsync(
Bybit.Net.Enums.Category.Spot,
"ETHUSDT",
Bybit.Net.Enums.OrderSide.Buy,
Bybit.Net.Enums.NewOrderType.Limit,
0.1m,
2000);
Place Market OrderPlace a new market order for buying 50 USDT worth of ETH at the best available price
var result = await bybitClient.V5Api.Trading.PlaceOrderAsync(
Bybit.Net.Enums.Category.Spot,
"ETHUSDT",
Bybit.Net.Enums.OrderSide.Buy,
Bybit.Net.Enums.NewOrderType.Market,
50,
marketUnit: MarketUnit.QuoteAsset);
Get Order InfoRetrieve order information for a specific order
var bybitClient = new BybitRestClient(options => {
options.ApiCredentials = new ApiCredentials("KEY", "SECRET");
});
var result = await bybitClient.V5Api.Trading.GetOrdersAsync(Bybit.Net.Enums.Category.Spot, orderId: "123");
Cancel an orderCancel a currently active order
var bybitClient = new BybitRestClient(options => {
options.ApiCredentials = new ApiCredentials("KEY", "SECRET");
});
var result = await bybitClient.V5Api.Trading.CancelOrderAsync(Bybit.Net.Enums.Category.Spot, "ETHUSDT", "123");
Linear Futures API
Get SymbolsGet a list of supported linear futures symbols
var bybitClient = new BybitRestClient();
var result = await bybitClient.V5Api.ExchangeData.GetLinearInverseSymbolsAsync(Bybit.Net.Enums.Category.Linear);
Get Symbol TickerGet the 24h price ticker of a futures symbol
var bybitClient = new BybitRestClient();
var result = await bybitClient.V5Api.ExchangeData.GetLinearInverseTickersAsync(Bybit.Net.Enums.Category.Linear, "ETHUSDT");
Get Recent TradesGet the most recent trades for a futures symbol
var bybitClient = new BybitRestClient();
var result = await bybitClient.V5Api.ExchangeData.GetTradeHistoryAsync(Bybit.Net.Enums.Category.Linear, "ETHUSDT");
Get BalancesGet balance of the perpetual futures account
vvar bybitClient = new BybitRestClient(options => {
options.ApiCredentials = new ApiCredentials("KEY", "SECRET");
});
// If the account type is Unified:
var result = await bybitClient.V5Api.Account.GetBalancesAsync(Bybit.Net.Enums.AccountType.Unified);
// Else
var result = await bybitClient.V5Api.Account.GetBalancesAsync(Bybit.Net.Enums.AccountType.Contract);
Get PositionsGet open positions
var bybitClient = new BybitRestClient(options => {
options.ApiCredentials = new ApiCredentials("KEY", "SECRET");
});
var result = await bybitClient.V5Api.Trading.GetPositionsAsync(Bybit.Net.Enums.Category.Linear);
Place Limit OrderPlace a new limit order for going long on 0.1 ETH at a price of 2000 USDT
var bybitClient = new BybitRestClient(options => {
options.ApiCredentials = new ApiCredentials("KEY", "SECRET");
});
var result = await bybitClient.V5Api.Trading.PlaceOrderAsync(
Bybit.Net.Enums.Category.Linear,
"ETHUSDT",
Bybit.Net.Enums.OrderSide.Buy,
Bybit.Net.Enums.NewOrderType.Limit,
0.1m,
2000,
positionIdx: PositionIdx.OneWayMode
);