Skip to main content

Account

Struct Account 

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

Account and trading API client.

Provides authenticated endpoints for account information and trading. All methods require authentication.

Implementations§

Source§

impl Account

Source

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

Get current account information including balances.

§Example
let client = Binance::new("api_key", "secret_key")?;
let account = client.account().get_account().await?;

for balance in account.balances {
    if balance.free > 0.0 || balance.locked > 0.0 {
        println!("{}: free={}, locked={}", balance.asset, balance.free, balance.locked);
    }
}
Source

pub async fn my_trades( &self, symbol: &str, from_id: Option<u64>, start_time: Option<u64>, end_time: Option<u64>, limit: Option<u32>, ) -> Result<Vec<UserTrade>>

Get account trade history for a symbol.

§Arguments
  • symbol - Trading pair symbol
  • from_id - Trade ID to fetch from
  • start_time - Start time in milliseconds
  • end_time - End time in milliseconds
  • limit - Max number of trades (default 500, max 1000)
§Example
let client = Binance::new("api_key", "secret_key")?;
let trades = client.account().my_trades("BTCUSDT", None, None, None, Some(10)).await?;
Source

pub async fn my_prevented_matches( &self, symbol: &str, prevented_match_id: Option<u64>, order_id: Option<u64>, from_prevented_match_id: Option<u64>, limit: Option<u32>, ) -> Result<Vec<PreventedMatch>>

Get orders that were expired due to self-trade prevention.

§Arguments
  • symbol - Trading pair symbol
  • prevented_match_id - Prevented match ID
  • order_id - Order ID
  • from_prevented_match_id - Start from prevented match ID
  • limit - Max number of entries (default 500, max 1000)
Source

pub async fn my_allocations( &self, symbol: &str, start_time: Option<u64>, end_time: Option<u64>, from_allocation_id: Option<u64>, limit: Option<u32>, order_id: Option<u64>, ) -> Result<Vec<Allocation>>

Get SOR allocations for a symbol.

§Arguments
  • symbol - Trading pair symbol
  • start_time - Start time in milliseconds
  • end_time - End time in milliseconds
  • from_allocation_id - Allocation ID to fetch from
  • limit - Max number of entries (default 500, max 1000)
  • order_id - Optional order ID to filter
Source

pub async fn commission_rates(&self, symbol: &str) -> Result<AccountCommission>

Get commission rates for a symbol.

§Arguments
  • symbol - Trading pair symbol
Source

pub async fn unfilled_order_count(&self) -> Result<Vec<UnfilledOrderCount>>

Query unfilled order count for all rate limit intervals.

Returns the current count of unfilled orders for each rate limit interval (e.g., per second, per day). This is useful for monitoring order placement rate limits.

§Example
let client = Binance::new("api_key", "secret_key")?;
let counts = client.account().unfilled_order_count().await?;
for count in counts {
    println!("{}: {}/{} orders", count.interval, count.count, count.limit);
}
Source

pub async fn order_amendments( &self, symbol: &str, order_id: u64, from_execution_id: Option<u64>, limit: Option<u32>, ) -> Result<Vec<OrderAmendment>>

Query amendment history for a specific order.

Returns all amendments made to a single order.

§Arguments
  • symbol - Trading pair symbol
  • order_id - Order ID to query amendments for
  • from_execution_id - Optional execution ID to start from
  • limit - Max number of entries (default 500, max 1000)
§Example
let client = Binance::new("api_key", "secret_key")?;
let amendments = client.account().order_amendments("BTCUSDT", 12345, None, None).await?;
for amendment in amendments {
    println!("Qty changed from {} to {}", amendment.orig_qty, amendment.new_qty);
}
Source

pub async fn create_order(&self, order: &NewOrder) -> Result<OrderFull>

Create a new order.

Use OrderBuilder to construct orders with the desired parameters.

§Example
use binance_api_client::{OrderBuilder, OrderSide, OrderType, TimeInForce};

let client = Binance::new("api_key", "secret_key")?;

// Limit buy order
let order = OrderBuilder::new("BTCUSDT", OrderSide::Buy, OrderType::Limit)
    .quantity("0.001")
    .price("50000.00")
    .time_in_force(TimeInForce::GTC)
    .build();

let response = client.account().create_order(&order).await?;
Source

pub async fn test_order(&self, order: &NewOrder) -> Result<()>

Test a new order without executing it.

Validates order parameters but doesn’t place the order.

§Example
let order = OrderBuilder::new("BTCUSDT", OrderSide::Buy, OrderType::Market)
    .quantity("0.001")
    .build();

client.account().test_order(&order).await?;
println!("Order parameters are valid");
Source

pub async fn amend_order_keep_priority( &self, symbol: &str, order_id: Option<u64>, orig_client_order_id: Option<&str>, new_qty: &str, new_client_order_id: Option<&str>, ) -> Result<AmendOrderResponse>

Amend an order’s quantity while keeping queue priority.

This endpoint allows reducing the quantity of an existing open order without losing its place in the order queue. The new quantity must be greater than 0 and less than the current order quantity.

§Arguments
  • symbol - Trading pair symbol
  • order_id - Order ID to amend (either order_id or orig_client_order_id required)
  • orig_client_order_id - Client order ID to amend
  • new_qty - New quantity (must be less than current quantity)
  • new_client_order_id - Optional new client order ID after amendment
§Example
let client = Binance::new("api_key", "secret_key")?;

// Reduce an order's quantity from 10 to 5
let response = client.account().amend_order_keep_priority(
    "BTCUSDT",
    Some(12345),
    None,
    "5.0",
    None,
).await?;

println!("Amended order ID: {}", response.amended_order.order_id);
Source

pub async fn cancel_replace_order( &self, request: &CancelReplaceOrder, ) -> Result<CancelReplaceResponse>

Cancel an existing order and place a new order.

§Example
use binance_api_client::api::account::CancelReplaceOrderBuilder;
use binance_api_client::{CancelReplaceMode, OrderSide, OrderType, TimeInForce};

let request = CancelReplaceOrderBuilder::new("BTCUSDT", OrderSide::Buy, OrderType::Limit, CancelReplaceMode::StopOnFailure)
    .cancel_order_id(12345)
    .price("25000.00")
    .quantity("0.01")
    .time_in_force(TimeInForce::GTC)
    .build();

let response = client.account().cancel_replace_order(&request).await?;
println!("Cancel result: {:?}", response.cancel_result);
Source

pub async fn create_sor_order(&self, order: &NewOrder) -> Result<OrderFull>

Place an order using smart order routing (SOR).

Source

pub async fn test_sor_order( &self, order: &NewOrder, compute_commission_rates: bool, ) -> Result<SorOrderTestResponse>

Test a new SOR order without executing it.

Source

pub async fn get_order( &self, symbol: &str, order_id: Option<u64>, client_order_id: Option<&str>, ) -> Result<Order>

Query an order’s status.

§Arguments
  • symbol - Trading pair symbol
  • order_id - Order ID to query (either order_id or client_order_id required)
  • client_order_id - Client order ID to query
§Example
let client = Binance::new("api_key", "secret_key")?;
let order = client.account().get_order("BTCUSDT", Some(12345), None).await?;
println!("Order status: {:?}", order.status);
Source

pub async fn cancel_order( &self, symbol: &str, order_id: Option<u64>, client_order_id: Option<&str>, ) -> Result<CancelOrderResponse>

Cancel an order.

§Arguments
  • symbol - Trading pair symbol
  • order_id - Order ID to cancel (either order_id or client_order_id required)
  • client_order_id - Client order ID to cancel
§Example
let client = Binance::new("api_key", "secret_key")?;
let result = client.account().cancel_order("BTCUSDT", Some(12345), None).await?;
println!("Canceled order: {}", result.order_id);
Source

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

Get all open orders for a symbol, or all symbols if none specified.

§Arguments
  • symbol - Optional trading pair symbol
§Example
let client = Binance::new("api_key", "secret_key")?;

// Get open orders for a specific symbol
let orders = client.account().open_orders(Some("BTCUSDT")).await?;

// Get all open orders
let all_orders = client.account().open_orders(None).await?;
Source

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

Cancel all open orders for a symbol.

§Arguments
  • symbol - Trading pair symbol
§Example
let client = Binance::new("api_key", "secret_key")?;
let canceled = client.account().cancel_all_orders("BTCUSDT").await?;
println!("Canceled {} orders", canceled.len());
Source

pub async fn all_orders( &self, symbol: &str, order_id: Option<u64>, start_time: Option<u64>, end_time: Option<u64>, limit: Option<u32>, ) -> Result<Vec<Order>>

Get all orders for a symbol (active, canceled, or filled).

§Arguments
  • symbol - Trading pair symbol
  • order_id - If set, get orders >= this order ID
  • start_time - Start time in milliseconds
  • end_time - End time in milliseconds
  • limit - Max number of orders (default 500, max 1000)
§Example
let client = Binance::new("api_key", "secret_key")?;
let orders = client.account().all_orders("BTCUSDT", None, None, None, Some(10)).await?;
Source

pub async fn create_oco(&self, order: &NewOcoOrder) -> Result<OcoOrder>

Create a new OCO (One-Cancels-Other) order.

An OCO order combines a limit order with a stop-limit order.

§Example
let oco = OcoOrderBuilder::new("BTCUSDT", OrderSide::Sell, "1.0", "55000.00", "48000.00")
    .stop_limit_price("47900.00")
    .build();

let result = client.account().create_oco(&oco).await?;
Source

pub async fn create_oto(&self, order: &NewOtoOrder) -> Result<OcoOrder>

Create a new OTO (One-Triggers-the-Other) order list.

Source

pub async fn create_otoco(&self, order: &NewOtocoOrder) -> Result<OcoOrder>

Create a new OTOCO (One-Triggers-One-Cancels-the-Other) order list.

Source

pub async fn create_opo(&self, order: &NewOpoOrder) -> Result<OcoOrder>

Create a new OPO (One-Places-the-Other) order list.

Source

pub async fn create_opoco(&self, order: &NewOpocoOrder) -> Result<OcoOrder>

Create a new OPOCO (One-Places-One-Cancels-the-Other) order list.

Source

pub async fn get_order_list( &self, order_list_id: Option<u64>, client_order_list_id: Option<&str>, ) -> Result<OcoOrder>

Query an order list by ID or client order list ID.

This applies to all order list types (OCO/OTO/OTOCO/OPO/OPOCO).

Source

pub async fn cancel_order_list( &self, symbol: &str, order_list_id: Option<u64>, client_order_list_id: Option<&str>, ) -> Result<OcoOrder>

Cancel an order list by symbol and list identifiers.

This applies to all order list types (OCO/OTO/OTOCO/OPO/OPOCO).

Source

pub async fn all_order_lists( &self, from_id: Option<u64>, start_time: Option<u64>, end_time: Option<u64>, limit: Option<u32>, ) -> Result<Vec<OcoOrder>>

Get all order lists.

This applies to all order list types (OCO/OTO/OTOCO/OPO/OPOCO).

Source

pub async fn open_order_lists(&self) -> Result<Vec<OcoOrder>>

Get all open order lists.

This applies to all order list types (OCO/OTO/OTOCO/OPO/OPOCO).

Source

pub async fn get_oco( &self, order_list_id: Option<u64>, client_order_list_id: Option<&str>, ) -> Result<OcoOrder>

Query an OCO order’s status.

§Arguments
  • order_list_id - OCO order list ID
§Example
let oco = client.account().get_oco(Some(12345), None).await?;
Source

pub async fn cancel_oco( &self, symbol: &str, order_list_id: Option<u64>, client_order_list_id: Option<&str>, ) -> Result<OcoOrder>

Cancel an OCO order.

§Arguments
  • symbol - Trading pair symbol
  • order_list_id - OCO order list ID
§Example
let result = client.account().cancel_oco("BTCUSDT", Some(12345), None).await?;
Source

pub async fn all_oco( &self, from_id: Option<u64>, start_time: Option<u64>, end_time: Option<u64>, limit: Option<u32>, ) -> Result<Vec<OcoOrder>>

Get all OCO orders.

§Arguments
  • from_id - If set, get orders >= this order list ID
  • start_time - Start time in milliseconds
  • end_time - End time in milliseconds
  • limit - Max number of orders (default 500, max 1000)
Source

pub async fn open_oco(&self) -> Result<Vec<OcoOrder>>

Get all open OCO orders.

Source

pub async fn limit_buy( &self, symbol: &str, quantity: &str, price: &str, ) -> Result<OrderFull>

Place a limit buy order.

§Arguments
  • symbol - Trading pair symbol
  • quantity - Order quantity
  • price - Limit price
§Example
let client = Binance::new("api_key", "secret_key")?;
let order = client.account().limit_buy("BTCUSDT", "0.001", "50000.00").await?;
Source

pub async fn limit_sell( &self, symbol: &str, quantity: &str, price: &str, ) -> Result<OrderFull>

Place a limit sell order.

§Arguments
  • symbol - Trading pair symbol
  • quantity - Order quantity
  • price - Limit price
§Example
let client = Binance::new("api_key", "secret_key")?;
let order = client.account().limit_sell("BTCUSDT", "0.001", "55000.00").await?;
Source

pub async fn market_buy( &self, symbol: &str, quantity: &str, ) -> Result<OrderFull>

Place a market buy order.

§Arguments
  • symbol - Trading pair symbol
  • quantity - Order quantity
§Example
let client = Binance::new("api_key", "secret_key")?;
let order = client.account().market_buy("BTCUSDT", "0.001").await?;
Source

pub async fn market_sell( &self, symbol: &str, quantity: &str, ) -> Result<OrderFull>

Place a market sell order.

§Arguments
  • symbol - Trading pair symbol
  • quantity - Order quantity
§Example
let client = Binance::new("api_key", "secret_key")?;
let order = client.account().market_sell("BTCUSDT", "0.001").await?;
Source

pub async fn market_buy_quote( &self, symbol: &str, quote_quantity: &str, ) -> Result<OrderFull>

Place a market buy order using quote asset quantity.

This allows you to specify how much of the quote asset (e.g., USDT) to spend.

§Arguments
  • symbol - Trading pair symbol
  • quote_quantity - Amount of quote asset to spend
§Example
let client = Binance::new("api_key", "secret_key")?;
// Spend 100 USDT to buy BTC
let order = client.account().market_buy_quote("BTCUSDT", "100.00").await?;

Trait Implementations§

Source§

impl Clone for Account

Source§

fn clone(&self) -> Account

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

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