Skip to main content

BpxClient

Struct BpxClient 

Source
pub struct BpxClient { /* private fields */ }
Expand description

A client for interacting with the Backpack Exchange API.

Implementations§

Source§

impl BpxClient

Source

pub async fn get_account(&self) -> Result<AccountSettings>

Fetches the account’s settings.

Source

pub async fn get_account_max_borrow( &self, symbol: &str, ) -> Result<AccountMaxBorrow>

Fetches the account’s maximum borrow amount for a given symbol.

Source

pub async fn get_account_max_order( &self, params: MaxOrderQuery, ) -> Result<AccountMaxOrder>

Fetches the account’s maximum order amount for a given symbol.

Source

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.

Source

pub async fn update_account(&self, payload: UpdateAccountPayload) -> Result<()>

Updates the account’s settings.

Source

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

Source

pub async fn get_borrow_lend_positions(&self) -> Result<Vec<BorrowLendPosition>>

Retrieves all the open borrow lending positions for the account.

Source§

impl BpxClient

Source

pub async fn get_balances(&self) -> Result<HashMap<String, Balance>>

Fetches the account’s current balances.

Source

pub async fn get_deposits( &self, limit: Option<i64>, offset: Option<i64>, ) -> Result<Vec<Deposit>>

Retrieves a list of deposits with optional pagination.

Source

pub async fn get_deposit_address( &self, blockchain: Blockchain, ) -> Result<DepositAddress>

Fetches the deposit address for a specified blockchain.

Source

pub async fn get_withdrawals( &self, limit: Option<i64>, offset: Option<i64>, ) -> Result<Vec<Withdrawal>>

Retrieves a list of withdrawals with optional pagination.

Source

pub async fn request_withdrawal( &self, payload: RequestWithdrawalPayload, ) -> Result<Withdrawal>

Submits a withdrawal request for the specified payload.

Source

pub async fn get_collateral(&self) -> Result<Collateral>

Fetches the subaccount’s collateral information.

Source§

impl BpxClient

Source§

impl BpxClient

Source

pub async fn get_historical_fills( &self, params: FillsHistoryParams, ) -> Result<Vec<Fill>>

Fetches historical fills with optional filtering and pagination parameters.

Source§

impl BpxClient

Source

pub async fn get_assets(&self) -> Result<Vec<Asset>>

Fetches available assets and their associated tokens.

Source

pub async fn get_markets(&self) -> Result<Vec<Market>>

Retrieves a list of available markets.

Source

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.

Source

pub async fn get_ticker(&self, symbol: &str) -> Result<Ticker>

Fetches the ticker information for a given symbol.

Source

pub async fn get_tickers(&self) -> Result<Vec<Ticker>>

Fetches the ticker information for all symbols.

Source

pub async fn get_order_book_depth( &self, symbol: &str, limit: Option<OrderBookDepthLimit>, ) -> Result<OrderBookDepth>

Retrieves the order book depth for a given symbol.

Source

pub async fn get_funding_interval_rates( &self, symbol: &str, ) -> Result<Vec<FundingRate>>

Funding interval rate history for futures.

Source

pub async fn get_k_lines( &self, symbol: &str, kline_interval: &str, start_time: i64, end_time: Option<i64>, ) -> Result<Vec<Kline>>

Fetches historical K-line (candlestick) data for a given symbol and interval.

Source§

impl BpxClient

Source

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.

Source

pub async fn execute_order(&self, payload: ExecuteOrderPayload) -> Result<Order>

Executes a new order with the given payload.

Source

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.

Source

pub async fn get_open_orders(&self, symbol: Option<&str>) -> Result<Vec<Order>>

Retrieves all open orders, optionally filtered by symbol.

Source

pub async fn execute_orders( &self, payload: Vec<ExecuteOrderPayload>, ) -> Result<Vec<BatchOrderResponse>>

Executes a new order with the given payload.

Source

pub async fn cancel_open_orders( &self, payload: CancelOpenOrdersPayload, ) -> Result<Vec<Order>>

Cancels all open orders matching the specified payload.

Source§

impl BpxClient

Source

pub async fn submit_rfq( &self, payload: RequestForQuotePayload, ) -> Result<RequestForQuote>

Source

pub async fn cancel_rfq( &self, payload: RequestForQuoteCancelPayload, ) -> Result<RequestForQuote>

Source

pub async fn refresh_rfq( &self, payload: RequestForQuoteRefreshPayload, ) -> Result<RequestForQuote>

Source

pub async fn accept_quote( &self, payload: QuoteAcceptPayload, ) -> Result<RequestForQuote>

Source

pub async fn submit_quote(&self, payload: QuotePayload) -> Result<Quote>

Source

pub async fn subscribe_to_rfqs( &self, tx: Sender<RequestForQuoteUpdate>, ) -> Result<()>

Source§

impl BpxClient

Source

pub async fn get_recent_trades( &self, symbol: &str, limit: Option<i16>, ) -> Result<Vec<Trade>>

Fetches the most recent trades for a given symbol, with an optional limit.

Source

pub async fn get_historical_trades( &self, symbol: &str, limit: Option<i64>, offset: Option<i64>, ) -> Result<Vec<Trade>>

Fetches historical trades for a given symbol, with optional limit and offset.

Source§

impl BpxClient

Source

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

Source

pub async fn get_vaults(&self) -> Result<Vec<Vault>>

Fetches information about all available vaults on the exchange.

Source

pub async fn vault_mint(&self, request: VaultMintRequest) -> Result<()>

Mints vault tokens by depositing an asset into a vault.

Source

pub async fn vault_redeem(&self, request: VaultRedeemRequest) -> Result<()>

Submits a request to redeem vault tokens for USDC.

Source

pub async fn vault_redeem_cancel( &self, request: VaultRedeemCancelRequest, ) -> Result<()>

Cancels a pending redeem request for a vault.

Source

pub async fn get_vault_pending_redeems( &self, vault_id: u32, ) -> Result<Vec<VaultRedeem>>

Fetches pending redeem requests for a vault.

Source

pub async fn get_vault_history( &self, params: VaultHistoryParams, ) -> Result<Vec<VaultHistory>>

Fetches historical vault data (NAV, equity, circulating supply).

Source§

impl BpxClient

Source

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.

Source

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

Source

pub fn builder() -> BpxClientBuilder

Source

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.

Source

pub 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.

Initializes a new client with WebSocket support.

Source

pub async fn get<U: IntoUrl>(&self, url: U) -> Result<Response>

Sends a GET request to the specified URL and signs it before execution.

Source

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.

Source

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.

Source

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.

Source

pub async fn execute(&self, request: Request) -> Result<Response>

Source

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.

Source

pub const fn client(&self) -> &Client

Returns a reference to the underlying HTTP client.

Source

pub fn base_url(&self) -> &Url

Source§

impl BpxClient

Source

pub fn build_signed_request<P: Serialize, U: IntoUrl>( &self, url: U, method: Method, instruction: &str, payload: Option<&P>, ) -> Result<Request>

Builds an authenticated request with signing headers.

Use this to create signed requests for custom endpoints. The instruction must match the Backpack API’s expected instruction string for the endpoint.

Methods from Deref<Target = Client>§

Source

pub fn get<U>(&self, url: U) -> RequestBuilder
where U: IntoUrl,

Convenience method to make a GET request to a URL.

§Errors

This method fails whenever the supplied Url cannot be parsed.

Source

pub fn post<U>(&self, url: U) -> RequestBuilder
where U: IntoUrl,

Convenience method to make a POST request to a URL.

§Errors

This method fails whenever the supplied Url cannot be parsed.

Source

pub fn put<U>(&self, url: U) -> RequestBuilder
where U: IntoUrl,

Convenience method to make a PUT request to a URL.

§Errors

This method fails whenever the supplied Url cannot be parsed.

Source

pub fn patch<U>(&self, url: U) -> RequestBuilder
where U: IntoUrl,

Convenience method to make a PATCH request to a URL.

§Errors

This method fails whenever the supplied Url cannot be parsed.

Source

pub fn delete<U>(&self, url: U) -> RequestBuilder
where U: IntoUrl,

Convenience method to make a DELETE request to a URL.

§Errors

This method fails whenever the supplied Url cannot be parsed.

Source

pub fn head<U>(&self, url: U) -> RequestBuilder
where U: IntoUrl,

Convenience method to make a HEAD request to a URL.

§Errors

This method fails whenever the supplied Url cannot be parsed.

Source

pub fn request<U>(&self, method: Method, url: U) -> RequestBuilder
where 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.

Source

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.

Trait Implementations§

Source§

impl AsRef<Client> for BpxClient

Source§

fn as_ref(&self) -> &Client

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for BpxClient

Source§

fn clone(&self) -> BpxClient

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BpxClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for BpxClient

Source§

type Target = Client

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for BpxClient

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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