Skip to main content

Margin

Struct Margin 

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

Margin Trading API client.

Provides access to Binance Margin SAPI endpoints for margin trading, loans, transfers, and account management.

§Example

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

// Get cross-margin account details
let account = client.margin().account().await?;
println!("Margin level: {}", account.margin_level);

// Check max borrowable
let max = client.margin().max_borrowable("BTC", None).await?;
println!("Max borrowable BTC: {}", max.amount);

Implementations§

Source§

impl Margin

Source

pub async fn account(&self) -> Result<MarginAccountDetails>

Get cross-margin account details.

Returns margin account information including balances, margin level, and trading status.

§Example
let account = client.margin().account().await?;
println!("Margin level: {}", account.margin_level);
println!("Total assets (BTC): {}", account.total_asset_of_btc);
for asset in account.user_assets {
    if asset.net_asset > 0.0 {
        println!("{}: free={}, borrowed={}", asset.asset, asset.free, asset.borrowed);
    }
}
Source

pub async fn isolated_account( &self, symbols: Option<&str>, ) -> Result<IsolatedMarginAccountDetails>

Get isolated margin account details.

§Arguments
  • symbols - Optional list of symbols to filter (comma-separated if multiple)
§Example
let account = client.margin().isolated_account(Some("BTCUSDT")).await?;
for asset in account.assets {
    println!("{}: margin_level={}", asset.symbol, asset.margin_level);
}
Source

pub async fn max_borrowable( &self, asset: &str, isolated_symbol: Option<&str>, ) -> Result<MaxBorrowableAmount>

Get max borrowable amount for an asset.

§Arguments
  • asset - Asset to query
  • isolated_symbol - Isolated margin symbol (for isolated margin)
§Example
let max = client.margin().max_borrowable("BTC", None).await?;
println!("Max borrowable: {} BTC", max.amount);
Source

pub async fn max_transferable( &self, asset: &str, isolated_symbol: Option<&str>, ) -> Result<MaxTransferableAmount>

Get max transferable amount for an asset.

§Arguments
  • asset - Asset to query
  • isolated_symbol - Isolated margin symbol (for isolated margin)
§Example
let max = client.margin().max_transferable("USDT", None).await?;
println!("Max transferable: {} USDT", max.amount);
Source

pub async fn isolated_account_limit(&self) -> Result<IsolatedAccountLimit>

Get isolated margin account limit.

§Example
let limit = client.margin().isolated_account_limit().await?;
println!("Enabled: {}, Max: {}", limit.enabled_account, limit.max_account);
Source

pub async fn transfer( &self, asset: &str, amount: &str, transfer_type: MarginTransferType, ) -> Result<TransactionId>

Execute a cross-margin transfer between spot and margin accounts.

§Arguments
  • asset - Asset to transfer
  • amount - Amount to transfer
  • transfer_type - Direction of transfer
§Example
use binance_api_client::MarginTransferType;

// Transfer 100 USDT from spot to margin
let result = client.margin()
    .transfer("USDT", "100.0", MarginTransferType::MainToMargin)
    .await?;
println!("Transfer ID: {}", result.tran_id);
Source

pub async fn isolated_transfer( &self, asset: &str, symbol: &str, amount: &str, trans_from: IsolatedMarginTransferType, trans_to: IsolatedMarginTransferType, ) -> Result<TransactionId>

Execute an isolated margin transfer.

§Arguments
  • asset - Asset to transfer
  • symbol - Isolated margin symbol
  • amount - Amount to transfer
  • trans_from - Source account type
  • trans_to - Destination account type
§Example
use binance_api_client::IsolatedMarginTransferType;

// Transfer 100 USDT from spot to BTCUSDT isolated margin
let result = client.margin()
    .isolated_transfer(
        "USDT",
        "BTCUSDT",
        "100.0",
        IsolatedMarginTransferType::Spot,
        IsolatedMarginTransferType::IsolatedMargin,
    )
    .await?;
Source

pub async fn loan( &self, asset: &str, amount: &str, is_isolated: bool, symbol: Option<&str>, ) -> Result<TransactionId>

Apply for a margin loan.

§Arguments
  • asset - Asset to borrow
  • amount - Amount to borrow
  • is_isolated - Whether this is isolated margin
  • symbol - Symbol for isolated margin (required if is_isolated is true)
§Example
// Borrow 0.1 BTC on cross margin
let result = client.margin().loan("BTC", "0.1", false, None).await?;
println!("Loan transaction ID: {}", result.tran_id);
Source

pub async fn repay( &self, asset: &str, amount: &str, is_isolated: bool, symbol: Option<&str>, ) -> Result<TransactionId>

Repay a margin loan.

§Arguments
  • asset - Asset to repay
  • amount - Amount to repay
  • is_isolated - Whether this is isolated margin
  • symbol - Symbol for isolated margin (required if is_isolated is true)
§Example
// Repay 0.1 BTC on cross margin
let result = client.margin().repay("BTC", "0.1", false, None).await?;
println!("Repay transaction ID: {}", result.tran_id);
Source

pub async fn loan_records( &self, asset: &str, isolated_symbol: Option<&str>, start_time: Option<u64>, end_time: Option<u64>, current: Option<u32>, size: Option<u32>, ) -> Result<RecordsQueryResult<LoanRecord>>

Get loan records.

§Arguments
  • asset - Asset to query
  • isolated_symbol - Isolated margin symbol (optional)
  • start_time - Start timestamp (optional)
  • end_time - End timestamp (optional)
  • current - Page number (default 1)
  • size - Page size (default 10, max 100)
§Example
let records = client.margin()
    .loan_records("BTC", None, None, None, None, Some(20))
    .await?;
for record in records.rows {
    println!("Loan: {} {} at {}", record.principal, record.asset, record.timestamp);
}
Source

pub async fn repay_records( &self, asset: &str, isolated_symbol: Option<&str>, start_time: Option<u64>, end_time: Option<u64>, current: Option<u32>, size: Option<u32>, ) -> Result<RecordsQueryResult<RepayRecord>>

Get repay records.

§Arguments
  • asset - Asset to query
  • isolated_symbol - Isolated margin symbol (optional)
  • start_time - Start timestamp (optional)
  • end_time - End timestamp (optional)
  • current - Page number (default 1)
  • size - Page size (default 10, max 100)
Source

pub async fn create_order( &self, symbol: &str, side: OrderSide, order_type: OrderType, quantity: Option<&str>, quote_order_qty: Option<&str>, price: Option<&str>, stop_price: Option<&str>, time_in_force: Option<TimeInForce>, new_client_order_id: Option<&str>, side_effect_type: Option<SideEffectType>, is_isolated: Option<bool>, ) -> Result<MarginOrderResult>

Create a new margin order.

§Arguments
  • symbol - Trading pair symbol
  • side - Order side (Buy/Sell)
  • order_type - Order type
  • quantity - Order quantity (optional for some order types)
  • quote_order_qty - Quote order quantity (optional)
  • price - Price (required for limit orders)
  • stop_price - Stop price (for stop orders)
  • time_in_force - Time in force (optional)
  • new_client_order_id - Client order ID (optional)
  • side_effect_type - Side effect type (optional)
  • is_isolated - Whether isolated margin (optional)
§Example
use binance_api_client::{OrderSide, OrderType, TimeInForce, SideEffectType};

let order = client.margin().create_order(
    "BTCUSDT",
    OrderSide::Buy,
    OrderType::Limit,
    Some("0.001"),
    None,
    Some("50000.00"),
    None,
    Some(TimeInForce::GTC),
    None,
    Some(SideEffectType::MarginBuy),
    None,
).await?;
Source

pub async fn cancel_order( &self, symbol: &str, order_id: Option<u64>, orig_client_order_id: Option<&str>, is_isolated: Option<bool>, ) -> Result<MarginOrderCancellation>

Cancel a margin order.

§Arguments
  • symbol - Trading pair symbol
  • order_id - Order ID (optional if orig_client_order_id provided)
  • orig_client_order_id - Original client order ID (optional if order_id provided)
  • is_isolated - Whether isolated margin
§Example
let result = client.margin()
    .cancel_order("BTCUSDT", Some(12345), None, None)
    .await?;
Source

pub async fn cancel_all_orders( &self, symbol: &str, is_isolated: Option<bool>, ) -> Result<Vec<MarginOrderCancellation>>

Cancel all open orders on a symbol.

§Arguments
  • symbol - Trading pair symbol
  • is_isolated - Whether isolated margin
§Example
let results = client.margin()
    .cancel_all_orders("BTCUSDT", None)
    .await?;
Source

pub async fn get_order( &self, symbol: &str, order_id: Option<u64>, orig_client_order_id: Option<&str>, is_isolated: Option<bool>, ) -> Result<MarginOrderState>

Query a margin order.

§Arguments
  • symbol - Trading pair symbol
  • order_id - Order ID (optional)
  • orig_client_order_id - Original client order ID (optional)
  • is_isolated - Whether isolated margin
Source

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

Get all open margin orders.

§Arguments
  • symbol - Trading pair symbol (optional)
  • is_isolated - Whether isolated margin
Source

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

Get all margin orders (active, cancelled, or filled).

§Arguments
  • symbol - Trading pair symbol
  • order_id - Order ID to start from (optional)
  • start_time - Start timestamp (optional)
  • end_time - End timestamp (optional)
  • limit - Number of records (default 500, max 500)
  • is_isolated - Whether isolated margin
Source

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

Get margin trades.

§Arguments
  • symbol - Trading pair symbol
  • order_id - Filter by order ID (optional)
  • start_time - Start timestamp (optional)
  • end_time - End timestamp (optional)
  • from_id - Trade ID to start from (optional)
  • limit - Number of records (default 500, max 1000)
  • is_isolated - Whether isolated margin
Source

pub async fn interest_history( &self, asset: Option<&str>, isolated_symbol: Option<&str>, start_time: Option<u64>, end_time: Option<u64>, current: Option<u32>, size: Option<u32>, ) -> Result<RecordsQueryResult<InterestHistoryRecord>>

Get interest history.

§Arguments
  • asset - Asset to query (optional)
  • isolated_symbol - Isolated margin symbol (optional)
  • start_time - Start timestamp (optional)
  • end_time - End timestamp (optional)
  • current - Page number (default 1)
  • size - Page size (default 10, max 100)
Source

pub async fn interest_rate_history( &self, asset: &str, vip_level: Option<u32>, start_time: Option<u64>, end_time: Option<u64>, limit: Option<u32>, ) -> Result<Vec<InterestRateRecord>>

Get interest rate history.

§Arguments
  • asset - Asset to query
  • vip_level - VIP level (optional, default uses user’s vip level)
  • start_time - Start timestamp (optional)
  • end_time - End timestamp (optional)
  • limit - Number of records (default 20, max 100)
Source

pub async fn pair(&self, symbol: &str) -> Result<MarginPairDetails>

Get cross margin pair details.

§Arguments
  • symbol - Trading pair symbol
Source

pub async fn all_pairs(&self) -> Result<Vec<MarginPairDetails>>

Get all cross margin pairs.

Source

pub async fn asset(&self, asset: &str) -> Result<MarginAssetInfo>

Get margin asset info.

§Arguments
  • asset - Asset symbol
Source

pub async fn all_assets(&self) -> Result<Vec<MarginAssetInfo>>

Get all margin assets info.

Source

pub async fn price_index(&self, symbol: &str) -> Result<MarginPriceIndex>

Get margin price index for a symbol.

§Arguments
  • symbol - Trading pair symbol
Source

pub async fn bnb_burn_status(&self) -> Result<BnbBurnStatus>

Get BNB burn status for spot trading and margin interest.

Source

pub async fn toggle_bnb_burn( &self, spot_bnb_burn: Option<bool>, interest_bnb_burn: Option<bool>, ) -> Result<BnbBurnStatus>

Toggle BNB burn on spot trade and margin interest.

§Arguments
  • spot_bnb_burn - Enable BNB for spot trading fees (optional)
  • interest_bnb_burn - Enable BNB for margin interest (optional)

Trait Implementations§

Source§

impl Clone for Margin

Source§

fn clone(&self) -> Margin

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§

§

impl Freeze for Margin

§

impl !RefUnwindSafe for Margin

§

impl Send for Margin

§

impl Sync for Margin

§

impl Unpin for Margin

§

impl !UnwindSafe for Margin

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