Skip to content

Latest commit

 

History

121 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

logo

Bybit.Exchange.Net

NuGet Version (Bybit.Exchange.Net) NuGet Download (Bybit.Exchange.Net) Azure DevOps Releases

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.

Prerequisites

  • Windows: .NET 8, .NET 9, .NET 10

Installation and sources

Features

The Features documentation provides an in-depth look at the functionalities and capabilities of our project. Understanding the available features.

Key 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.

Release Notes

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.

API Support

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.

Quick Setup

Program.cs

using Bybit.Exchange.Net.Extensions;
using Bybit.Exchange.Net.Models.Common;

builder.Services.AddBybitExchange(new BybitRestOptions()
{
    Credentials = new ByBitCredentials()
    {
        Key = "key",
        Secret = "secret",
    }
});

Blazor Pages

@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,
    });
}

Others

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 
});

WebSocket Integration

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 
});

WebSocket Public Streams

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");

User-Agent Configuration

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"
});

Contributing Guide

We welcome contributions to our project! Before getting started, please take a moment to read through the following guidelines:

Submitting Changes

  1. Clone "contributors" branch.
  2. Add some nice features.
  3. Create a Pull Request to "develop" branch.

Reporting Bugs

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.

License

By contributing to our project, you agree that your contributions will be licensed under the LICENSE

About

A library designed for .NET projects, tailored for seamless interaction with the Bybit's 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.

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages