Struct binance::account::Account[][src]

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

Implementations

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

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

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

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

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

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());
assert!(canceled_orders.is_ok(), "{:?}", canceled_orders);

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

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

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

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

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

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

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

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.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more