pub struct BinanceFuturesHttpClient { /* private fields */ }Expand description
Binance Futures HTTP client for USD-M and COIN-M perpetuals.
Implementations§
Source§impl BinanceFuturesHttpClient
impl BinanceFuturesHttpClient
Sourcepub fn new(
product_type: BinanceProductType,
environment: BinanceEnvironment,
clock: &'static AtomicTime,
api_key: Option<String>,
api_secret: Option<String>,
base_url_override: Option<String>,
recv_window: Option<u64>,
timeout_secs: Option<u64>,
proxy_url: Option<String>,
treat_expired_as_canceled: bool,
) -> BinanceFuturesHttpResult<Self>
pub fn new( product_type: BinanceProductType, environment: BinanceEnvironment, clock: &'static AtomicTime, api_key: Option<String>, api_secret: Option<String>, base_url_override: Option<String>, recv_window: Option<u64>, timeout_secs: Option<u64>, proxy_url: Option<String>, treat_expired_as_canceled: bool, ) -> BinanceFuturesHttpResult<Self>
Creates a new BinanceFuturesHttpClient instance.
§Errors
Returns an error if the product type is invalid or HTTP client creation fails.
Sourcepub const fn product_type(&self) -> BinanceProductType
pub const fn product_type(&self) -> BinanceProductType
Returns the product type (UsdM or CoinM).
Sourcepub fn inner(&self) -> &BinanceRawFuturesHttpClient
pub fn inner(&self) -> &BinanceRawFuturesHttpClient
Returns a reference to the inner raw HTTP client.
Sourcepub fn instruments_cache(&self) -> Arc<DashMap<Ustr, BinanceFuturesInstrument>> ⓘ
pub fn instruments_cache(&self) -> Arc<DashMap<Ustr, BinanceFuturesInstrument>> ⓘ
Returns a clone of the instruments cache Arc.
Sourcepub async fn server_time(&self) -> BinanceFuturesHttpResult<BinanceServerTime>
pub async fn server_time(&self) -> BinanceFuturesHttpResult<BinanceServerTime>
Sourcepub async fn set_leverage(
&self,
params: &BinanceSetLeverageParams,
) -> BinanceFuturesHttpResult<BinanceLeverageResponse>
pub async fn set_leverage( &self, params: &BinanceSetLeverageParams, ) -> BinanceFuturesHttpResult<BinanceLeverageResponse>
Sourcepub async fn set_margin_type(
&self,
params: &BinanceSetMarginTypeParams,
) -> BinanceFuturesHttpResult<Value>
pub async fn set_margin_type( &self, params: &BinanceSetMarginTypeParams, ) -> BinanceFuturesHttpResult<Value>
Sourcepub async fn query_hedge_mode(
&self,
) -> BinanceFuturesHttpResult<BinanceHedgeModeResponse>
pub async fn query_hedge_mode( &self, ) -> BinanceFuturesHttpResult<BinanceHedgeModeResponse>
Sourcepub async fn create_listen_key(
&self,
) -> BinanceFuturesHttpResult<ListenKeyResponse>
pub async fn create_listen_key( &self, ) -> BinanceFuturesHttpResult<ListenKeyResponse>
Sourcepub async fn keepalive_listen_key(
&self,
listen_key: &str,
) -> BinanceFuturesHttpResult<()>
pub async fn keepalive_listen_key( &self, listen_key: &str, ) -> BinanceFuturesHttpResult<()>
Sourcepub async fn close_listen_key(
&self,
listen_key: &str,
) -> BinanceFuturesHttpResult<()>
pub async fn close_listen_key( &self, listen_key: &str, ) -> BinanceFuturesHttpResult<()>
Sourcepub async fn exchange_info(&self) -> BinanceFuturesHttpResult<()>
pub async fn exchange_info(&self) -> BinanceFuturesHttpResult<()>
Fetches exchange information and populates the instrument cache.
§Errors
Returns an error if the request fails or the product type is invalid.
Sourcepub async fn request_symbol_statuses(
&self,
) -> BinanceFuturesHttpResult<AHashMap<Ustr, MarketStatusAction>>
pub async fn request_symbol_statuses( &self, ) -> BinanceFuturesHttpResult<AHashMap<Ustr, MarketStatusAction>>
Fetches exchange info and returns the current status of each symbol.
Builds a fresh status snapshot from the response without disturbing the shared instruments cache, so a transient failure does not break other HTTP operations that depend on cached precision data.
§Errors
Returns an error if the request fails or the product type is invalid.
Sourcepub async fn request_instruments(
&self,
) -> BinanceFuturesHttpResult<Vec<InstrumentAny>>
pub async fn request_instruments( &self, ) -> BinanceFuturesHttpResult<Vec<InstrumentAny>>
Fetches exchange information and returns parsed Nautilus instruments.
§Errors
Returns an error if the request fails or the product type is invalid.
Sourcepub async fn ticker_24h(
&self,
params: &BinanceTicker24hrParams,
) -> BinanceFuturesHttpResult<Vec<BinanceFuturesTicker24hr>>
pub async fn ticker_24h( &self, params: &BinanceTicker24hrParams, ) -> BinanceFuturesHttpResult<Vec<BinanceFuturesTicker24hr>>
Sourcepub async fn book_ticker(
&self,
params: &BinanceBookTickerParams,
) -> BinanceFuturesHttpResult<Vec<BinanceBookTicker>>
pub async fn book_ticker( &self, params: &BinanceBookTickerParams, ) -> BinanceFuturesHttpResult<Vec<BinanceBookTicker>>
Sourcepub async fn price_ticker(
&self,
symbol: Option<&str>,
) -> BinanceFuturesHttpResult<Vec<BinancePriceTicker>>
pub async fn price_ticker( &self, symbol: Option<&str>, ) -> BinanceFuturesHttpResult<Vec<BinancePriceTicker>>
Sourcepub async fn depth(
&self,
params: &BinanceDepthParams,
) -> BinanceFuturesHttpResult<BinanceOrderBook>
pub async fn depth( &self, params: &BinanceDepthParams, ) -> BinanceFuturesHttpResult<BinanceOrderBook>
Sourcepub async fn mark_price(
&self,
params: &BinanceMarkPriceParams,
) -> BinanceFuturesHttpResult<Vec<BinanceFuturesMarkPrice>>
pub async fn mark_price( &self, params: &BinanceMarkPriceParams, ) -> BinanceFuturesHttpResult<Vec<BinanceFuturesMarkPrice>>
Sourcepub async fn funding_rate(
&self,
params: &BinanceFundingRateParams,
) -> BinanceFuturesHttpResult<Vec<BinanceFundingRate>>
pub async fn funding_rate( &self, params: &BinanceFundingRateParams, ) -> BinanceFuturesHttpResult<Vec<BinanceFundingRate>>
Sourcepub async fn open_interest(
&self,
params: &BinanceOpenInterestParams,
) -> BinanceFuturesHttpResult<BinanceOpenInterest>
pub async fn open_interest( &self, params: &BinanceOpenInterestParams, ) -> BinanceFuturesHttpResult<BinanceOpenInterest>
Sourcepub async fn query_order(
&self,
params: &BinanceOrderQueryParams,
) -> BinanceFuturesHttpResult<BinanceFuturesOrder>
pub async fn query_order( &self, params: &BinanceOrderQueryParams, ) -> BinanceFuturesHttpResult<BinanceFuturesOrder>
Queries a single order by order ID or client order ID.
§Errors
Returns an error if the request fails.
Sourcepub async fn query_open_orders(
&self,
params: &BinanceOpenOrdersParams,
) -> BinanceFuturesHttpResult<Vec<BinanceFuturesOrder>>
pub async fn query_open_orders( &self, params: &BinanceOpenOrdersParams, ) -> BinanceFuturesHttpResult<Vec<BinanceFuturesOrder>>
Sourcepub async fn query_all_orders(
&self,
params: &BinanceAllOrdersParams,
) -> BinanceFuturesHttpResult<Vec<BinanceFuturesOrder>>
pub async fn query_all_orders( &self, params: &BinanceAllOrdersParams, ) -> BinanceFuturesHttpResult<Vec<BinanceFuturesOrder>>
Sourcepub async fn query_account(
&self,
) -> BinanceFuturesHttpResult<BinanceFuturesAccountInfo>
pub async fn query_account( &self, ) -> BinanceFuturesHttpResult<BinanceFuturesAccountInfo>
Fetches account information including balances and positions.
§Errors
Returns an error if the request fails.
Sourcepub async fn query_positions(
&self,
params: &BinancePositionRiskParams,
) -> BinanceFuturesHttpResult<Vec<BinancePositionRisk>>
pub async fn query_positions( &self, params: &BinancePositionRiskParams, ) -> BinanceFuturesHttpResult<Vec<BinancePositionRisk>>
Sourcepub async fn query_user_trades(
&self,
params: &BinanceUserTradesParams,
) -> BinanceFuturesHttpResult<Vec<BinanceUserTrade>>
pub async fn query_user_trades( &self, params: &BinanceUserTradesParams, ) -> BinanceFuturesHttpResult<Vec<BinanceUserTrade>>
Sourcepub async fn submit_order(
&self,
account_id: AccountId,
instrument_id: InstrumentId,
client_order_id: ClientOrderId,
order_side: OrderSide,
order_type: OrderType,
quantity: Quantity,
time_in_force: TimeInForce,
price: Option<Price>,
trigger_price: Option<Price>,
reduce_only: bool,
post_only: bool,
position_side: Option<BinancePositionSide>,
price_match: Option<BinancePriceMatch>,
) -> Result<OrderStatusReport>
pub async fn submit_order( &self, account_id: AccountId, instrument_id: InstrumentId, client_order_id: ClientOrderId, order_side: OrderSide, order_type: OrderType, quantity: Quantity, time_in_force: TimeInForce, price: Option<Price>, trigger_price: Option<Price>, reduce_only: bool, post_only: bool, position_side: Option<BinancePositionSide>, price_match: Option<BinancePriceMatch>, ) -> Result<OrderStatusReport>
Submits a new order.
§Errors
Returns an error if:
- The instrument is not cached.
- The order type or time-in-force is unsupported.
- Stop orders are submitted without a trigger price.
- The request fails.
Sourcepub async fn submit_algo_order(
&self,
account_id: AccountId,
instrument_id: InstrumentId,
client_order_id: ClientOrderId,
order_side: OrderSide,
order_type: OrderType,
quantity: Quantity,
time_in_force: TimeInForce,
price: Option<Price>,
trigger_price: Option<Price>,
reduce_only: bool,
close_position: bool,
position_side: Option<BinancePositionSide>,
activation_price: Option<Price>,
callback_rate: Option<String>,
working_type: Option<BinanceWorkingType>,
) -> Result<OrderStatusReport>
pub async fn submit_algo_order( &self, account_id: AccountId, instrument_id: InstrumentId, client_order_id: ClientOrderId, order_side: OrderSide, order_type: OrderType, quantity: Quantity, time_in_force: TimeInForce, price: Option<Price>, trigger_price: Option<Price>, reduce_only: bool, close_position: bool, position_side: Option<BinancePositionSide>, activation_price: Option<Price>, callback_rate: Option<String>, working_type: Option<BinanceWorkingType>, ) -> Result<OrderStatusReport>
Submits an algo order (conditional order) to the Binance Algo Service.
As of 2025-12-09, Binance migrated conditional order types to the Algo Service API. This method handles StopMarket, StopLimit, MarketIfTouched, LimitIfTouched, and TrailingStopMarket orders.
§Errors
Returns an error if:
- The order type requires a trigger price but none is provided.
- The instrument is not cached.
- The request fails.
Sourcepub async fn submit_order_list(
&self,
orders: &[BatchOrderItem],
) -> BinanceFuturesHttpResult<Vec<BatchOrderResult>>
pub async fn submit_order_list( &self, orders: &[BatchOrderItem], ) -> BinanceFuturesHttpResult<Vec<BatchOrderResult>>
Submits multiple orders in a single request (up to 5 orders).
Each order in the batch is processed independently. The response contains the result for each order, which can be either a success or an error.
§Errors
Returns an error if the batch exceeds 5 orders or the request fails.
Sourcepub async fn modify_order(
&self,
account_id: AccountId,
instrument_id: InstrumentId,
venue_order_id: Option<VenueOrderId>,
client_order_id: Option<ClientOrderId>,
order_side: OrderSide,
quantity: Quantity,
price: Price,
) -> Result<OrderStatusReport>
pub async fn modify_order( &self, account_id: AccountId, instrument_id: InstrumentId, venue_order_id: Option<VenueOrderId>, client_order_id: Option<ClientOrderId>, order_side: OrderSide, quantity: Quantity, price: Price, ) -> Result<OrderStatusReport>
Modifies an existing order (price and quantity only).
Either venue_order_id or client_order_id must be provided.
§Errors
Returns an error if:
- Neither venue_order_id nor client_order_id is provided.
- The instrument is not cached.
- The request fails.
Sourcepub async fn batch_modify_orders(
&self,
modifies: &[BatchModifyItem],
) -> BinanceFuturesHttpResult<Vec<BatchOrderResult>>
pub async fn batch_modify_orders( &self, modifies: &[BatchModifyItem], ) -> BinanceFuturesHttpResult<Vec<BatchOrderResult>>
Modifies multiple orders in a single request (up to 5 orders).
Each modify in the batch is processed independently. The response contains the result for each modify, which can be either a success or an error.
§Errors
Returns an error if the batch exceeds 5 orders or the request fails.
Sourcepub async fn cancel_order(
&self,
instrument_id: InstrumentId,
venue_order_id: Option<VenueOrderId>,
client_order_id: Option<ClientOrderId>,
) -> Result<VenueOrderId>
pub async fn cancel_order( &self, instrument_id: InstrumentId, venue_order_id: Option<VenueOrderId>, client_order_id: Option<ClientOrderId>, ) -> Result<VenueOrderId>
Cancels an order by venue order ID or client order ID.
Either venue_order_id or client_order_id must be provided.
§Errors
Returns an error if:
- Neither venue_order_id nor client_order_id is provided.
- The request fails.
Sourcepub async fn cancel_algo_order(
&self,
client_order_id: ClientOrderId,
) -> Result<()>
pub async fn cancel_algo_order( &self, client_order_id: ClientOrderId, ) -> Result<()>
Cancels an algo order (conditional order) via the Binance Algo Service.
Use the client_algo_id which corresponds to the client_order_id used
when submitting the algo order.
§Errors
Returns an error if the request fails.
Sourcepub async fn cancel_all_orders(
&self,
instrument_id: InstrumentId,
) -> Result<Vec<VenueOrderId>>
pub async fn cancel_all_orders( &self, instrument_id: InstrumentId, ) -> Result<Vec<VenueOrderId>>
Sourcepub async fn cancel_all_algo_orders(
&self,
instrument_id: InstrumentId,
) -> Result<()>
pub async fn cancel_all_algo_orders( &self, instrument_id: InstrumentId, ) -> Result<()>
Sourcepub async fn batch_cancel_orders(
&self,
cancels: &[BatchCancelItem],
) -> BinanceFuturesHttpResult<Vec<BatchOrderResult>>
pub async fn batch_cancel_orders( &self, cancels: &[BatchCancelItem], ) -> BinanceFuturesHttpResult<Vec<BatchOrderResult>>
Cancels multiple orders in a single request (up to 5 orders).
Each cancel in the batch is processed independently. The response contains the result for each cancel, which can be either a success or an error.
§Errors
Returns an error if the batch exceeds 5 orders or the request fails.
Sourcepub async fn query_open_algo_orders(
&self,
instrument_id: Option<InstrumentId>,
) -> BinanceFuturesHttpResult<Vec<BinanceFuturesAlgoOrder>>
pub async fn query_open_algo_orders( &self, instrument_id: Option<InstrumentId>, ) -> BinanceFuturesHttpResult<Vec<BinanceFuturesAlgoOrder>>
Queries open algo orders (conditional orders).
Returns all open algo orders, optionally filtered by symbol.
§Errors
Returns an error if the request fails.
Sourcepub async fn query_algo_order(
&self,
client_order_id: ClientOrderId,
) -> BinanceFuturesHttpResult<BinanceFuturesAlgoOrder>
pub async fn query_algo_order( &self, client_order_id: ClientOrderId, ) -> BinanceFuturesHttpResult<BinanceFuturesAlgoOrder>
Sourcepub async fn request_account_state(
&self,
account_id: AccountId,
) -> Result<AccountState>
pub async fn request_account_state( &self, account_id: AccountId, ) -> Result<AccountState>
Sourcepub async fn request_order_status_report(
&self,
account_id: AccountId,
instrument_id: InstrumentId,
venue_order_id: Option<VenueOrderId>,
client_order_id: Option<ClientOrderId>,
) -> Result<OrderStatusReport>
pub async fn request_order_status_report( &self, account_id: AccountId, instrument_id: InstrumentId, venue_order_id: Option<VenueOrderId>, client_order_id: Option<ClientOrderId>, ) -> Result<OrderStatusReport>
Requests a single order status report.
Either venue_order_id or client_order_id must be provided.
§Errors
Returns an error if the request fails or parsing fails.
Sourcepub async fn request_order_status_reports(
&self,
account_id: AccountId,
instrument_id: Option<InstrumentId>,
open_only: bool,
) -> Result<Vec<OrderStatusReport>>
pub async fn request_order_status_reports( &self, account_id: AccountId, instrument_id: Option<InstrumentId>, open_only: bool, ) -> Result<Vec<OrderStatusReport>>
Requests order status reports for open orders.
If instrument_id is None, returns all open orders.
§Errors
Returns an error if the request fails or parsing fails.
Sourcepub async fn request_fill_reports(
&self,
account_id: AccountId,
instrument_id: InstrumentId,
venue_order_id: Option<VenueOrderId>,
start: Option<i64>,
end: Option<i64>,
limit: Option<u32>,
) -> Result<Vec<FillReport>>
pub async fn request_fill_reports( &self, account_id: AccountId, instrument_id: InstrumentId, venue_order_id: Option<VenueOrderId>, start: Option<i64>, end: Option<i64>, limit: Option<u32>, ) -> Result<Vec<FillReport>>
Sourcepub async fn request_trades(
&self,
instrument_id: InstrumentId,
limit: Option<u32>,
) -> Result<Vec<TradeTick>>
pub async fn request_trades( &self, instrument_id: InstrumentId, limit: Option<u32>, ) -> Result<Vec<TradeTick>>
Requests recent public trades for an instrument.
§Errors
Returns an error if the request fails, instrument is not cached, or parsing fails.
Sourcepub async fn request_bars(
&self,
bar_type: BarType,
start: Option<DateTime<Utc>>,
end: Option<DateTime<Utc>>,
limit: Option<u32>,
) -> Result<Vec<Bar>>
pub async fn request_bars( &self, bar_type: BarType, start: Option<DateTime<Utc>>, end: Option<DateTime<Utc>>, limit: Option<u32>, ) -> Result<Vec<Bar>>
Requests bar (kline/candlestick) data for an instrument.
§Errors
Returns an error if the bar type is not supported, instrument is not cached, or the request fails.
Trait Implementations§
Source§impl Clone for BinanceFuturesHttpClient
impl Clone for BinanceFuturesHttpClient
Source§fn clone(&self) -> BinanceFuturesHttpClient
fn clone(&self) -> BinanceFuturesHttpClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for BinanceFuturesHttpClient
impl !RefUnwindSafe for BinanceFuturesHttpClient
impl Send for BinanceFuturesHttpClient
impl Sync for BinanceFuturesHttpClient
impl Unpin for BinanceFuturesHttpClient
impl UnsafeUnpin for BinanceFuturesHttpClient
impl !UnwindSafe for BinanceFuturesHttpClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more