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
impl Client
pub async fn update_schema(&self) -> SDKResult<()>
Sourcepub async fn mainnet() -> SDKResult<Self>
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?;Sourcepub fn client(&self) -> &GeneratedClient
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.
Sourcepub fn chain_hash(&self) -> [u8; 32]
pub fn chain_hash(&self) -> [u8; 32]
Get the current chain hash.
pub fn user_actions(&self) -> &Option<Vec<UserActionDiscriminants>>
Sourcepub fn max_priority_fee_bips(&self) -> PriorityFeeBips
pub fn max_priority_fee_bips(&self) -> PriorityFeeBips
Get the default max priority fee in basis points.
Sourcepub fn symbols(&self) -> &[SymbolInfo]
pub fn symbols(&self) -> &[SymbolInfo]
Get all available symbols and their metadata.
Sourcepub fn symbol_info(&self, market_id: MarketId) -> Option<&SymbolInfo>
pub fn symbol_info(&self, market_id: MarketId) -> Option<&SymbolInfo>
Look up symbol info by MarketId.
Sourcepub fn symbol_info_by_name(&self, symbol: &str) -> Option<&SymbolInfo>
pub fn symbol_info_by_name(&self, symbol: &str) -> Option<&SymbolInfo>
Look up symbol info by name.
Sourcepub async fn refresh_metadata(&mut self) -> SDKResult<()>
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§impl Client
impl Client
Sourcepub async fn place_orders(
&self,
market_id: MarketId,
orders: Vec<NewOrderArgs>,
replace: bool,
sub_account_index: Option<u8>,
) -> SDKResult<SubmitTxResponse>
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 viaclient.market_id("BTC-USD"))orders— One or more orders to placereplace— Iftrue, cancel existing orders before placing new onessub_account_index—Nonefor 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);Sourcepub async fn cancel_orders(
&self,
market_id: MarketId,
orders: Vec<CancelOrderArgs>,
sub_account_index: Option<u8>,
) -> SDKResult<SubmitTxResponse>
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?;Sourcepub async fn cancel_market_orders(
&self,
market_id: MarketId,
sub_account_index: Option<u8>,
) -> SDKResult<SubmitTxResponse>
pub async fn cancel_market_orders( &self, market_id: MarketId, sub_account_index: Option<u8>, ) -> SDKResult<SubmitTxResponse>
Sourcepub async fn cancel_all_orders(
&self,
sub_account_index: Option<u8>,
) -> SDKResult<SubmitTxResponse>
pub async fn cancel_all_orders( &self, sub_account_index: Option<u8>, ) -> SDKResult<SubmitTxResponse>
Sourcepub async fn my_open_orders(&self, symbol: &str) -> SDKResult<Vec<BinanceOrder>>
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);
}Sourcepub async fn my_account(&self) -> SDKResult<Account>
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.
Sourcepub async fn my_balances(&self) -> SDKResult<Vec<Balance>>
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.
Sourcepub async fn amend_orders(
&self,
market_id: MarketId,
orders: Vec<AmendOrderArgs>,
sub_account_index: Option<u8>,
) -> SDKResult<SubmitTxResponse>
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
impl Client
Sourcepub async fn send_transaction(
&self,
signed: &SignedTransaction,
) -> SDKResult<SubmitTxResponse>
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
impl Client
Sourcepub fn connect_ws<'f1>(&'f1 self) -> ClientConnectWsBuilder<'f1>
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.
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.
pub fn connect_ws_managed<'f1>(&'f1 self) -> ClientConnectWsManagedBuilder<'f1>
Methods from Deref<Target = GeneratedClient>§
Sourcepub async fn account_config<'a>(
&'a self,
address: &'a str,
) -> Result<ResponseValue<ByteStream>, Error<ApiErrorResponse>>
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
Sourcepub 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>>
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 microsecondslimit: Number of results (default 500, max 1000)order_id: Return orders with orderId >= this valuestart_time: Start time in microsecondssymbol: Trading pair symbol (optional filter)
Sourcepub async fn borrow_lend_pools<'a>(
&'a self,
symbol: Option<&'a str>,
) -> Result<ResponseValue<Vec<BorrowLendPoolResponse>>, Error<ApiErrorResponse>>
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
Sourcepub async fn commission_rate<'a>(
&'a self,
address: &'a str,
symbol: &'a str,
) -> Result<ResponseValue<()>, Error<ApiErrorResponse>>
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
Sourcepub async fn order_book<'a>(
&'a self,
limit: Option<i32>,
symbol: &'a str,
) -> Result<ResponseValue<OrderBook>, Error<ApiErrorResponse>>
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
Sourcepub async fn exchange_info<'a>(
&'a self,
) -> Result<ResponseValue<ExchangeInfo>, Error<ApiErrorResponse>>
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
Sourcepub async fn funding_rate<'a>(
&'a self,
symbol: Option<&'a str>,
) -> Result<ResponseValue<FundingRate>, Error<ApiErrorResponse>>
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
Sourcepub async fn insurance_balance<'a>(
&'a self,
) -> Result<ResponseValue<Vec<InsuranceBalance>>, Error<ApiErrorResponse>>
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
Sourcepub async fn leverage_bracket<'a>(
&'a self,
symbol: Option<&'a str>,
) -> Result<ResponseValue<Vec<LeverageBracket>>, Error<ApiErrorResponse>>
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
Sourcepub async fn open_interest<'a>(
&'a self,
) -> Result<ResponseValue<Vec<OpenInterest>>, Error<ApiErrorResponse>>
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
Sourcepub 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>>
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
Sourcepub async fn query_open_orders<'a>(
&'a self,
address: &'a str,
symbol: &'a str,
) -> Result<ResponseValue<Vec<BinanceOrder>>, Error<ApiErrorResponse>>
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 addresssymbol: Trading pair symbol
Sourcepub async fn ping<'a>(
&'a self,
) -> Result<ResponseValue<PingResponse>, Error<ApiErrorResponse>>
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
Sourcepub async fn rate_limit_order<'a>(
&'a self,
) -> Result<ResponseValue<ByteStream>, Error<ApiErrorResponse>>
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
Sourcepub async fn symbol_config<'a>(
&'a self,
address: &'a str,
symbol: Option<&'a str>,
) -> Result<ResponseValue<()>, Error<ApiErrorResponse>>
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
Sourcepub async fn ticker_24hr<'a>(
&'a self,
) -> Result<ResponseValue<Vec<Ticker24hr>>, Error<ApiErrorResponse>>
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
Sourcepub async fn ticker_price<'a>(
&'a self,
symbol: Option<&'a str>,
) -> Result<ResponseValue<Vec<PriceTicker>>, Error<ApiErrorResponse>>
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
Sourcepub async fn time<'a>(
&'a self,
) -> Result<ResponseValue<TimeResponse>, Error<ApiErrorResponse>>
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
Sourcepub async fn recent_trades<'a>(
&'a self,
limit: Option<i32>,
symbol: &'a str,
) -> Result<ResponseValue<Vec<Trade>>, Error<ApiErrorResponse>>
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 1000symbol: Symbol
Sourcepub 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>>
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 microsecondslimit: Number of results (default 500, max 1000)start_time: Start time in microseconds
Sourcepub 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>>
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)
Sourcepub 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>>
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)
Sourcepub 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>>
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)
Sourcepub 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>>
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 microsecondslimit: Number of results (default 500, max 1000)start_time: Start time in microseconds
Sourcepub async fn account_info<'a>(
&'a self,
address: &'a str,
) -> Result<ResponseValue<Account>, Error<ApiErrorResponse>>
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
Sourcepub async fn account_balance<'a>(
&'a self,
address: &'a str,
) -> Result<ResponseValue<Vec<Balance>>, Error<ApiErrorResponse>>
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
Sourcepub async fn health<'a>(
&'a self,
) -> Result<ResponseValue<ByteStream>, Error<ApiErrorResponse>>
pub async fn health<'a>( &'a self, ) -> Result<ResponseValue<ByteStream>, Error<ApiErrorResponse>>
Get health of the API
Sends a GET request to /health
Sourcepub async fn ready<'a>(
&'a self,
) -> Result<ResponseValue<ReadinessStatus>, Error<ApiErrorResponse>>
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
Sourcepub async fn constants<'a>(
&'a self,
) -> Result<ResponseValue<RollupConstants>, Error<ApiErrorResponse>>
pub async fn constants<'a>( &'a self, ) -> Result<ResponseValue<RollupConstants>, Error<ApiErrorResponse>>
Get the rollup constants
Sends a GET request to /rollup/constants
Sourcepub async fn schema<'a>(
&'a self,
) -> Result<ResponseValue<Map<String, Value>>, Error<ApiErrorResponse>>
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
Sourcepub async fn submit_tx<'a>(
&'a self,
body: &'a SubmitTxRequest,
) -> Result<ResponseValue<SubmitTxResponse>, Error<ApiErrorResponse>>
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