Skip to main content

Crate bybit_client

Crate bybit_client 

Source
Expand description

§Bybit Client

A Rust client library for the Bybit V5 API.

§Features

  • Full REST API V5 coverage.
  • WebSocket support for real-time data.
  • HMAC-SHA256 authentication.
  • Async/await support with tokio.
  • Strongly typed request/response structures.

§Quick Start

use bybit_client::{BybitClient, ClientConfig};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create a public-only client for public endpoints.
    let client = BybitClient::public_only()?;

    // Or create an authenticated client for private endpoints.
    let client = BybitClient::new("your_api_key", "your_api_secret")?;

    // Use testnet for testing.
    let client = BybitClient::with_config(
        ClientConfig::new("api_key", "api_secret").testnet()
    )?;

    Ok(())
}

§Configuration

The client supports various configuration options:

use bybit_client::{ClientConfig, Environment, ApiRegion};

let config = ClientConfig::new("api_key", "api_secret")
    .testnet()                    // Use testnet.
    .recv_window(10000)           // Set `recv_window` to 10 seconds.
    .debug(true)                  // Enable debug logging.
    .timeout_ms(30000);           // Set request timeout to 30 seconds.

Re-exports§

pub use client::BybitClient;
pub use client::BybitClientBuilder;
pub use config::ApiRegion;
pub use config::ClientConfig;
pub use config::Environment;
pub use error::ApiResponse;
pub use error::BybitError;
pub use error::ListResult;
pub use types::*;

Modules§

api
API endpoint implementations.
auth
Authentication and request signing for Bybit API.
client
Main Bybit client.
config
Configuration for the Bybit client.
error
Error types for the Bybit client library.
http
HTTP client module for REST API.
prelude
Prelude module for common imports.
types
Type definitions for the Bybit API.
ws
WebSocket client implementation.