Account

Struct Account 

Source
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: u64

Implementations§

Source§

impl Account

Source

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);
Source

pub async fn get_balance<S>(&self, asset: S) -> Result<Balance>
where S: Into<String>,

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);
Source

pub async fn get_open_orders<S>(&self, symbol: S) -> Result<Vec<Order>>
where S: AsRef<str>,

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);
Source

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);
Source

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);
Source

pub async fn cancel_all_open_orders<S>(&self, symbol: S) -> Result<Vec<Order>>
where S: AsRef<str>,

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

pub async fn cancel_replace_order( &self, order: CancelReplaceRequest, ) -> Result<OrderCanceledReplaced>

Source

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);
Source

pub async fn trade_history<S>(&self, symbol: S) -> Result<Vec<TradeHistory>>
where S: AsRef<str>,

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);

Trait Implementations§

Source§

impl Binance for Account

Source§

fn new_with_config( api_key: Option<String>, secret_key: Option<String>, config: &Config, ) -> Account

Source§

fn new(api_key: Option<String>, secret_key: Option<String>) -> Self

Source§

fn new_with_env(config: &Config) -> Self

Create a binance API using environment variables for credentials BINANCE_API_KEY=$YOUR_API_KEY BINANCE_API_SECRET_KEY=$YOUR_SECRET_KEY
Source§

impl Clone for Account

Source§

fn clone(&self) -> Account

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§

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> 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