pub struct Client<'a> {
pub api_key: Cow<'a, str>,
pub secret_key: Cow<'a, str>,
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: Cow<'a, str>The API key for the Bybit account.
secret_key: Cow<'a, str>The 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<'a> Client<'_>
impl<'a> Client<'_>
sourcepub fn new(
api_key: Option<Cow<'_, str>>,
secret_key: Option<Cow<'_, str>>,
host: String,
) -> Self
pub fn new( api_key: Option<Cow<'_, str>>, secret_key: Option<Cow<'_, str>>, 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.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Client<'a>
impl<'a> !RefUnwindSafe for Client<'a>
impl<'a> Send for Client<'a>
impl<'a> Sync for Client<'a>
impl<'a> Unpin for Client<'a>
impl<'a> !UnwindSafe for Client<'a>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)