pub struct Client {
pub api_key: String,
pub secret_key: String,
pub host: String,
pub inner_client: Client,
}Expand description
The main client struct that wraps the reqwest client.
It stores the API key, secret key, and host to make requests to the Bybit API.
Fields§
§api_key: StringThe API key for the Bybit account.
secret_key: StringThe secret key for the Bybit account.
host: StringThe host to make requests to.
inner_client: ClientThe reqwest client that makes the HTTP requests.
Implementations§
Source§impl Client
impl Client
Sourcepub fn new(
api_key: Option<String>,
secret_key: Option<String>,
host: String,
) -> Self
pub fn new( api_key: Option<String>, secret_key: Option<String>, host: String, ) -> Self
Create a new instance of Client.
§Arguments
api_key- The API key for the Bybit account. It can beNoneif the client is not for authenticated requests.secret_key- The secret key for the Bybit account. It can beNoneif the client is not for authenticated requests.host- The host to make requests to.
§Returns
A new instance of Client.
Sourcepub async fn get<T: DeserializeOwned + Send + 'static>(
&self,
endpoint: API,
request: Option<String>,
) -> Result<T, BybitError>
pub async fn get<T: DeserializeOwned + Send + 'static>( &self, endpoint: API, request: Option<String>, ) -> Result<T, BybitError>
Sourcepub async fn get_signed<T: DeserializeOwned + Send + 'static>(
&self,
endpoint: API,
recv_window: u16,
request: Option<String>,
) -> Result<T, BybitError>
pub async fn get_signed<T: DeserializeOwned + Send + 'static>( &self, endpoint: API, recv_window: u16, request: Option<String>, ) -> Result<T, BybitError>
Makes a signed HTTP GET request to the specified endpoint.
§Arguments
endpoint- The endpoint to make the request to.recv_window- The receive window for the request in milliseconds.request- The query string to append to the URL.
§Returns
A Result containing the response deserialized to the specified type T.
Sourcepub async fn post<T: DeserializeOwned + Send + 'static>(
&self,
endpoint: API,
request: Option<String>,
) -> Result<T, BybitError>
pub async fn post<T: DeserializeOwned + Send + 'static>( &self, endpoint: API, request: Option<String>, ) -> Result<T, BybitError>
Sourcepub async fn post_signed<T: DeserializeOwned + Send + 'static>(
&self,
endpoint: API,
recv_window: u16,
raw_request_body: Option<String>,
) -> Result<T, BybitError>
pub async fn post_signed<T: DeserializeOwned + Send + 'static>( &self, endpoint: API, recv_window: u16, raw_request_body: Option<String>, ) -> Result<T, BybitError>
Makes a signed HTTP POST request to the specified endpoint.
§Arguments
endpoint- The endpoint to make the request to.recv_window- The receive window for the request in milliseconds.raw_request_body- The raw request body to sign. Only used if provided.
§Returns
A Result containing the response deserialized to the specified type T.
Sourcepub async fn wss_connect(
&self,
endpoint: WebsocketAPI,
request_body: Option<String>,
private: bool,
alive_dur: Option<u16>,
) -> Result<WebSocketStream<MaybeTlsStream<TcpStream>>, BybitError>
pub async fn wss_connect( &self, endpoint: WebsocketAPI, request_body: Option<String>, private: bool, alive_dur: Option<u16>, ) -> Result<WebSocketStream<MaybeTlsStream<TcpStream>>, BybitError>
Connects to the Bybit WebSocket endpoint and sends an authentication message.
§Arguments
endpoint- The WebSocket endpoint to connect to.request_body- An optional request body to send after authenticating.private- A boolean indicating whether to send the authentication message.alive_dur- An optional duration in seconds to set thealivefield of the authentication message to.
§Returns
Returns a Result containing a WebSocketStream if the connection and authentication
are successful, or a BybitError if an error occurs.