Skip to main content

Client

Struct Client 

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

The main trading API client for REST operations.

Provides methods for building, signing, and submitting transactions, as well as access to all generated API methods via Deref.

§WebSocket Support

For real-time market data and WebSocket order submission, use WsClient separately. See the ws module documentation for details.

§Example

use bullet_rust_sdk::{Network, Client};

// Connect to REST API
let api = Client::mainnet().await?;

// Query via REST
let info = api.exchange_info().await?;

Implementations§

Source§

impl Client

Source

pub async fn update_schema(&self) -> SDKResult<()>

Source

pub async fn mainnet() -> SDKResult<Self>

Connect to the mainnet environment.

§Example
use bullet_rust_sdk::Client;

let api = Client::mainnet().await?;
let info = api.exchange_info().await?;
Source

pub fn client(&self) -> &GeneratedClient

Get a reference to the underlying generated client.

Prefer using Deref (calling methods directly on Client) instead of this method.

Source

pub fn chain_id(&self) -> u64

Get the chain ID for this network.

Source

pub fn chain_hash(&self) -> [u8; 32]

Get the current chain hash.

Source

pub fn user_actions(&self) -> &Option<Vec<UserActionDiscriminants>>

Source

pub fn url(&self) -> &str

The REST API URL.

Source

pub fn ws_url(&self) -> &str

The websocket URL.

Source

pub fn keypair(&self) -> Option<&Keypair>

Get the default keypair for signing transactions.

Source

pub fn max_fee(&self) -> Amount

Get the default max fee for transactions.

Source

pub fn max_priority_fee_bips(&self) -> PriorityFeeBips

Get the default max priority fee in basis points.

Source

pub fn gas_limit(&self) -> Option<Gas>

Get the default gas limit for transactions.

Source

pub fn market_id(&self, symbol: &str) -> Option<MarketId>

Resolve a symbol string to its MarketId.

Returns None if the symbol is not found in the cached metadata.

§Example
let market_id = client.market_id("BTC-USD").expect("unknown symbol");
client.place_orders(market_id, orders, false, None).await?;
Source

pub fn symbols(&self) -> &[SymbolInfo]

Get all available symbols and their metadata.

Source

pub fn symbol_info(&self, market_id: MarketId) -> Option<&SymbolInfo>

Look up symbol info by MarketId.

Source

pub fn symbol_info_by_name(&self, symbol: &str) -> Option<&SymbolInfo>

Look up symbol info by name.

Source

pub async fn refresh_metadata(&mut self) -> SDKResult<()>

Re-fetch exchange metadata from the server.

Call this in long-running bots to pick up newly listed markets.

Source

pub fn builder() -> ClientBuilder

Create a new Client connected to a network.

Source§

impl Client

Source

pub async fn place_orders( &self, market_id: MarketId, orders: Vec<NewOrderArgs>, replace: bool, sub_account_index: Option<u8>, ) -> SDKResult<SubmitTxResponse>

Place orders on a market. Signs and submits the transaction.

§Arguments
  • market_id — Numeric market ID (resolve via client.market_id("BTC-USD"))
  • orders — One or more orders to place
  • replace — If true, cancel existing orders before placing new ones
  • sub_account_indexNone for the main account, Some(n) for a sub-account
§Example
use bullet_rust_sdk::*;

let market_id = client.market_id("BTC-USD").unwrap();
let price = PositiveDecimal::try_from(rust_decimal::Decimal::from(50000))?;
let size = PositiveDecimal::try_from(rust_decimal::Decimal::new(1, 3))?;
let resp = client.place_orders(
    market_id,
    vec![NewOrderArgs::limit(price, size, Side::Bid)],
    false,
    None,
).await?;
println!("TX: {}, status: {:?}", resp.id, resp.status);
Source

pub async fn cancel_orders( &self, market_id: MarketId, orders: Vec<CancelOrderArgs>, sub_account_index: Option<u8>, ) -> SDKResult<SubmitTxResponse>

Cancel specific orders on a market. Signs and submits the transaction.

Cancel by exchange-assigned OrderId, client-assigned ClientOrderId, or both.

§Example
use bullet_rust_sdk::*;

let resp = client.cancel_orders(
    MarketId(0),
    vec![CancelOrderArgs {
        order_id: Some(OrderId(12345)),
        client_order_id: None,
    }],
    None,
).await?;
Source

pub async fn cancel_market_orders( &self, market_id: MarketId, sub_account_index: Option<u8>, ) -> SDKResult<SubmitTxResponse>

Cancel all orders on a specific market. Signs and submits the transaction.

§Example
let resp = client.cancel_market_orders(MarketId(0), None).await?;
Source

pub async fn cancel_all_orders( &self, sub_account_index: Option<u8>, ) -> SDKResult<SubmitTxResponse>

Cancel all orders across all markets. Signs and submits the transaction.

§Example
let resp = client.cancel_all_orders(None).await?;
Source

pub fn address(&self) -> SDKResult<String>

Get the base58 address derived from the client’s keypair.

Returns Err(SDKError::MissingKeypair) if no keypair is configured.

§Example
let address = client.address()?;
println!("My address: {address}"); // e.g. "5Hq3...xyz"
Source

pub async fn my_open_orders(&self, symbol: &str) -> SDKResult<Vec<BinanceOrder>>

Query open orders for the client’s own account on a symbol.

Convenience wrapper around query_open_orders that derives the address from the client’s keypair.

§Example
let orders = client.my_open_orders("BTC-USD").await?;
for o in &orders {
    println!("{}: {} {} @ {}", o.order_id, o.side, o.orig_qty, o.price);
}
Source

pub async fn my_account(&self) -> SDKResult<Account>

Query account info (positions, margins) for the client’s own account.

Convenience wrapper around account_info that derives the address from the client’s keypair and unwraps the response.

Source

pub async fn my_balances(&self) -> SDKResult<Vec<Balance>>

Query balances for the client’s own account.

Convenience wrapper around account_balance that derives the address from the client’s keypair and unwraps the response.

Source

pub async fn amend_orders( &self, market_id: MarketId, orders: Vec<AmendOrderArgs>, sub_account_index: Option<u8>, ) -> SDKResult<SubmitTxResponse>

Amend (cancel + replace) existing orders. Signs and submits the transaction.

Each AmendOrderArgs pairs a CancelOrderArgs with a NewOrderArgs, atomically replacing the cancelled order with a new one.

§Example
use bullet_rust_sdk::*;

let resp = client.amend_orders(
    market_id,
    vec![AmendOrderArgs {
        cancel: CancelOrderArgs {
            order_id: Some(OrderId(12345)),
            client_order_id: None,
        },
        place: NewOrderArgs::limit(new_price, new_size, Side::Bid),
    }],
    None,
).await?;
Source§

impl Client

Source

pub async fn send_transaction( &self, signed: &SignedTransaction, ) -> SDKResult<SubmitTxResponse>

Send a signed transaction to the network.

Returns the response from the sequencer.

Source§

impl Client

Source

pub fn connect_ws<'f1>(&'f1 self) -> ClientConnectWsBuilder<'f1>

Open a raw WebSocket connection.

For production bots, prefer connect_ws_managed which handles reconnection automatically.

Source§

impl Client

Convenience wrapper on Client that forwards to ManagedWebsocket::connect.

Kept as a thin helper so the common case (client.connect_ws_managed()) is discoverable; the real dependency still flows managed → client.

Methods from Deref<Target = GeneratedClient>§

Source

pub async fn account_config<'a>( &'a self, address: &'a str, ) -> Result<ResponseValue<ByteStream>, Error<ApiErrorResponse>>

Futures Account Configuration

Sends a GET request to /fapi/v1/accountConfig

Source

pub async fn all_orders<'a>( &'a self, address: Option<&'a str>, end_time: Option<i64>, limit: Option<u64>, order_id: Option<i64>, start_time: Option<i64>, symbol: Option<&'a str>, ) -> Result<ResponseValue<PaginatedResponseHistoricalOrder>, Error<ApiErrorResponse>>

All Orders (order history from ClickHouse)

Sends a GET request to /fapi/v1/allOrders

Arguments:

  • address: Account address (required on first request, encoded in cursor for subsequent)
  • end_time: End time in microseconds
  • limit: Number of results (default 500, max 1000)
  • order_id: Return orders with orderId >= this value
  • start_time: Start time in microseconds
  • symbol: Trading pair symbol (optional filter)
Source

pub async fn borrow_lend_pools<'a>( &'a self, symbol: Option<&'a str>, ) -> Result<ResponseValue<Vec<BorrowLendPoolResponse>>, Error<ApiErrorResponse>>

Borrow Lend Pools - Doesnt exist in Binance

Sends a GET request to /fapi/v1/borrowLendPools

Arguments:

  • symbol: Symbol
Source

pub async fn commission_rate<'a>( &'a self, address: &'a str, symbol: &'a str, ) -> Result<ResponseValue<()>, Error<ApiErrorResponse>>

User Commission Rate (USER_DATA)

Sends a GET request to /fapi/v1/commissionRate

Source

pub async fn order_book<'a>( &'a self, limit: Option<i32>, symbol: &'a str, ) -> Result<ResponseValue<OrderBook>, Error<ApiErrorResponse>>

Get orderbook

Sends a GET request to /fapi/v1/depth

Arguments:

  • limit: Limit (default 20, max 1000)
  • symbol: Symbol
Source

pub async fn exchange_info<'a>( &'a self, ) -> Result<ResponseValue<ExchangeInfo>, Error<ApiErrorResponse>>

Get current exchange trading rules and symbol information

Sends a GET request to /fapi/v1/exchangeInfo

Source

pub async fn funding_rate<'a>( &'a self, symbol: Option<&'a str>, ) -> Result<ResponseValue<FundingRate>, Error<ApiErrorResponse>>

Latest price for a symbol or symbols

Sends a GET request to /fapi/v1/fundingRate

Arguments:

  • symbol: Symbol
Source

pub async fn insurance_balance<'a>( &'a self, ) -> Result<ResponseValue<Vec<InsuranceBalance>>, Error<ApiErrorResponse>>

Query Insurance Fund Balance Snapshot

Sends a GET request to /fapi/v1/insuranceBalance

Source

pub async fn leverage_bracket<'a>( &'a self, symbol: Option<&'a str>, ) -> Result<ResponseValue<Vec<LeverageBracket>>, Error<ApiErrorResponse>>

Notional and Leverage Brackets (USER_DATA)

Sends a GET request to /fapi/v1/leverageBracket

Source

pub async fn open_interest<'a>( &'a self, ) -> Result<ResponseValue<Vec<OpenInterest>>, Error<ApiErrorResponse>>

Open interest per market

Sends a GET request to /fapi/v1/openInterest

Source

pub async fn query_open_order<'a>( &'a self, address: &'a str, client_order_id: Option<i64>, order_id: Option<i64>, symbol: &'a str, ) -> Result<ResponseValue<BinanceOrder>, Error<ApiErrorResponse>>

Query Current Open Order

Sends a GET request to /fapi/v1/openOrder

Source

pub async fn query_open_orders<'a>( &'a self, address: &'a str, symbol: &'a str, ) -> Result<ResponseValue<Vec<BinanceOrder>>, Error<ApiErrorResponse>>

Query All Open Orders

Sends a GET request to /fapi/v1/openOrders

Arguments:

  • address: Account address
  • symbol: Trading pair symbol
Source

pub async fn ping<'a>( &'a self, ) -> Result<ResponseValue<PingResponse>, Error<ApiErrorResponse>>

Test connectivity to the Rest API

Sends a GET request to /fapi/v1/ping

Source

pub async fn rate_limit_order<'a>( &'a self, ) -> Result<ResponseValue<ByteStream>, Error<ApiErrorResponse>>

Query User Rate Limit (USER_DATA)

Sends a GET request to /fapi/v1/rateLimit/order

Source

pub async fn symbol_config<'a>( &'a self, address: &'a str, symbol: Option<&'a str>, ) -> Result<ResponseValue<()>, Error<ApiErrorResponse>>

Symbol Configuration (USER_DATA)

Sends a GET request to /fapi/v1/symbolConfig

Source

pub async fn ticker_24hr<'a>( &'a self, ) -> Result<ResponseValue<Vec<Ticker24hr>>, Error<ApiErrorResponse>>

24 hour rolling window price change statistics. returns all markets — no per-symbol filtering (intentional, dataset is small)

Sends a GET request to /fapi/v1/ticker/24hr

Source

pub async fn ticker_price<'a>( &'a self, symbol: Option<&'a str>, ) -> Result<ResponseValue<Vec<PriceTicker>>, Error<ApiErrorResponse>>

Latest price for a symbol or symbols

Sends a GET request to /fapi/v1/ticker/price

Arguments:

  • symbol: Symbol
Source

pub async fn time<'a>( &'a self, ) -> Result<ResponseValue<TimeResponse>, Error<ApiErrorResponse>>

Test connectivity to the Rest API and get the current server time

Sends a GET request to /fapi/v1/time

Source

pub async fn recent_trades<'a>( &'a self, limit: Option<i32>, symbol: &'a str, ) -> Result<ResponseValue<Vec<Trade>>, Error<ApiErrorResponse>>

Recent Trades List

Sends a GET request to /fapi/v1/trades

Arguments:

  • limit: Default 100; max 1000
  • symbol: Symbol
Source

pub async fn user_deposits<'a>( &'a self, address: Option<&'a str>, end_time: Option<i64>, limit: Option<u64>, start_time: Option<i64>, ) -> Result<ResponseValue<PaginatedResponseUserDeposit>, Error<ApiErrorResponse>>

User Deposit History

Sends a GET request to /fapi/v1/userDeposits

Arguments:

  • address: Account address (required on first request, encoded in cursor for subsequent)
  • end_time: End time in microseconds
  • limit: Number of results (default 500, max 1000)
  • start_time: Start time in microseconds
Source

pub async fn user_funding_payments<'a>( &'a self, address: Option<&'a str>, end_time: Option<i64>, limit: Option<u64>, start_time: Option<i64>, symbol: Option<&'a str>, ) -> Result<ResponseValue<PaginatedResponseUserFundingPayment>, Error<ApiErrorResponse>>

User Funding Payment History

Sends a GET request to /fapi/v1/userFundingPayments

Arguments:

  • address: Account address (required on first request, encoded in cursor for subsequent)
  • end_time: End time in microseconds (optional filter)
  • limit: Number of results (default 500, max 1000)
  • start_time: Start time in microseconds (optional filter)
  • symbol: Trading pair symbol (optional filter)
Source

pub async fn user_liquidations<'a>( &'a self, address: Option<&'a str>, end_time: Option<i64>, limit: Option<u64>, start_time: Option<i64>, symbol: Option<&'a str>, ) -> Result<ResponseValue<PaginatedResponseUserLiquidation>, Error<ApiErrorResponse>>

User Liquidation History

Sends a GET request to /fapi/v1/userLiquidations

Arguments:

  • address: Account address (required on first request, encoded in cursor for subsequent)
  • end_time: End time in microseconds (optional filter)
  • limit: Number of results (default 500, max 1000)
  • start_time: Start time in microseconds (optional filter)
  • symbol: Trading pair symbol (optional filter)
Source

pub async fn user_trades<'a>( &'a self, address: Option<&'a str>, end_time: Option<i64>, limit: Option<u64>, start_time: Option<i64>, symbol: Option<&'a str>, ) -> Result<ResponseValue<PaginatedResponseUserTrade>, Error<ApiErrorResponse>>

Account Trade List

Sends a GET request to /fapi/v1/userTrades

Arguments:

  • address: Account address (required on first request, encoded in cursor for subsequent)
  • end_time: End time in microseconds (optional filter)
  • limit: Number of results (default 500, max 1000)
  • start_time: Start time in microseconds (optional filter)
  • symbol: Trading pair symbol (optional filter)
Source

pub async fn user_withdrawals<'a>( &'a self, address: Option<&'a str>, end_time: Option<i64>, limit: Option<u64>, start_time: Option<i64>, ) -> Result<ResponseValue<PaginatedResponseUserWithdrawal>, Error<ApiErrorResponse>>

User Withdrawal History

Sends a GET request to /fapi/v1/userWithdrawals

Arguments:

  • address: Account address (required on first request, encoded in cursor for subsequent)
  • end_time: End time in microseconds
  • limit: Number of results (default 500, max 1000)
  • start_time: Start time in microseconds
Source

pub async fn account_info<'a>( &'a self, address: &'a str, ) -> Result<ResponseValue<Account>, Error<ApiErrorResponse>>

Get current account information

Sends a GET request to /fapi/v3/account

Source

pub async fn account_balance<'a>( &'a self, address: &'a str, ) -> Result<ResponseValue<Vec<Balance>>, Error<ApiErrorResponse>>

Get account balance

Sends a GET request to /fapi/v3/balance

Source

pub async fn health<'a>( &'a self, ) -> Result<ResponseValue<ByteStream>, Error<ApiErrorResponse>>

Get health of the API

Sends a GET request to /health

Source

pub async fn ready<'a>( &'a self, ) -> Result<ResponseValue<ReadinessStatus>, Error<ApiErrorResponse>>

readiness probe — 200 when all components healthy, 503 otherwise

Sends a GET request to /health/ready

Source

pub async fn constants<'a>( &'a self, ) -> Result<ResponseValue<RollupConstants>, Error<ApiErrorResponse>>

Get the rollup constants

Sends a GET request to /rollup/constants

Source

pub async fn schema<'a>( &'a self, ) -> Result<ResponseValue<Map<String, Value>>, Error<ApiErrorResponse>>

Get the rollup schema (unwrapped)

Sends a GET request to /rollup/schema

Source

pub async fn submit_tx<'a>( &'a self, body: &'a SubmitTxRequest, ) -> Result<ResponseValue<SubmitTxResponse>, Error<ApiErrorResponse>>

Submit a transaction to the rollup

Sends a POST request to /tx/submit

Trait Implementations§

Source§

impl Deref for Client

Implement Deref to allow calling generated client methods directly.

This enables ergonomic access to all API methods:

let api = Client::new(url, None).await?;
let info = api.exchange_info().await?;
Source§

type Target = Client

The resulting type after dereferencing.
Source§

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

Dereferences the value.

Auto Trait Implementations§

§

impl !Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl UnsafeUnpin for Client

§

impl !UnwindSafe for Client

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<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, 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