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