Struct binance::margin::Margin[][src]

pub struct Margin {
    pub client: Client,
    pub recv_window: u64,
}

Fields

client: Clientrecv_window: u64

Implementations

Execute transfer between spot account and margin account.

Examples

use binance::{api::*, margin::*, config::*, rest_model::*};
let margin: Margin = Binance::new_with_env(&Config::testnet());
let transaction_id = tokio_test::block_on(margin.transfer("BTCUSDT", 0.001, MarginTransferType::FromMainToMargin));
assert!(transaction_id.is_ok(), "{:?}", transaction_id);

Apply for a loan.

Examples

use binance::{api::*, margin::*, config::*, rest_model::*};
let margin: Margin = Binance::new_with_env(&Config::testnet());
let transaction_id = tokio_test::block_on(margin.loan("BTCUSDT", 0.001));
assert!(transaction_id.is_ok(), "{:?}", transaction_id);

Repay loan for margin account.

use binance::{api::*, margin::*, config::*, rest_model::*};
let margin: Margin = Binance::new_with_env(&Config::testnet());
let transaction_id = tokio_test::block_on(margin.repay("BTCUSDT", 0.001));
assert!(transaction_id.is_ok(), "{:?}", transaction_id);

Post a new order for margin account.

Examples

use binance::{api::*, margin::*, config::*, rest_model::*};
let margin: Margin = Binance::new_with_env(&Config::testnet());
let margin_order = MarginOrder {
    symbol: "BTCUSDT".to_string(),
    side: OrderSide::Sell,
    order_type: OrderType::Limit,
    quantity: 0.001,
    price: 10.0,
    stop_price: 10.0,
    new_client_order_id: "my_id".to_string(),
    iceberg_qty: 10.0,
    new_order_resp_type: OrderResponse::Ack,
    time_in_force: TimeInForce::FOK
};
let transaction_id = tokio_test::block_on(margin.trade(margin_order));
assert!(transaction_id.is_ok(), "{:?}", transaction_id);

Cancel an existing order

Examples

use binance::{api::*, margin::*, config::*, rest_model::*};
let margin: Margin = Binance::new_with_env(&Config::testnet());
let transaction_id = tokio_test::block_on(margin.cancel_trade("BTCUSDT", 1_u64, "my_id".to_string(), "my_next_id".to_string()));
assert!(transaction_id.is_ok(), "{:?}", transaction_id);

Get existing loan records

Examples

use binance::{api::*, margin::*, config::*, rest_model::*};
let margin: Margin = Binance::new_with_env(&Config::testnet());
let loan_query = RecordsQuery {
   asset: "BTC".to_string(),
   tx_id: None,
   start_time: None,
   end_time: None,
   current: None,
   size: None,
   transfer_type: Some(TransferType::RollIn)
};
let records = tokio_test::block_on(margin.loans(loan_query));
assert!(records.is_ok(), "{:?}", records);

Get existing repay records history

Examples

use binance::{api::*, margin::*, config::*, rest_model::*};
let margin: Margin = Binance::new_with_env(&Config::testnet());
let records_query = RecordsQuery {
   asset: "BTC".to_string(),
   tx_id: None,
   start_time: None,
   end_time: None,
   current: None,
   size: None,
   transfer_type: Some(TransferType::RollIn)
};
let records = tokio_test::block_on(margin.repays(records_query));
assert!(records.is_ok(), "{:?}", records);

Get margin account details

Examples

use binance::{api::*, margin::*, config::*, rest_model::*};
let margin: Margin = Binance::new_with_env(&Config::testnet());
let account_details = tokio_test::block_on(margin.details());
assert!(account_details.is_ok(), "{:?}", account_details);

Get asset details

Examples

use binance::{api::*, margin::*, config::*, rest_model::*};
let margin: Margin = Binance::new_with_env(&Config::testnet());
let asset_detail = tokio_test::block_on(margin.asset("BTC"));
assert!(asset_detail.is_ok(), "{:?}", asset_detail);

Get margin pair market data

Examples

use binance::{api::*, margin::*, config::*, rest_model::*};
let margin: Margin = Binance::new_with_env(&Config::testnet());
let pair_details = tokio_test::block_on(margin.pair("BTCUSDT"));
assert!(pair_details.is_ok(), "{:?}", pair_details);

Get all assets details

Examples

use binance::{api::*, margin::*, config::*, rest_model::*};
let margin: Margin = Binance::new_with_env(&Config::testnet());
let all_assets = tokio_test::block_on(margin.all_assets());
assert!(all_assets.is_ok(), "{:?}", all_assets);

Get all pair details

Examples

use binance::{api::*, margin::*, config::*, rest_model::*};
let margin: Margin = Binance::new_with_env(&Config::testnet());
let all_pairs = tokio_test::block_on(margin.all_pairs());
assert!(all_pairs.is_ok(), "{:?}", all_pairs);

Get price index

Examples

use binance::{api::*, margin::*, config::*, rest_model::*};
let margin: Margin = Binance::new_with_env(&Config::testnet());
let price_index = tokio_test::block_on(margin.price_index("BTCUSDT"));
assert!(price_index.is_ok(), "{:?}", price_index);

Get transfer history

Examples

use binance::{api::*, margin::*, config::*, rest_model::*};
let margin: Margin = Binance::new_with_env(&Config::testnet());
let records_query = RecordsQuery {
   asset: "BTC".to_string(),
   tx_id: None,
   start_time: None,
   end_time: None,
   current: None,
   size: None,
   transfer_type: Some(TransferType::RollIn)
};
let records = tokio_test::block_on(margin.transfers(records_query));
assert!(records.is_ok(), "{:?}", records);

Get interest history

Examples

use binance::{api::*, margin::*, config::*, rest_model::*};
let margin: Margin = Binance::new_with_env(&Config::testnet());
let records_query = RecordsQuery {
   asset: "BTC".to_string(),
   tx_id: None,
   start_time: None,
   end_time: None,
   current: None,
   size: None,
   transfer_type: Some(TransferType::RollIn)
};
let records = tokio_test::block_on(margin.interests(records_query));
assert!(records.is_ok(), "{:?}", records);

Get forced liquidation history

Examples

use binance::{api::*, margin::*, config::*, rest_model::*};
let margin: Margin = Binance::new_with_env(&Config::testnet());
let records_query = RecordsQuery {
   asset: "BTC".to_string(),
   tx_id: None,
   start_time: None,
   end_time: None,
   current: None,
   size: None,
   transfer_type: Some(TransferType::RollIn)
};
let records = tokio_test::block_on(margin.forced_liquidations(records_query));
assert!(records.is_ok(), "{:?}", records);

Get an existing order state

Examples

use binance::{api::*, margin::*, config::*, rest_model::*};
let margin: Margin = Binance::new_with_env(&Config::testnet());
let records_query = MarginOrderQuery {
    symbol: "BTCUSDT".to_string(),
    order_id: "1".to_string(),
    orig_client_order_id: "my_id".to_string(),
};
let records = tokio_test::block_on(margin.order(records_query));
assert!(records.is_ok(), "{:?}", records);

Get open orders

Examples

use binance::{api::*, margin::*, config::*, rest_model::*};
let margin: Margin = Binance::new_with_env(&Config::testnet());
let order_state = tokio_test::block_on(margin.open_orders("BTCUSDT"));
assert!(order_state.is_ok(), "{:?}", order_state);

Get all orders

Examples

use binance::{api::*, margin::*, config::*, rest_model::*};
let margin: Margin = Binance::new_with_env(&Config::testnet());
let records_query = RecordsQuery {
   asset: "BTC".to_string(),
   tx_id: None,
   start_time: None,
   end_time: None,
   current: None,
   size: None,
   transfer_type: Some(TransferType::RollIn)
};
let records = tokio_test::block_on(margin.orders(records_query));
assert!(records.is_ok(), "{:?}", records);

Get all trades

Examples

use binance::{api::*, margin::*, config::*, rest_model::*};
let margin: Margin = Binance::new_with_env(&Config::testnet());
let records_query = RecordsQuery {
   asset: "BTC".to_string(),
   tx_id: None,
   start_time: None,
   end_time: None,
   current: None,
   size: None,
   transfer_type: Some(TransferType::RollIn)
};
let records = tokio_test::block_on(margin.trades(records_query));
assert!(records.is_ok(), "{:?}", records);

Get max borrowable

Examples

use binance::{api::*, margin::*, config::*, rest_model::*};
let margin: Margin = Binance::new_with_env(&Config::testnet());
let max = tokio_test::block_on(margin.max_borrowable("BTC"));
assert!(max.is_ok(), "{:?}", max);

Get max transferable

Examples

use binance::{api::*, margin::*, config::*, rest_model::*};
let margin: Margin = Binance::new_with_env(&Config::testnet());
let max = tokio_test::block_on(margin.max_transferable("BTC"));
assert!(max.is_ok(), "{:?}", max);

Start user data stream

Examples

use binance::{api::*, margin::*, config::*};
let margin: Margin = Binance::new_with_env(&Config::testnet());
let start = tokio_test::block_on(margin.start());
assert!(start.is_ok(), "{:?}", start);
assert!(start.unwrap().listen_key.len() > 0)

Current open orders on a symbol

Examples

use binance::{api::*, margin::*, config::*};
let margin: Margin = Binance::new_with_env(&Config::testnet());
let start = tokio_test::block_on(margin.start());
assert!(start.is_ok(), "{:?}", start);
let keep_alive = tokio_test::block_on(margin.keep_alive(&start.unwrap().listen_key));
assert!(keep_alive.is_ok())

Close the user stream

Examples

use binance::{api::*, margin::*, config::*};
let margin: Margin = Binance::new_with_env(&Config::testnet());
let start = tokio_test::block_on(margin.start());
assert!(start.is_ok(), "{:?}", start);
let close = tokio_test::block_on(margin.close(&start.unwrap().listen_key));
assert!(close.is_ok())

Trait Implementations

Create a binance API using environment variables for credentials BINANCE_API_KEY= BINANCE_API_SECRET_KEY= Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

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

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.