Bybit.Exchange.Net is a library designed for .NET projects, tailored for seamless interaction with the Bybit crypto exchange API. With a structure closely aligned with Bybit's API documentation, it prioritizes simplicity, offering rich models, enums, and convenient logging for easy integration into .NET projects. Ideal for developers building crypto trading applications on the Bybit.
- Windows: .NET 8, .NET 9, .NET 10
The Features documentation provides an in-depth look at the functionalities and capabilities of our project. Understanding the available features.
-
Built with full compatibility for .NET 8, .NET 9, .NET 10 ensuring smooth execution on the latest .NET applications and projects.
-
Designed with a structure closest to Bybit's API documentation, ensuring consistency and ease of understanding during integration.
-
Focuses on providing models and enums that accurately reflect the key concepts from Bybit's API, simplifying the creation and handling of API requests.
-
The library is designed to simplify the process of interacting with the Bybit API, with logically organized methods and classes, saving developers time and effort during integration.
-
Effortlessly log API responses, including raw data from Bybit, to enhance tracking and facilitate effective debugging throughout the development and deployment phases of your application.
With flexibility, user-friendliness, and seamless integration into .NET projects, Bybit.Exchange.Net is a valuable resource for developers looking to build crypto trading applications on the Bybit exchange.
Explore the Release Notes to stay up-to-date with the latest changes, improvements, and bug fixes. We regularly update this section to provide transparency and highlight the evolution of the project.
Refer to the API Documentation for details on the current APIs supported by our project. If you have suggestions for new APIs, feel free to open a request.
using Bybit.Exchange.Net.Extensions;
using Bybit.Exchange.Net.Models.Common;
builder.Services.AddBybitExchange(new BybitRestOptions()
{
Credentials = new ByBitCredentials()
{
Key = "key",
Secret = "secret",
}
});@using Bybit.Exchange.Net.Library.Interface
@using Bybit.Exchange.Net.Models.V5.Account
@using static Bybit.Exchange.Net.Data.Enums
@inject IBybitRestClient client
protected override async Task OnInitializedAsync()
{
var response = await client.V5.Account.GetWalletBalanceAsync(new GetWalletBalanceRequest()
{
accountType = AccountType.UNIFIED,
});
}using Bybit.Exchange.Net.Library
using Bybit.Exchange.Net.Models.Common
using Bybit.Exchange.Net.Models.V5.Market
using static Bybit.Exchange.Net.Data.Enums
var client = new BybitRestClient(new BybitRestOptions()
{
Credentials = new ByBitCredentials(key, secret),
Environment = BybitEnvironment.Live
});
var response = await client.V5.Market.GetTickersAsync(new GetTickersRequest() {
category = Category.Spot
});using Bybit.Exchange.Net.Library;
using Bybit.Exchange.Net.Models.Common;
using Bybit.Exchange.Net.Models.V5.Trade;
using Bybit.Exchange.Net.Models.V5.WebSocket;
using static Bybit.Exchange.Net.Data.Enums;
var wsOptions = new BybitWebSocketOptions()
{
Credentials = new ByBitCredentials("key", "secret"),
Environment = BybitEnvironment.Testnet
};
var wsClient = new BybitWebSocketClient(wsOptions);
// 1. Setup Event Handlers
wsClient.OnOrderUpdate(msg => {
Console.WriteLine($"Order Update: {msg.Data.Count} orders received");
});
// 2. Connect to Private Stream (Order, Position, Wallet, Execution)
await wsClient.ConnectPrivateAsync();
await wsClient.AuthenticateAsync();
await wsClient.SubscribeAsync("order", "position");
// 3. Connect to Trade Stream (Place, Amend, Cancel Orders)
await wsClient.ConnectTradeAsync();
await wsClient.AuthenticateAsync();
var tradeResponse = await wsClient.CreateOrderAsync(new PlaceOrderRequest()
{
symbol = "BTCUSDT",
side = Side.Buy,
orderType = OrderType.Market,
qty = "0.01",
category = Category.Linear
});using Bybit.Exchange.Net.Library;
using Bybit.Exchange.Net.Models.Common;
using Bybit.Exchange.Net.Models.V5.WebSocket.Public;
using static Bybit.Exchange.Net.Data.Enums;
var wsClient = new BybitWebSocketClient(new BybitWebSocketOptions()
{
Environment = BybitEnvironment.Live
});
// Register handlers before connecting
wsClient.OnOrderbookUpdate(msg => {
Console.WriteLine($"[{msg.Type}] {msg.Topic} — Bids: {msg.Data.Bids?.Count}, Asks: {msg.Data.Asks?.Count}");
});
wsClient.OnTickerUpdate(msg => {
Console.WriteLine($"Ticker {msg.Data.Symbol}: Last={msg.Data.LastPrice}, 24h%={msg.Data.Price24hPcnt}");
});
wsClient.OnKlineUpdate(msg => {
foreach (var k in msg.Data)
Console.WriteLine($"Kline {k.Interval}: O={k.Open} H={k.High} L={k.Low} C={k.Close}");
});
wsClient.OnPublicTradeUpdate(msg => {
foreach (var t in msg.Data)
Console.WriteLine($"Trade {t.Symbol}: {t.Side} {t.Size}@{t.Price}");
});
wsClient.OnLiquidationUpdate(msg => {
foreach (var l in msg.Data)
Console.WriteLine($"Liquidation {l.Symbol}: {l.Side} {l.Size}@{l.Price}");
});
// Connect to Linear public channel
await wsClient.ConnectPublicAsync(PublicChannelType.Linear);
await wsClient.SubscribePublicAsync(PublicChannelType.Linear,
"orderbook.50.BTCUSDT",
"tickers.BTCUSDT",
"kline.1.BTCUSDT");
// Connect to Spot channel simultaneously (multi-connection)
await wsClient.ConnectPublicAsync(PublicChannelType.Spot);
await wsClient.SubscribePublicAsync(PublicChannelType.Spot,
"tickers.ETHUSDT",
"publicTrade.ETHUSDT");By default, every API request includes a User-Agent header set to Bybit.Exchange.Net/{version}. You can customize it via BybitRestOptions:
var client = new BybitRestClient(new BybitRestOptions()
{
UserAgent = "MyTradingBot/1.0"
});We welcome contributions to our project! Before getting started, please take a moment to read through the following guidelines:
- Clone "contributors" branch.
- Add some nice features.
- Create a Pull Request to "develop" branch.
If you have found a bug in our project, please open an issue on GitHub. When reporting a bug, please include as much detail as possible about the issue and steps to reproduce it.
By contributing to our project, you agree that your contributions will be licensed under the LICENSE