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
impl Account
Sourcepub async fn get_account(&self) -> Result<AccountInfo>
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);
}
}Sourcepub 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>>
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 symbolfrom_id- Trade ID to fetch fromstart_time- Start time in millisecondsend_time- End time in millisecondslimit- 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?;Sourcepub 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>>
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 symbolprevented_match_id- Prevented match IDorder_id- Order IDfrom_prevented_match_id- Start from prevented match IDlimit- Max number of entries (default 500, max 1000)
Sourcepub 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>>
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 symbolstart_time- Start time in millisecondsend_time- End time in millisecondsfrom_allocation_id- Allocation ID to fetch fromlimit- Max number of entries (default 500, max 1000)order_id- Optional order ID to filter
Sourcepub async fn commission_rates(&self, symbol: &str) -> Result<AccountCommission>
pub async fn commission_rates(&self, symbol: &str) -> Result<AccountCommission>
Sourcepub async fn unfilled_order_count(&self) -> Result<Vec<UnfilledOrderCount>>
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);
}Sourcepub async fn order_amendments(
&self,
symbol: &str,
order_id: u64,
from_execution_id: Option<u64>,
limit: Option<u32>,
) -> Result<Vec<OrderAmendment>>
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 symbolorder_id- Order ID to query amendments forfrom_execution_id- Optional execution ID to start fromlimit- 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);
}Sourcepub async fn create_order(&self, order: &NewOrder) -> Result<OrderFull>
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?;Sourcepub async fn test_order(&self, order: &NewOrder) -> Result<()>
pub async fn test_order(&self, order: &NewOrder) -> Result<()>
Sourcepub 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>
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 symbolorder_id- Order ID to amend (either order_id or orig_client_order_id required)orig_client_order_id- Client order ID to amendnew_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);Sourcepub async fn cancel_replace_order(
&self,
request: &CancelReplaceOrder,
) -> Result<CancelReplaceResponse>
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);Sourcepub async fn create_sor_order(&self, order: &NewOrder) -> Result<OrderFull>
pub async fn create_sor_order(&self, order: &NewOrder) -> Result<OrderFull>
Place an order using smart order routing (SOR).
Sourcepub async fn test_sor_order(
&self,
order: &NewOrder,
compute_commission_rates: bool,
) -> Result<SorOrderTestResponse>
pub async fn test_sor_order( &self, order: &NewOrder, compute_commission_rates: bool, ) -> Result<SorOrderTestResponse>
Test a new SOR order without executing it.
Sourcepub async fn get_order(
&self,
symbol: &str,
order_id: Option<u64>,
client_order_id: Option<&str>,
) -> Result<Order>
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 symbolorder_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);Sourcepub async fn cancel_order(
&self,
symbol: &str,
order_id: Option<u64>,
client_order_id: Option<&str>,
) -> Result<CancelOrderResponse>
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 symbolorder_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);Sourcepub async fn open_orders(&self, symbol: Option<&str>) -> Result<Vec<Order>>
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?;Sourcepub async fn cancel_all_orders(
&self,
symbol: &str,
) -> Result<Vec<CancelOrderResponse>>
pub async fn cancel_all_orders( &self, symbol: &str, ) -> Result<Vec<CancelOrderResponse>>
Sourcepub 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>>
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 symbolorder_id- If set, get orders >= this order IDstart_time- Start time in millisecondsend_time- End time in millisecondslimit- 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?;Sourcepub async fn create_oco(&self, order: &NewOcoOrder) -> Result<OcoOrder>
pub async fn create_oco(&self, order: &NewOcoOrder) -> Result<OcoOrder>
Sourcepub async fn create_oto(&self, order: &NewOtoOrder) -> Result<OcoOrder>
pub async fn create_oto(&self, order: &NewOtoOrder) -> Result<OcoOrder>
Create a new OTO (One-Triggers-the-Other) order list.
Sourcepub async fn create_otoco(&self, order: &NewOtocoOrder) -> Result<OcoOrder>
pub async fn create_otoco(&self, order: &NewOtocoOrder) -> Result<OcoOrder>
Create a new OTOCO (One-Triggers-One-Cancels-the-Other) order list.
Sourcepub async fn create_opo(&self, order: &NewOpoOrder) -> Result<OcoOrder>
pub async fn create_opo(&self, order: &NewOpoOrder) -> Result<OcoOrder>
Create a new OPO (One-Places-the-Other) order list.
Sourcepub async fn create_opoco(&self, order: &NewOpocoOrder) -> Result<OcoOrder>
pub async fn create_opoco(&self, order: &NewOpocoOrder) -> Result<OcoOrder>
Create a new OPOCO (One-Places-One-Cancels-the-Other) order list.
Sourcepub async fn get_order_list(
&self,
order_list_id: Option<u64>,
client_order_list_id: Option<&str>,
) -> Result<OcoOrder>
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).
Sourcepub async fn cancel_order_list(
&self,
symbol: &str,
order_list_id: Option<u64>,
client_order_list_id: Option<&str>,
) -> Result<OcoOrder>
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).
Sourcepub async fn all_order_lists(
&self,
from_id: Option<u64>,
start_time: Option<u64>,
end_time: Option<u64>,
limit: Option<u32>,
) -> Result<Vec<OcoOrder>>
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).
Sourcepub async fn open_order_lists(&self) -> Result<Vec<OcoOrder>>
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).
Sourcepub async fn get_oco(
&self,
order_list_id: Option<u64>,
client_order_list_id: Option<&str>,
) -> Result<OcoOrder>
pub async fn get_oco( &self, order_list_id: Option<u64>, client_order_list_id: Option<&str>, ) -> Result<OcoOrder>
Sourcepub async fn cancel_oco(
&self,
symbol: &str,
order_list_id: Option<u64>,
client_order_list_id: Option<&str>,
) -> Result<OcoOrder>
pub async fn cancel_oco( &self, symbol: &str, order_list_id: Option<u64>, client_order_list_id: Option<&str>, ) -> Result<OcoOrder>
Sourcepub async fn all_oco(
&self,
from_id: Option<u64>,
start_time: Option<u64>,
end_time: Option<u64>,
limit: Option<u32>,
) -> Result<Vec<OcoOrder>>
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 IDstart_time- Start time in millisecondsend_time- End time in millisecondslimit- Max number of orders (default 500, max 1000)
Sourcepub async fn limit_buy(
&self,
symbol: &str,
quantity: &str,
price: &str,
) -> Result<OrderFull>
pub async fn limit_buy( &self, symbol: &str, quantity: &str, price: &str, ) -> Result<OrderFull>
Sourcepub async fn limit_sell(
&self,
symbol: &str,
quantity: &str,
price: &str,
) -> Result<OrderFull>
pub async fn limit_sell( &self, symbol: &str, quantity: &str, price: &str, ) -> Result<OrderFull>
Sourcepub async fn market_buy_quote(
&self,
symbol: &str,
quote_quantity: &str,
) -> Result<OrderFull>
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 symbolquote_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?;