RestClient

Struct RestClient 

Source
pub struct RestClient { /* private fields */ }

Implementations§

Source§

impl RestClient

Source

pub fn new( api_key_pair: ApiKeyPair, base_url: String, debug: bool, ) -> RestClient

Examples found in repository?
examples/account_example.rs (line 16)
7async fn main() -> Result<(), Box<dyn std::error::Error>> {
8    let api_key = env::var("BYBIT_API_KEY").unwrap_or_else(|_| "YOUR_API_KEY".to_string());
9    let api_secret = env::var("BYBIT_API_SECRET").unwrap_or_else(|_| "YOUR_API_SECRET".to_string());
10    
11    // Using testnet by default
12    let base_url = "https://api-testnet.bybit.com".to_string(); 
13
14    // ApiKeyPair takes (profile_name, key, secret)
15    let key_pair = ApiKeyPair::new("account_demo".to_string(), api_key, api_secret);
16    let client = RestClient::new(key_pair, base_url, true);
17    
18    // AccountClient takes ownership of RestClient
19    let account_client = AccountClient::new(client);
20
21    println!("--- Testing get_wallet_balance ---");
22    let params = GetWalletBalanceParams {
23        account_type: AccountType::UNIFIED,
24        coin: None,
25    };
26    
27    match account_client.get_wallet_balance(params).await {
28        Ok(response) => println!("Success: {:?}", response),
29        Err(e) => println!("Error: {:?}", e),
30    }
31
32    println!("\n--- Testing get_fee_rate ---");
33    match account_client.get_fee_rate("spot", None, None).await {
34        Ok(response) => println!("Success: {:?}", response),
35        Err(e) => println!("Error: {:?}", e),
36    }
37
38    Ok(())
39}
Source

pub async fn get<A: DeserializeOwned>( &self, endpoint: &str, query: Value, sec_type: SecType, ) -> Result<A, Error>

Source

pub async fn post<A: DeserializeOwned>( &self, endpoint: &str, body: Value, sec_type: SecType, ) -> Result<A, Error>

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> 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<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