| Crates.io | patisson-bybit-sdk |
| lib.rs | patisson-bybit-sdk |
| version | 0.1.9 |
| created_at | 2025-05-17 13:55:17.844609+00 |
| updated_at | 2025-12-31 11:11:35.620552+00 |
| description | Unofficial Rust SDK for the Bybit exchange API |
| homepage | |
| repository | https://github.com/yurii-musolov/patisson-bybit-sdk |
| max_upload_size | |
| id | 1677901 |
| size | 345,685 |
Unofficial Rust SDK for the Bybit exchange API.
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"
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.
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:#?}");
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:#?}");
}
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:#?}");
}
This project is licensed under the MIT license.