Skip to main content

BinanceSpotHttpClient

Struct BinanceSpotHttpClient 

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

High-level HTTP client for Binance Spot API.

Wraps BinanceRawSpotHttpClient and provides domain-level methods:

  • Simple types (ping, server_time): Pass through from raw client.
  • Complex types (instruments, orders): Transform to Nautilus domain types.

Implementations§

Source§

impl BinanceSpotHttpClient

Source

pub fn new( 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>, ) -> BinanceSpotHttpResult<Self>

Creates a new Binance Spot HTTP client.

§Errors

Returns an error if the underlying HTTP client cannot be created.

Source

pub fn inner(&self) -> &BinanceRawSpotHttpClient

Returns a reference to the inner raw client.

Source

pub const fn schema_id() -> u16

Returns the SBE schema ID.

Source

pub const fn schema_version() -> u16

Returns the SBE schema version.

Source

pub fn cache_instruments(&self, instruments: Vec<InstrumentAny>)

Caches multiple instruments.

Source

pub fn cache_instrument(&self, instrument: InstrumentAny)

Caches a single instrument.

Source

pub fn get_instrument(&self, symbol: &Ustr) -> Option<InstrumentAny>

Gets an instrument from the cache by symbol.

Source

pub async fn ping(&self) -> BinanceSpotHttpResult<()>

Tests connectivity to the API.

§Errors

Returns an error if the request fails or SBE decoding fails.

Source

pub async fn server_time(&self) -> BinanceSpotHttpResult<i64>

Returns the server time in microseconds since epoch.

Note: SBE provides microsecond precision vs JSON’s milliseconds.

§Errors

Returns an error if the request fails or SBE decoding fails.

Source

pub async fn exchange_info( &self, ) -> BinanceSpotHttpResult<BinanceExchangeInfoSbe>

Returns exchange information including trading symbols.

§Errors

Returns an error if the request fails or SBE decoding fails.

Source

pub async fn request_instruments( &self, ) -> BinanceSpotHttpResult<Vec<InstrumentAny>>

Requests Nautilus instruments for all trading symbols.

Fetches exchange info via SBE and parses each symbol into a CurrencyPair. Non-trading symbols are skipped with a debug log.

§Errors

Returns an error if the request fails or SBE decoding fails.

Source

pub async fn request_trades( &self, instrument_id: InstrumentId, limit: Option<u32>, ) -> Result<Vec<TradeTick>>

Requests recent trades for an instrument.

§Errors

Returns an error if the request fails, the instrument is not cached, or trade parsing fails.

Source

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.

§Errors

Returns an error if the bar type is not supported, instrument is not cached, or the request fails.

Source

pub async fn request_account_state( &self, account_id: AccountId, ) -> Result<AccountState>

Requests the account state with Nautilus types.

§Errors

Returns an error if the request fails or SBE decoding fails.

Source

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 the status of a specific order.

Either venue_order_id or client_order_id must be provided.

§Errors

Returns an error if neither identifier is provided, the request fails, instrument is not cached, or parsing fails.

Source

pub async fn request_order_status_reports( &self, account_id: AccountId, instrument_id: Option<InstrumentId>, start: Option<DateTime<Utc>>, end: Option<DateTime<Utc>>, open_only: bool, limit: Option<u32>, ) -> Result<Vec<OrderStatusReport>>

Requests order status reports.

When open_only is true, returns only open orders (instrument_id optional). When open_only is false, returns order history (instrument_id required).

§Errors

Returns an error if the request fails, any order’s instrument is not cached, or parsing fails.

Source

pub async fn request_fill_reports( &self, account_id: AccountId, instrument_id: InstrumentId, venue_order_id: Option<VenueOrderId>, start: Option<DateTime<Utc>>, end: Option<DateTime<Utc>>, limit: Option<u32>, ) -> Result<Vec<FillReport>>

Requests fill reports (trade history) for an instrument.

§Errors

Returns an error if the request fails, any trade’s instrument is not cached, or parsing fails.

Source

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>, post_only: bool, quote_quantity: bool, display_qty: Option<Quantity>, ) -> Result<OrderStatusReport>

Submits a new order to the venue.

Converts Nautilus domain types to Binance-specific parameters and returns an OrderStatusReport.

§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 or SBE decoding fails.
Source

pub async fn submit_order_list( &self, orders: &[BatchOrderItem], ) -> BinanceSpotHttpResult<Vec<BatchOrderResult>>

Submits multiple orders in a single batch request.

Binance limits batch submit to 5 orders maximum.

§Errors

Returns an error if the request fails or JSON parsing fails.

Source

pub async fn modify_order( &self, account_id: AccountId, instrument_id: InstrumentId, venue_order_id: VenueOrderId, client_order_id: ClientOrderId, order_side: OrderSide, order_type: OrderType, quantity: Quantity, time_in_force: TimeInForce, price: Option<Price>, ) -> Result<OrderStatusReport>

Modifies an existing order (cancel and replace atomically).

§Errors

Returns an error if:

  • The instrument is not cached.
  • The order type or time-in-force is unsupported.
  • The request fails or SBE decoding fails.
Source

pub async fn cancel_order( &self, instrument_id: InstrumentId, venue_order_id: Option<VenueOrderId>, client_order_id: Option<ClientOrderId>, ) -> Result<VenueOrderId>

Cancels an existing order on the venue.

Either venue_order_id or client_order_id must be provided.

§Errors

Returns an error if the request fails or SBE decoding fails.

Source

pub async fn batch_cancel_orders( &self, cancels: &[BatchCancelItem], ) -> BinanceSpotHttpResult<Vec<BatchCancelResult>>

Cancels multiple orders in a single batch request.

Binance limits batch cancel to 5 orders maximum.

§Errors

Returns an error if the request fails or JSON parsing fails.

Source

pub async fn cancel_all_orders( &self, instrument_id: InstrumentId, ) -> Result<Vec<(VenueOrderId, ClientOrderId)>>

Cancels all open orders for a symbol.

Returns the venue order IDs of all canceled orders.

§Errors

Returns an error if the request fails or SBE decoding fails.

Trait Implementations§

Source§

impl Clone for BinanceSpotHttpClient

Source§

fn clone(&self) -> Self

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 BinanceSpotHttpClient

Source§

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

Formats the value using the given formatter. Read more

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> PolicyExt for T
where T: ?Sized,

§

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
§

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> Ungil for T
where T: Send,