pub struct BpxClient { /* private fields */ }Expand description
A client for interacting with the Backpack Exchange API.
Implementations§
Source§impl BpxClient
impl BpxClient
Sourcepub async fn get_account(&self) -> Result<AccountSettings>
pub async fn get_account(&self) -> Result<AccountSettings>
Fetches the account’s settings.
Sourcepub async fn get_account_max_borrow(
&self,
symbol: &str,
) -> Result<AccountMaxBorrow>
pub async fn get_account_max_borrow( &self, symbol: &str, ) -> Result<AccountMaxBorrow>
Fetches the account’s maximum borrow amount for a given symbol.
Sourcepub async fn get_account_max_withdrawal(
&self,
symbol: &str,
auto_borrow: Option<bool>,
auto_lend_redeem: Option<bool>,
) -> Result<AccountMaxWithdrawal>
pub async fn get_account_max_withdrawal( &self, symbol: &str, auto_borrow: Option<bool>, auto_lend_redeem: Option<bool>, ) -> Result<AccountMaxWithdrawal>
Fetches the account’s maximum withdrawal amount for a given symbol.
Sourcepub async fn update_account(&self, payload: UpdateAccountPayload) -> Result<()>
pub async fn update_account(&self, payload: UpdateAccountPayload) -> Result<()>
Updates the account’s settings.
Sourcepub async fn convert_dust_balance(
&self,
payload: ConvertDustPayload,
) -> Result<()>
pub async fn convert_dust_balance( &self, payload: ConvertDustPayload, ) -> Result<()>
Converts a dust balance to USDC. The balance (including lend) must be less than the minimum quantity tradable on the spot order book.
Source§impl BpxClient
impl BpxClient
Sourcepub async fn get_borrow_lend_positions(&self) -> Result<Vec<BorrowLendPosition>>
pub async fn get_borrow_lend_positions(&self) -> Result<Vec<BorrowLendPosition>>
Retrieves all the open borrow lending positions for the account.
Source§impl BpxClient
impl BpxClient
Sourcepub async fn get_balances(&self) -> Result<HashMap<String, Balance>>
pub async fn get_balances(&self) -> Result<HashMap<String, Balance>>
Fetches the account’s current balances.
Sourcepub async fn get_deposits(
&self,
limit: Option<i64>,
offset: Option<i64>,
) -> Result<Vec<Deposit>>
pub async fn get_deposits( &self, limit: Option<i64>, offset: Option<i64>, ) -> Result<Vec<Deposit>>
Retrieves a list of deposits with optional pagination.
Sourcepub async fn get_deposit_address(
&self,
blockchain: Blockchain,
) -> Result<DepositAddress>
pub async fn get_deposit_address( &self, blockchain: Blockchain, ) -> Result<DepositAddress>
Fetches the deposit address for a specified blockchain.
Sourcepub async fn get_withdrawals(
&self,
limit: Option<i64>,
offset: Option<i64>,
) -> Result<Vec<Withdrawal>>
pub async fn get_withdrawals( &self, limit: Option<i64>, offset: Option<i64>, ) -> Result<Vec<Withdrawal>>
Retrieves a list of withdrawals with optional pagination.
Sourcepub async fn request_withdrawal(
&self,
payload: RequestWithdrawalPayload,
) -> Result<Withdrawal>
pub async fn request_withdrawal( &self, payload: RequestWithdrawalPayload, ) -> Result<Withdrawal>
Submits a withdrawal request for the specified payload.
Sourcepub async fn get_collateral(&self) -> Result<Collateral>
pub async fn get_collateral(&self) -> Result<Collateral>
Fetches the subaccount’s collateral information.
Source§impl BpxClient
impl BpxClient
pub async fn get_open_future_positions(&self) -> Result<Vec<FuturePosition>>
Source§impl BpxClient
impl BpxClient
Sourcepub async fn get_historical_fills(
&self,
params: FillsHistoryParams,
) -> Result<Vec<Fill>>
pub async fn get_historical_fills( &self, params: FillsHistoryParams, ) -> Result<Vec<Fill>>
Fetches historical fills with optional filtering and pagination parameters.
Source§impl BpxClient
impl BpxClient
Sourcepub async fn get_assets(&self) -> Result<Vec<Asset>>
pub async fn get_assets(&self) -> Result<Vec<Asset>>
Fetches available assets and their associated tokens.
Sourcepub async fn get_markets(&self) -> Result<Vec<Market>>
pub async fn get_markets(&self) -> Result<Vec<Market>>
Retrieves a list of available markets.
Sourcepub async fn get_all_mark_prices(&self) -> Result<Vec<MarkPrice>>
pub async fn get_all_mark_prices(&self) -> Result<Vec<MarkPrice>>
Retrieves mark price, index price and the funding rate for the current interval for all symbols, or the symbol specified.
Sourcepub async fn get_ticker(&self, symbol: &str) -> Result<Ticker>
pub async fn get_ticker(&self, symbol: &str) -> Result<Ticker>
Fetches the ticker information for a given symbol.
Sourcepub async fn get_tickers(&self) -> Result<Vec<Ticker>>
pub async fn get_tickers(&self) -> Result<Vec<Ticker>>
Fetches the ticker information for all symbols.
Sourcepub async fn get_order_book_depth(&self, symbol: &str) -> Result<OrderBookDepth>
pub async fn get_order_book_depth(&self, symbol: &str) -> Result<OrderBookDepth>
Retrieves the order book depth for a given symbol.
Sourcepub async fn get_funding_interval_rates(
&self,
symbol: &str,
) -> Result<Vec<FundingRate>>
pub async fn get_funding_interval_rates( &self, symbol: &str, ) -> Result<Vec<FundingRate>>
Funding interval rate history for futures.
Source§impl BpxClient
impl BpxClient
Sourcepub async fn get_open_order(
&self,
symbol: &str,
order_id: Option<&str>,
client_id: Option<u32>,
) -> Result<Order>
pub async fn get_open_order( &self, symbol: &str, order_id: Option<&str>, client_id: Option<u32>, ) -> Result<Order>
Fetches a specific open order by symbol and either order ID or client ID.
Sourcepub async fn execute_order(&self, payload: ExecuteOrderPayload) -> Result<Order>
pub async fn execute_order(&self, payload: ExecuteOrderPayload) -> Result<Order>
Executes a new order with the given payload.
Sourcepub async fn cancel_order(
&self,
symbol: &str,
order_id: Option<&str>,
client_id: Option<u32>,
) -> Result<Order>
pub async fn cancel_order( &self, symbol: &str, order_id: Option<&str>, client_id: Option<u32>, ) -> Result<Order>
Cancels a specific order by symbol and either order ID or client ID.
Sourcepub async fn get_open_orders(&self, symbol: Option<&str>) -> Result<Vec<Order>>
pub async fn get_open_orders(&self, symbol: Option<&str>) -> Result<Vec<Order>>
Retrieves all open orders, optionally filtered by symbol.
Sourcepub async fn cancel_open_orders(
&self,
payload: CancelOpenOrdersPayload,
) -> Result<Vec<Order>>
pub async fn cancel_open_orders( &self, payload: CancelOpenOrdersPayload, ) -> Result<Vec<Order>>
Cancels all open orders matching the specified payload.
Source§impl BpxClient
impl BpxClient
pub async fn submit_rfq( &self, payload: RequestForQuotePayload, ) -> Result<RequestForQuote>
pub async fn submit_quote(&self, payload: QuotePayload) -> Result<Quote>
pub async fn subscribe_to_rfqs( &self, tx: Sender<RequestForQuoteUpdate>, ) -> Result<()>
Source§impl BpxClient
impl BpxClient
Source§impl BpxClient
impl BpxClient
Sourcepub async fn request_two_factor(
&self,
payload: RequestTwoFactorPayload,
) -> Result<RequestTwoFactorResponse>
pub async fn request_two_factor( &self, payload: RequestTwoFactorPayload, ) -> Result<RequestTwoFactorResponse>
Requests a two-factor authentication token.
Sends a request to initiate the two-factor authentication process with the provided payload and returns the response.
Source§impl BpxClient
impl BpxClient
Sourcepub async fn subscribe<T>(&self, stream: &str, tx: Sender<T>) -> Result<()>where
T: DeserializeOwned + Send + 'static,
pub async fn subscribe<T>(&self, stream: &str, tx: Sender<T>) -> Result<()>where
T: DeserializeOwned + Send + 'static,
Subscribes to a private WebSocket stream and sends messages of type T through a transmitter channel.
Sourcepub async fn subscribe_multiple<T>(
&self,
streams: &[&str],
tx: Sender<T>,
) -> Result<()>where
T: DeserializeOwned + Send + 'static,
pub async fn subscribe_multiple<T>(
&self,
streams: &[&str],
tx: Sender<T>,
) -> Result<()>where
T: DeserializeOwned + Send + 'static,
Subscribes to multiple private WebSocket streams and sends messages of type T through a transmitter channel.
Source§impl BpxClient
impl BpxClient
pub fn builder() -> BpxClientBuilder
Sourcepub fn init(
base_url: String,
secret: &str,
headers: Option<BpxHeaders>,
) -> Result<Self>
pub fn init( base_url: String, secret: &str, headers: Option<BpxHeaders>, ) -> Result<Self>
Initializes a new client with the given base URL, API secret, and optional headers.
This sets up the signing and verification keys, and creates a reqwest client
with default headers including the API key and content type.
Sourcepub fn init_with_ws(
base_url: String,
ws_url: String,
secret: &str,
headers: Option<BpxHeaders>,
) -> Result<Self>
👎Deprecated: Use BpxClient::builder() instead to configure the client with a custom websocket URL.
pub fn init_with_ws( base_url: String, ws_url: String, secret: &str, headers: Option<BpxHeaders>, ) -> Result<Self>
Initializes a new client with WebSocket support.
Sourcepub async fn get<U: IntoUrl>(&self, url: U) -> Result<Response>
pub async fn get<U: IntoUrl>(&self, url: U) -> Result<Response>
Sends a GET request to the specified URL and signs it before execution.
Sourcepub async fn post<P: Serialize, U: IntoUrl>(
&self,
url: U,
payload: P,
) -> Result<Response>
pub async fn post<P: Serialize, U: IntoUrl>( &self, url: U, payload: P, ) -> Result<Response>
Sends a POST request with a JSON payload to the specified URL and signs it.
Sourcepub async fn delete<P: Serialize, U: IntoUrl>(
&self,
url: U,
payload: P,
) -> Result<Response>
pub async fn delete<P: Serialize, U: IntoUrl>( &self, url: U, payload: P, ) -> Result<Response>
Sends a DELETE request with a JSON payload to the specified URL and signs it.
Sourcepub async fn patch<P: Serialize, U: IntoUrl>(
&self,
url: U,
payload: P,
) -> Result<Response>
pub async fn patch<P: Serialize, U: IntoUrl>( &self, url: U, payload: P, ) -> Result<Response>
Sends a PATCH request with a JSON payload to the specified URL and signs it.
Sourcepub const fn verifying_key(&self) -> Option<&VerifyingKey>
pub const fn verifying_key(&self) -> Option<&VerifyingKey>
Returns a reference to the VerifyingKey used for request verification.
Return will be Some if the client was initialised with a secret key, otherwise None.
Methods from Deref<Target = Client>§
Sourcepub fn get<U>(&self, url: U) -> RequestBuilderwhere
U: IntoUrl,
pub fn get<U>(&self, url: U) -> RequestBuilderwhere
U: IntoUrl,
Convenience method to make a GET request to a URL.
§Errors
This method fails whenever the supplied Url cannot be parsed.
Sourcepub fn post<U>(&self, url: U) -> RequestBuilderwhere
U: IntoUrl,
pub fn post<U>(&self, url: U) -> RequestBuilderwhere
U: IntoUrl,
Convenience method to make a POST request to a URL.
§Errors
This method fails whenever the supplied Url cannot be parsed.
Sourcepub fn put<U>(&self, url: U) -> RequestBuilderwhere
U: IntoUrl,
pub fn put<U>(&self, url: U) -> RequestBuilderwhere
U: IntoUrl,
Convenience method to make a PUT request to a URL.
§Errors
This method fails whenever the supplied Url cannot be parsed.
Sourcepub fn patch<U>(&self, url: U) -> RequestBuilderwhere
U: IntoUrl,
pub fn patch<U>(&self, url: U) -> RequestBuilderwhere
U: IntoUrl,
Convenience method to make a PATCH request to a URL.
§Errors
This method fails whenever the supplied Url cannot be parsed.
Sourcepub fn delete<U>(&self, url: U) -> RequestBuilderwhere
U: IntoUrl,
pub fn delete<U>(&self, url: U) -> RequestBuilderwhere
U: IntoUrl,
Convenience method to make a DELETE request to a URL.
§Errors
This method fails whenever the supplied Url cannot be parsed.
Sourcepub fn head<U>(&self, url: U) -> RequestBuilderwhere
U: IntoUrl,
pub fn head<U>(&self, url: U) -> RequestBuilderwhere
U: IntoUrl,
Convenience method to make a HEAD request to a URL.
§Errors
This method fails whenever the supplied Url cannot be parsed.
Sourcepub fn request<U>(&self, method: Method, url: U) -> RequestBuilderwhere
U: IntoUrl,
pub fn request<U>(&self, method: Method, url: U) -> RequestBuilderwhere
U: IntoUrl,
Start building a Request with the Method and Url.
Returns a RequestBuilder, which will allow setting headers and
the request body before sending.
§Errors
This method fails whenever the supplied Url cannot be parsed.
Sourcepub fn execute(
&self,
request: Request,
) -> impl Future<Output = Result<Response, Error>>
pub fn execute( &self, request: Request, ) -> impl Future<Output = Result<Response, Error>>
Executes a Request.
A Request can be built manually with Request::new() or obtained
from a RequestBuilder with RequestBuilder::build().
You should prefer to use the RequestBuilder and
RequestBuilder::send().
§Errors
This method fails if there was an error while sending request, redirect loop was detected or redirect limit was exhausted.