bybit/
general.rs

1use crate::prelude::*;
2
3#[derive(Clone)]
4pub struct General {
5    pub client: Client,
6}
7
8/// The `General` struct represents general functionality for the Bybit API.
9impl General {
10    /// Tests for connectivity by sending a ping request to the Bybit server.
11    ///
12    /// # Returns
13    ///
14    /// Returns a `Result` containing a `String` with the response message if successful,
15
16    /// or a `BybitError` if an error occurs.
17    pub async fn ping(&self) -> Result<String, BybitError> {
18        // Call the get method on the client field of self, passing in the time variable and None as arguments, and return the result
19        let _response: ServerTimeResponse =
20            self.client.get(API::Market(Market::Time), None).await?;
21
22        // prints pong to the console
23        Ok("pong: Hi, this is bybit".to_string())
24    }
25
26    /// Retrieves the server time from the Bybit API.
27    ///
28    /// # Returns
29    ///
30    /// Returns a `Result` containing a `ServerTime` struct if successful,
31
32    /// or a `BybitError` if an error occurs.
33    pub async fn get_server_time(&self) -> Result<ServerTimeResponse, BybitError> {
34        // Create a variable called time and set it to an API::Market enum variant with a Market::Time value
35        // Call the get method on the client field of self, passing in the time variable and None as arguments, and return the result
36        let response: ServerTimeResponse = self.client.get(API::Market(Market::Time), None).await?;
37
38        // Return the ServerTime struct
39        Ok(response)
40    }
41}