patisson-bybit-sdk

Crates.iopatisson-bybit-sdk
lib.rspatisson-bybit-sdk
version0.1.9
created_at2025-05-17 13:55:17.844609+00
updated_at2025-12-31 11:11:35.620552+00
descriptionUnofficial Rust SDK for the Bybit exchange API
homepage
repositoryhttps://github.com/yurii-musolov/patisson-bybit-sdk
max_upload_size
id1677901
size345,685
Yurii Musolov (yurii-musolov)

documentation

https://docs.rs/crate/patisson-bybit-sdk

README

Bybit SDK

Crates.io Documentation MIT licensed

Unofficial Rust SDK for the Bybit exchange API.

Disclaimer

Stability & Versioning Policy

No stability or backward-compatibility guarantees are provided.

Every version change must be treated as a breaking change, including minor and patch releases.

Users are strongly advised to pin an exact version, for example:

patisson-bybit-sdk = "=0.1.9"

Maintenance Policy

This package is developed only in the author’s free time.

Releases are best-effort and not planned in advance.

The scope of the package is intentionally limited to the most commonly used functionality.

Features

  • REST API support
  • Websocket API support
  • Only async clients
  • All categories: Spot, Linear, Inverse, Option

Examples

Get tickers

use bybit::v5::{BASE_URL_API_MAINNET_1, Category, Client, GetTickersParams};

let cfg = ClientConfig {
    base_url: BASE_URL_API_MAINNET_1.to_string(),
    api_key: None,
    api_secret: None,
    recv_window: 5000, // Milliseconds.
    referer: None,
};
let client = Client::new(cfg);
let params = GetTickersParams {
    category: Category::Linear,
    symbol: Some(String::from("BTCUSDT")),
    base_coin: None, // If category=option, symbol or baseCoin must be passed.
    exp_date: None,
};
let response = client.get_tickers(params).await?;
println!("{response:#?}");

Subscribe to public channel 'ticker'

use bybit::v5::{
    BASE_URL_STREAM_MAINNET_1, DEFAULT_PING_INTERVAL, IncomingMessage, OutgoingMessage, Path,
    Topic, stream,
};

let url = format!("{}{}", BASE_URL_STREAM_MAINNET_1, Path::PublicLinear);
let symbol = String::from("BTCUSDT");
let topic = Topic::Ticker(symbol).to_string();
let message = OutgoingMessage::Subscribe {
    req_id: Some(String::from("req-0001")),
    args: vec![topic],
};

let (tx, mut rx, response) = stream(&url, DEFAULT_PING_INTERVAL).await?;
println!("{response:#?}");

tokio::spawn(async move {
    if let Err(err) = tx.send(message).await {
        eprintln!("{err}");
    }
});

while let Some(message) = rx.recv().await {
    println!("{message:#?}");
}

Subscribe to private channels

use Topic::{ExecutionAllCategory, OrderAllCategory, PositionAllCategory, Wallet};
use bybit::v5::{
    BASE_URL_STREAM_MAINNET_1, DEFAULT_PING_INTERVAL, OutgoingMessage, Path, SensitiveString,
    Topic, create_outgoing_message_auth, stream,
};

let api_key = SensitiveString::from("XXXXXXXX");
let api_secret = SensitiveString::from("XXXXXXXXXXXXXXXX");

let url = format!("{}{}", BASE_URL_STREAM_MAINNET_1, Path::Private);
let messages = vec![
    create_outgoing_message_auth(api_key, api_secret, Some(String::from("req-0001"))),
    OutgoingMessage::Subscribe {
        req_id: Some(String::from("req-0002")),
        args: vec![
            ExecutionAllCategory,
            OrderAllCategory,
            PositionAllCategory,
            Wallet,
        ],
    },
];

let (tx, mut rx, response) = stream(&url, DEFAULT_PING_INTERVAL).await?;
println!("{response:#?}");

tokio::spawn(async move {
    for message in messages {
        if let Err(err) = tx.send(message).await {
            eprintln!("{err}");
        }
    }
});

while let Some(message) = rx.recv().await {
    println!("{message:#?}");
}

License

This project is licensed under the MIT license.

Commit count: 38

cargo fmt