pub struct AccountClient { /* private fields */ }Expand description
Client for dealing with orders
Implementations§
Source§impl AccountClient
impl AccountClient
Sourcepub fn connect<A, S, U>(api_key: A, secret_key: S, url: U) -> Result<Self>
pub fn connect<A, S, U>(api_key: A, secret_key: S, url: U) -> Result<Self>
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(())
}Sourcepub fn place_limit_order<'a>(
&self,
symbol: &'a str,
side: Side,
price: f64,
quantity: f64,
execute: bool,
) -> ParamBuilder<'a, '_, LimitOrderParams>
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?;Sourcepub fn place_market_order<'a>(
&self,
symbol: &'a str,
side: Side,
quantity: f64,
execute: bool,
) -> ParamBuilder<'a, '_, MarketOrderParams>
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?;Sourcepub fn get_order<'a>(
&self,
symbol: &'a str,
id: ID<'a>,
) -> ParamBuilder<'a, '_, OrderStatusParams>
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?;Sourcepub fn cancel_order<'a>(
&self,
symbol: &'a str,
id: ID<'a>,
) -> ParamBuilder<'a, '_, CancelOrderParams>
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?;Sourcepub fn get_open_orders(&self) -> ParamBuilder<'_, '_, OpenOrderParams>
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?;Sourcepub fn get_all_orders<'a>(
&self,
symbol: &'a str,
) -> ParamBuilder<'a, '_, AllOrdersParams>
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?;Sourcepub fn place_oco_order<'a>(
&self,
symbol: &'a str,
side: Side,
price: f64,
stop_price: f64,
quantity: f64,
) -> ParamBuilder<'a, '_, OcoParams>
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?;Sourcepub fn cancel_oco_order<'a>(
&self,
symbol: &'a str,
id: ID<'a>,
) -> ParamBuilder<'a, '_, CancelOcoParams>
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?;Sourcepub fn get_oco_order<'a>(
&self,
id: ID<'a>,
) -> ParamBuilder<'a, '_, OcoStatusParams>
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?;Sourcepub fn get_all_oco_orders(&self) -> ParamBuilder<'_, '_, AllOcoParams>
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?;Sourcepub fn get_open_oco_orders(&self) -> ParamBuilder<'_, '_, OpenOcoParams>
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?;Sourcepub fn get_account(&self) -> ParamBuilder<'_, '_, AccountParams>
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?;Sourcepub fn get_account_trades<'a>(
&self,
symbol: &'a str,
) -> ParamBuilder<'a, '_, AccountTradesParams>
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?;Sourcepub fn to_withdraw_client(&self) -> WithdrawalClient
pub fn to_withdraw_client(&self) -> WithdrawalClient
Helper method for getting a withdraw client instance.
Sourcepub fn to_market_data_client(&self) -> MarketDataClient
pub fn to_market_data_client(&self) -> MarketDataClient
Helper method for getting a market client instance.
Sourcepub fn to_general_client(&self) -> GeneralClient
pub fn to_general_client(&self) -> GeneralClient
Helper method for getting a general client instance.
Trait Implementations§
Source§impl Clone for AccountClient
impl Clone for AccountClient
Source§fn clone(&self) -> AccountClient
fn clone(&self) -> AccountClient
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for AccountClient
impl !RefUnwindSafe for AccountClient
impl Send for AccountClient
impl Sync for AccountClient
impl Unpin for AccountClient
impl !UnwindSafe for AccountClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more