Skip to main content

General

Struct General 

Source
pub struct General {
    pub client: Client,
}

Fields§

§client: Client

Implementations§

Source§

impl General

The General struct provides general API functionality for the Bybit exchange.

This module includes methods for checking connectivity, retrieving server time, and getting system status information. These endpoints are essential for synchronizing trading operations with Bybit’s servers and monitoring platform health.

Source

pub async fn ping(&self) -> Result<bool, BybitError>

Tests connectivity to the Bybit API server.

This method sends a request to the server time endpoint to verify that the API is accessible and responsive. It’s useful for health checks and connection monitoring in trading applications.

§Returns

Returns Ok(true) if the server responds successfully, or Ok(false) if the server responds with an error. Returns Err(BybitError) for network or other critical failures.

§Examples
use bybit::prelude::*;

#[tokio::main]
async fn main() {
    let general = General::new(None, None);
    match general.ping().await {
        Ok(true) => println!("Connected to Bybit API"),
        Ok(false) => println!("Bybit API responded with an error"),
        Err(e) => println!("Connection failed: {:?}", e),
    }
}
Source

pub async fn get_server_time(&self) -> Result<ServerTimeResponse, BybitError>

Retrieves the current server time from Bybit with high precision.

This endpoint returns the server time in seconds and nanoseconds since the Unix epoch. Accurate server time is critical for synchronizing trading bot operations and avoiding timestamp-related errors in API requests.

§Returns

Returns a Result containing a ServerTimeResponse if successful, or a BybitError if an error occurs.

§Examples
use bybit::prelude::*;

#[tokio::main]
async fn main() {
    let general = General::new(None, None);
    match general.get_server_time().await {
        Ok(response) => {
            println!("Server time: {} seconds", response.result.time_second);
            println!("Nanosecond component: {}", response.result.time_nano);
        }
        Err(e) => println!("Failed to get server time: {:?}", e),
    }
}
Source

pub async fn get_server_datetime(&self) -> Result<DateTime<Utc>, BybitError>

Retrieves the server time as a chrono::DateTime<Utc> object.

This is a convenience method that converts the server time response into a more usable DateTime format for time calculations and comparisons.

§Returns

Returns a Result containing a DateTime<Utc> if successful, or a BybitError if an error occurs.

§Examples
use bybit::prelude::*;
use chrono::{DateTime, Utc};

#[tokio::main]
async fn main() {
    let general = General::new(None, None);
    match general.get_server_datetime().await {
        Ok(dt) => println!("Server datetime: {}", dt),
        Err(e) => println!("Failed to get server datetime: {:?}", e),
    }
}
Source

pub async fn get_server_time_millis(&self) -> Result<u64, BybitError>

Retrieves the server time in milliseconds since the Unix epoch.

This is a convenience method that returns the server time in milliseconds, which is commonly used for API request timestamps and performance measurements.

§Returns

Returns a Result containing milliseconds as u64 if successful, or a BybitError if an error occurs.

§Examples
use bybit::prelude::*;

#[tokio::main]
async fn main() {
    let general = General::new(None, None);
    match general.get_server_time_millis().await {
        Ok(ms) => println!("Server time in milliseconds: {}", ms),
        Err(e) => println!("Failed to get server time: {:?}", e),
    }
}
Source

pub async fn get_api_timestamp(&self) -> Result<String, BybitError>

Retrieves the current timestamp for API requests.

Bybit requires request timestamps to be within ±5 seconds of server time. This method returns the current server time in the format expected by Bybit API endpoints (milliseconds as string).

§Returns

Returns a Result containing the timestamp as a String if successful, or a BybitError if an error occurs.

§Examples
use bybit::prelude::*;

#[tokio::main]
async fn main() {
    let general = General::new(None, None);
    match general.get_api_timestamp().await {
        Ok(timestamp) => println!("API timestamp: {}", timestamp),
        Err(e) => println!("Failed to get API timestamp: {:?}", e),
    }
}
Source

pub async fn get_system_status( &self, id: Option<String>, state: Option<String>, ) -> Result<SystemStatusResponse, BybitError>

Retrieves the system status from the Bybit API.

This endpoint returns information about platform maintenance or service incidents. It’s useful for monitoring platform health and scheduling maintenance windows.

§Parameters
  • id - Optional unique identifier for filtering system status records
  • state - Optional system state for filtering (e.g., “completed”, “in_progress”, “scheduled”)
§Returns

Returns a Result containing a SystemStatusResponse if successful, or a BybitError if an error occurs.

§Examples
use bybit::prelude::*;

#[tokio::main]
async fn main() {
    let general = General::new(None, None);

    // Get all system status records
    match general.get_system_status(None, None).await {
        Ok(response) => println!("System status: {:?}", response),
        Err(e) => println!("Failed to get system status: {:?}", e),
    }

    // Get only completed incidents
    match general.get_system_status(None, Some("completed".to_string())).await {
        Ok(response) => println!("Completed incidents: {:?}", response),
        Err(e) => println!("Failed to get completed incidents: {:?}", e),
    }
}

Trait Implementations§

Source§

impl Bybit for General

Source§

fn new(api_key: Option<String>, secret_key: Option<String>) -> General

Creates a new instance of the module with default configuration. Read more
Source§

fn new_with_config( config: &Config, api_key: Option<String>, secret_key: Option<String>, ) -> General

Creates a new instance of the module with custom configuration. Read more
Source§

impl Clone for General

Source§

fn clone(&self) -> General

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more