pub struct Account {
pub client: Client,
pub recv_window: u64,
}Expand description
Account API access, full example provided in examples/binance_endpoints.rs
Fields§
§client: Client§recv_window: u64Implementations§
Source§impl Account
impl Account
Sourcepub async fn get_account(&self) -> Result<AccountInformation>
pub async fn get_account(&self) -> Result<AccountInformation>
General account information
§Examples
use binance::{api::*, account::*, config::*};
let account: Account = Binance::new_with_env(&Config::testnet());
let account = tokio_test::block_on(account.get_account());
assert!(account.is_ok(), "{:?}", account);Sourcepub async fn get_balance<S>(&self, asset: S) -> Result<Balance>
pub async fn get_balance<S>(&self, asset: S) -> Result<Balance>
Account balance for a single asset
§Examples
use binance::{api::*, account::*, config::*};
let account: Account = Binance::new_with_env(&Config::testnet());
let balance = tokio_test::block_on(account.get_balance("BTC"));
assert!(balance.is_ok(), "{:?}", balance);Sourcepub async fn get_open_orders<S>(&self, symbol: S) -> Result<Vec<Order>>
pub async fn get_open_orders<S>(&self, symbol: S) -> Result<Vec<Order>>
All currently open orders for a single symbol
§Examples
use binance::{api::*, account::*, config::*};
let account: Account = Binance::new_with_env(&Config::testnet());
let orders = tokio_test::block_on(account.get_open_orders("BTCUSDT"));
assert!(orders.is_ok(), "{:?}", orders);Sourcepub async fn get_all_orders(&self, query: OrdersQuery) -> Result<Vec<Order>>
pub async fn get_all_orders(&self, query: OrdersQuery) -> Result<Vec<Order>>
All orders for the account
§Examples
use binance::{api::*, account::*, config::*};
let account: Account = Binance::new_with_env(&Config::testnet());
let query = OrdersQuery {
symbol: "BTCUSDT".to_string(),
order_id: None,
start_time: None,
end_time: None,
limit: None,
recv_window: None,
};
let orders = tokio_test::block_on(account.get_all_orders(query));
assert!(orders.is_ok(), "{:?}", orders);Sourcepub async fn get_all_open_orders(&self) -> Result<Vec<Order>>
pub async fn get_all_open_orders(&self) -> Result<Vec<Order>>
All currently open orders for the account
§Examples
use binance::{api::*, account::*, config::*};
let account: Account = Binance::new_with_env(&Config::testnet());
let orders = tokio_test::block_on(account.get_all_open_orders());
assert!(orders.is_ok(), "{:?}", orders);Sourcepub async fn cancel_all_open_orders<S>(&self, symbol: S) -> Result<Vec<Order>>
pub async fn cancel_all_open_orders<S>(&self, symbol: S) -> Result<Vec<Order>>
Cancels all currently open orders of specified symbol for the account
§Examples
use binance::{api::*, account::*, config::*};
let account: Account = Binance::new_with_env(&Config::testnet());
let canceled_orders = tokio_test::block_on(account.cancel_all_open_orders("ETHBTC"));
assert!(canceled_orders.is_ok(), "{:?}", canceled_orders);Sourcepub async fn order_status(&self, osr: OrderStatusRequest) -> Result<Order>
pub async fn order_status(&self, osr: OrderStatusRequest) -> Result<Order>
Check an order’s status
§Examples
use binance::{api::*, account::*, config::*};
let account: Account = Binance::new_with_env(&Config::testnet());
let query = OrderStatusRequest {
symbol: "BTCUSDT".to_string(),
order_id: Some(1),
orig_client_order_id: Some("my_id".to_string()),
recv_window: None
};
let order = tokio_test::block_on(account.order_status(query));
assert!(order.is_ok(), "{:?}", order);Sourcepub async fn test_order_status(
&self,
osr: OrderStatusRequest,
) -> Result<TestResponse>
pub async fn test_order_status( &self, osr: OrderStatusRequest, ) -> Result<TestResponse>
Place a test status order
This order is sandboxed: it is validated, but not sent to the matching engine.
§Examples
use binance::{api::*, account::*, config::*};
let account: Account = Binance::new_with_env(&Config::testnet());
let query = OrderStatusRequest {
symbol: "BTCUSDT".to_string(),
order_id: Some(1),
orig_client_order_id: Some("my_id".to_string()),
recv_window: None
};
let resp = tokio_test::block_on(account.test_order_status(query));
assert!(resp.is_ok(), "{:?}", resp);Sourcepub async fn place_order(&self, order: OrderRequest) -> Result<Transaction>
pub async fn place_order(&self, order: OrderRequest) -> Result<Transaction>
Place an order Returns the Transaction if Ok This methods validates the order request before sending, making sure it complies with Binance rules
§Examples
use binance::{api::*, account::*, config::*, rest_model::*};
let account: Account = Binance::new_with_env(&Config::testnet());
let limit_buy = OrderRequest {
symbol: "BTCUSDT".to_string(),
quantity: Some(10.0),
price: Some(0.014000),
order_type: OrderType::Limit,
side: OrderSide::Buy,
time_in_force: Some(TimeInForce::FOK),
..OrderRequest::default()
};
let transaction = tokio_test::block_on(account.place_order(limit_buy));
assert!(transaction.is_ok(), "{:?}", transaction);Sourcepub async fn place_test_order(
&self,
order: OrderRequest,
) -> Result<TestResponse>
pub async fn place_test_order( &self, order: OrderRequest, ) -> Result<TestResponse>
Place a test order
Despite being a test, this order is still validated before calls This order is sandboxed: it is validated, but not sent to the matching engine.
§Examples
use binance::{api::*, account::*, config::*, rest_model::*};
let account: Account = Binance::new_with_env(&Config::testnet());
let limit_buy = OrderRequest {
symbol: "BTCUSDT".to_string(),
quantity: Some(10.0),
price: Some(0.014000),
order_type: OrderType::Limit,
side: OrderSide::Buy,
time_in_force: Some(TimeInForce::FOK),
..OrderRequest::default()
};
let resp = tokio_test::block_on(account.place_test_order(limit_buy));
assert!(resp.is_ok(), "{:?}", resp);Sourcepub async fn cancel_order(&self, o: OrderCancellation) -> Result<OrderCanceled>
pub async fn cancel_order(&self, o: OrderCancellation) -> Result<OrderCanceled>
Place a cancellation order
§Examples
use binance::{api::*, account::*, config::*};
let account: Account = Binance::new_with_env(&Config::testnet());
let query = OrderCancellation {
symbol: "BTCUSDT".to_string(),
order_id: Some(1),
orig_client_order_id: Some("my_id".to_string()),
new_client_order_id: None,
recv_window: None
};
let canceled = tokio_test::block_on(account.cancel_order(query));
assert!(canceled.is_ok(), "{:?}", canceled);pub async fn cancel_replace_order( &self, order: CancelReplaceRequest, ) -> Result<OrderCanceledReplaced>
Sourcepub async fn test_cancel_order(
&self,
o: OrderCancellation,
) -> Result<TestResponse>
pub async fn test_cancel_order( &self, o: OrderCancellation, ) -> Result<TestResponse>
Place a test cancel order
This order is sandboxed: it is validated, but not sent to the matching engine.
§Examples
use binance::{api::*, account::*, config::*};
let account: Account = Binance::new_with_env(&Config::testnet());
let query = OrderCancellation {
symbol: "BTCUSDT".to_string(),
order_id: Some(1),
orig_client_order_id: Some("my_id".to_string()),
new_client_order_id: None,
recv_window: None
};
let response = tokio_test::block_on(account.test_cancel_order(query));
assert!(response.is_ok(), "{:?}", response);Sourcepub async fn trade_history<S>(&self, symbol: S) -> Result<Vec<TradeHistory>>
pub async fn trade_history<S>(&self, symbol: S) -> Result<Vec<TradeHistory>>
Trade history
§Examples
use binance::{api::*, account::*, config::*};
let account: Account = Binance::new_with_env(&Config::testnet());
let trade_history = tokio_test::block_on(account.trade_history("BTCUSDT"));
assert!(trade_history.is_ok(), "{:?}", trade_history);