AccountClient

Struct AccountClient 

Source
pub struct AccountClient { /* private fields */ }
Expand description

Client for dealing with orders

Implementations§

Source§

impl AccountClient

Source

pub fn connect<A, S, U>(api_key: A, secret_key: S, url: U) -> Result<Self>
where A: Into<String>, S: Into<String>, U: Into<String>,

Creates new client instance.

§Example
use tokio_binance::{AccountClient, BINANCE_US_URL};
 
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = AccountClient::connect("<api-key>", "<secret-key>", BINANCE_US_URL)?;
    Ok(())
}
Source

pub fn place_limit_order<'a>( &self, symbol: &'a str, side: Side, price: f64, quantity: f64, execute: bool, ) -> ParamBuilder<'a, '_, LimitOrderParams>

Place a new limit order.

§Example
use tokio_binance::{Side::Sell, TimeInForce::Fok, OrderRespType::Full};
use serde_json::Value;
 
let response = client
    // false will send as test, true will send as a real order.
    .place_limit_order("BNBUSDT", Sell, 20.00, 5.00, false)
    // optional: lifetime of order; default is Gtc.
    .with_time_in_force(Fok)
    // optional: unique id; auto generated by default.
    .with_new_client_order_id("<uuid>")
    // optional: splits quantity; sets time in force to Gtc.
    .with_iceberg_qty(1.00)
    // optional: output verbosity; default is Ack.
    .with_new_order_resp_type(Full)
    // optional: converts Limit to Stop-Limit; triggers when price hits below 21.00.
    .with_stop_loss_limit(21.00)
    // optional: converts Limit to Stop-Limit; triggers when price hits above 21.00.
    .with_take_profit_limit(21.00)
    // optional: processing time for request; default is 5000, can't be above 60000.
    .with_recv_window(8000)
    // optional: converts Limit to Limit-Maker; consumes builder and returns a different one.
    .into_limit_maker_order()
    //
    .json::<Value>()
    .await?;
Source

pub fn place_market_order<'a>( &self, symbol: &'a str, side: Side, quantity: f64, execute: bool, ) -> ParamBuilder<'a, '_, MarketOrderParams>

Place a new market order.

§Example
use tokio_binance::{Side::Sell, TimeInForce::Fok, OrderRespType::Full};
use serde_json::Value;
 
let response = client
    // false will send as test, true will send as a real order.
    .place_market_order("BNBUSDT", Sell, 5.00, false)
    // optional: unique id; auto generated by default.
    .with_new_client_order_id("<uuid>")
    // optional: output verbosity; default is Ack.
    .with_new_order_resp_type(Full)
    // optional: converts Market to Stop-Loss; triggers when price hits below 21.00.
    .with_stop_loss(21.00)
    // optional: converts Market to Stop-Loss; triggers when price hits above 21.00.
    .with_take_profit(21.00)
    // optional: processing time for request; default is 5000, can't be above 60000.
    .with_recv_window(8000)
    //
    .json::<Value>()
    .await?;
Source

pub fn get_order<'a>( &self, symbol: &'a str, id: ID<'a>, ) -> ParamBuilder<'a, '_, OrderStatusParams>

Get order.

§Example
use tokio_binance::ID;
use serde_json::Value;
 
let response = client
    .get_order("BNBUSDT", ID::ClientOId("<uuid>"))
    // optional: processing time for request; default is 5000, can't be above 60000.
    .with_recv_window(8000)
    //
    .json::<Value>()
    .await?;
Source

pub fn cancel_order<'a>( &self, symbol: &'a str, id: ID<'a>, ) -> ParamBuilder<'a, '_, CancelOrderParams>

Cancel order.

§Example
use tokio_binance::ID;
use serde_json::Value;
 
let response = client
    .cancel_order("BNBUSDT", ID::ClientOId("<uuid>"))
    // optional: unique id; auto generated by default.
    .with_new_client_order_id("<uuid>")
    // optional: processing time for request; default is 5000, can't be above 60000.
    .with_recv_window(8000)
    //
    .json::<Value>()
    .await?;
Source

pub fn get_open_orders(&self) -> ParamBuilder<'_, '_, OpenOrderParams>

Get open orders.

§Example
use serde_json::Value;
 
let response = client
    .get_open_orders()
    // optional: filter by symbol; gets all symbols by default.
    .with_symbol("BNBUSDT")
    // optional: processing time for request; default is 5000, can't be above 60000.
    .with_recv_window(8000)
    //
    .json::<Value>()
    .await?;
Source

pub fn get_all_orders<'a>( &self, symbol: &'a str, ) -> ParamBuilder<'a, '_, AllOrdersParams>

Get all orders.

§Example
use chrono::{Utc, Duration};
use serde_json::Value;
 
let end = Utc::now();
let start = end - Duration::hours(23);
 
let response = client
    .get_all_orders("BNBUSDT")
    // optional: filter by orders greater than or equal to the provided id.
    // If supplied, neither startTime or endTime can be provided
    .with_order_id(1230494)
    // optional: get orders from; pass 24 hours of orders is the default.
    .with_start_time(start)
    // optional: get orders until; default is now.
    .with_end_time(end)
    // optional: limit the amount of orders; default 500; max 1000.
    .with_limit(100)
    // optional: processing time for request; default is 5000, can't be above 60000.
    .with_recv_window(8000)
    //
    .json::<Value>()
    .await?;
Source

pub fn place_oco_order<'a>( &self, symbol: &'a str, side: Side, price: f64, stop_price: f64, quantity: f64, ) -> ParamBuilder<'a, '_, OcoParams>

Place a new oco order.

§Price Restrictions:
  • SELL: Limit Price > Last Price > Stop Price
  • BUY: Limit Price < Last Price < Stop Price
§Example
use tokio_binance::{Side::Sell, TimeInForce::Gtc, OrderRespType::Full};
use serde_json::Value;
 
let response = client
    // Limit to sell at 30.00 and Stop-Loss at 20.00; One cancels the other.
    .place_oco_order("BNBUSDT", Sell, 30.00, 20.00, 5.00)
    // optional: A unique Id for the entire orderList; auto generated by default.
    .with_list_client_order_id("<uuid>")
    // optional: A unique Id for the limit order; auto generated by default.
    .with_limit_client_order_id("<uuid>")
    // optional: splits quantity for the limit order leg;
    .with_limit_iceberg_qty(1.00)
    // optional: A unique Id for the stop loss/stop loss limit leg; auto generated by default.
    .with_stop_client_order_id("<uuid>")
    // optional: Converts Stop-Loss to Stop-Limit; triggers bellow 20.00.
    .with_stop_limit_price(19.00, Gtc)
    // optional: splits quantity for the stop order leg;
    .with_stop_iceberg_qty(1.00)
    // optional: output verbosity; default is Ack.
    .with_new_order_resp_type(Full)
    // optional: processing time for request; default is 5000, can't be above 60000.
    .with_recv_window(8000)
    //
    .json::<Value>()
    .await?;
Source

pub fn cancel_oco_order<'a>( &self, symbol: &'a str, id: ID<'a>, ) -> ParamBuilder<'a, '_, CancelOcoParams>

Cancel oco order.

§Example
use tokio_binance::ID;
use serde_json::Value;
 
let response = client
    .cancel_oco_order("BNBUSDT", ID::ClientOId("<uuid>"))
    // optional: unique id; auto generated by default.
    .with_new_client_order_id("<uuid>")
    // optional: processing time for request; default is 5000, can't be above 60000.
    .with_recv_window(8000)
    //
    .json::<Value>()
    .await?;
Source

pub fn get_oco_order<'a>( &self, id: ID<'a>, ) -> ParamBuilder<'a, '_, OcoStatusParams>

Get oco order.

§Example
use tokio_binance::ID;
use serde_json::Value;
 
let response = client
    .get_oco_order(ID::ClientOId("<uuid>"))
    // optional: processing time for request; default is 5000, can't be above 60000.
    .with_recv_window(8000)
    //
    .json::<Value>()
    .await?;
Source

pub fn get_all_oco_orders(&self) -> ParamBuilder<'_, '_, AllOcoParams>

Get all oco orders.

§Example
use chrono::{Utc, Duration};
use serde_json::Value;
 
let end = Utc::now();
let start = end - Duration::hours(23);
 
let response = client
    .get_all_oco_orders()
    // optional: filter by orders greater than or equal to the provided id.
    // If supplied, neither startTime or endTime can be provided
    .with_from_id(1230494)
    // optional: get orders from; pass 24 hours of orders is the default.
    .with_start_time(start)
    // optional: get orders until; default is now.
    .with_end_time(end)
    // optional: limit the amount of orders; default 500; max 1000.
    .with_limit(100)
    // optional: processing time for request; default is 5000, can't be above 60000.
    .with_recv_window(8000)
    //
    .json::<Value>()
    .await?;
Source

pub fn get_open_oco_orders(&self) -> ParamBuilder<'_, '_, OpenOcoParams>

Get open oco orders.

§Example
use serde_json::Value;
 
let response = client
    .get_open_oco_orders()
    // optional: processing time for request; default is 5000, can't be above 60000.
    .with_recv_window(8000)
    //
    .json::<Value>()
    .await?;
Source

pub fn get_account(&self) -> ParamBuilder<'_, '_, AccountParams>

Get current account information.

§Example
use serde_json::Value;
 
let response = client
    .get_account()
    // optional: processing time for request; default is 5000, can't be above 60000.
    .with_recv_window(8000)
    //
    .json::<Value>()
    .await?;
Source

pub fn get_account_trades<'a>( &self, symbol: &'a str, ) -> ParamBuilder<'a, '_, AccountTradesParams>

Get trades for a specific account and symbol.

§Example
use chrono::{Utc, Duration};
use serde_json::Value;
 
let end = Utc::now();
let start = end - Duration::hours(23);
 
let response = client
    .get_account_trades("BNBUSDT")
    // optional: filter by orders greater than or equal to the provided id.
    // If supplied, neither startTime or endTime can be provided
    .with_from_id(1230494)
    // optional: get orders from; pass 24 hours of orders is the default.
    .with_start_time(start)
    // optional: get orders until; default is now.
    .with_end_time(end)
    // optional: limit the amount of orders; default 500; max 1000.
    .with_limit(100)
    // optional: processing time for request; default is 5000, can't be above 60000.
    .with_recv_window(8000)
    //
    .json::<Value>()
    .await?;
Source

pub fn to_withdraw_client(&self) -> WithdrawalClient

Helper method for getting a withdraw client instance.

Source

pub fn to_market_data_client(&self) -> MarketDataClient

Helper method for getting a market client instance.

Source

pub fn to_general_client(&self) -> GeneralClient

Helper method for getting a general client instance.

Trait Implementations§

Source§

impl Clone for AccountClient

Source§

fn clone(&self) -> AccountClient

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

impl<T> ErasedDestructor for T
where T: 'static,