Struct binance::margin::Margin [−][src]
pub struct Margin { pub client: Client, pub recv_window: u64, }
Fields
client: Client
recv_window: u64
Implementations
pub async fn transfer<S, F>(
&self,
symbol: S,
qty: F,
transfer_type: MarginTransferType
) -> Result<TransactionId> where
S: Into<String>,
F: Into<f64>,
pub async fn transfer<S, F>(
&self,
symbol: S,
qty: F,
transfer_type: MarginTransferType
) -> Result<TransactionId> where
S: Into<String>,
F: Into<f64>,
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);
pub async fn cancel_trade<S, F>(
&self,
symbol: S,
order_id: F,
orig_client_order_id: String,
new_client_order_id: String
) -> Result<TransactionId> where
S: Into<String>,
F: Into<u64>,
pub async fn cancel_trade<S, F>(
&self,
symbol: S,
order_id: F,
orig_client_order_id: String,
new_client_order_id: String
) -> Result<TransactionId> where
S: Into<String>,
F: Into<u64>,
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);
pub async fn repays(
&self,
repays_query: RecordsQuery
) -> Result<RecordsQueryResult<RepayState>>
pub async fn repays(
&self,
repays_query: RecordsQuery
) -> Result<RecordsQueryResult<RepayState>>
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);
pub async fn transfers(
&self,
transfers_query: RecordsQuery
) -> Result<RecordsQueryResult<OrderState>>
pub async fn transfers(
&self,
transfers_query: RecordsQuery
) -> Result<RecordsQueryResult<OrderState>>
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);
pub async fn interests(
&self,
interest_query: RecordsQuery
) -> Result<RecordsQueryResult<InterestState>>
pub async fn interests(
&self,
interest_query: RecordsQuery
) -> Result<RecordsQueryResult<InterestState>>
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);
pub async fn forced_liquidations(
&self,
forced_liquidations_query: RecordsQuery
) -> Result<RecordsQueryResult<ForcedLiquidationState>>
pub async fn forced_liquidations(
&self,
forced_liquidations_query: RecordsQuery
) -> Result<RecordsQueryResult<ForcedLiquidationState>>
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);
pub async fn open_orders<S>(&self, symbol: S) -> Result<MarginOrderState> where
S: Into<String>,
pub async fn open_orders<S>(&self, symbol: S) -> Result<MarginOrderState> where
S: Into<String>,
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);
pub async fn orders(
&self,
all_orders_query: RecordsQuery
) -> Result<RecordsQueryResult<OrderSumaryState>>
pub async fn orders(
&self,
all_orders_query: RecordsQuery
) -> Result<RecordsQueryResult<OrderSumaryState>>
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);
pub async fn trades(
&self,
all_orders_query: RecordsQuery
) -> Result<RecordsQueryResult<OwnTradesState>>
pub async fn trades(
&self,
all_orders_query: RecordsQuery
) -> Result<RecordsQueryResult<OwnTradesState>>
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
Auto Trait Implementations
impl !RefUnwindSafe for Margin
impl !UnwindSafe for Margin
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
type Output = T
type Output = T
Should always be Self