[][src]Struct cbpro::builder::QueryBuilder

pub struct QueryBuilder<T> { /* fields omitted */ }

Builder returned by the public and private client. All methods are optional but the builder must be consumed with one of the terminal methods. Methods beloging to this struct can be chained and calling the same method more than once will overwrite the previously set value.

Methods

impl<'a, T: Params<'a>> QueryBuilder<T>[src]

Example


let client = PublicClient::new(SANDBOX_URL);
let products = client
    .get_products()
    .json()
    .await?;
 
println!("{}", serde_json::to_string_pretty(&products).unwrap());

pub async fn json(self) -> Result<Value>[src]

General terminal method

impl<'a, T: Params<'a> + ProductID<'a>> QueryBuilder<T>[src]

pub fn product_id(self, value: &'a str) -> Self[src]

Sets product id

Example

let response = client.cancel_all()
    .product_id("BTC-USD")
    .json()
    .await?;
 
println!("{}", serde_json::to_string_pretty(&response).unwrap());

impl<'a, T: Params<'a> + Book<'a>> QueryBuilder<T>[src]

pub fn level(self, value: i32) -> Self[src]

Sets level for order book data. Max level is 3.

Example

let client = PublicClient::new(SANDBOX_URL);
let order_book = client.get_product_order_book("BTC-USD")
    .level(3)
    .json()
    .await?;
 
println!("{}", serde_json::to_string_pretty(&order_book).unwrap());

impl<'a, T: Params<'a> + Paginate<'a> + Send + Unpin + 'a> QueryBuilder<T>[src]

pub fn limit(self, value: i32) -> Self[src]

Sets limit for the ammount of pages each request will return. Max number of pages is 100.

Example

use futures::TryStreamExt;
let client = PublicClient::new(SANDBOX_URL);
let mut pages = client.get_trades("BTC-USD")
    .limit(10)
    .after(7102310) // after or before but not both
    .paginate()?; // or .json().await? for a single request

while let Some(json) = pages.try_next().await? {
    println!("{}", serde_json::to_string_pretty(&json).unwrap());
    tokio::time::delay_for(core::time::Duration::new(1, 0)).await;
}

pub fn before(self, value: i32) -> Self[src]

Gets newer page from the trade id specified.

pub fn after(self, value: i32) -> Self[src]

Gets older page from the trade id specified.

pub fn paginate(self) -> Result<Pages<'a>>[src]

Terminal method returning a stream of json pages

impl<'a, T: Params<'a> + Candle<'a>> QueryBuilder<T>[src]

pub fn range<Tz: TimeZone>(self, start: DateTime<Tz>, end: DateTime<Tz>) -> Self where
    Tz::Offset: Display
[src]

Sets start and end time for historic rates. If the range results in more than 300 candles, the request will be rejected.

Example

let client = PublicClient::new(SANDBOX_URL);
let end = chrono::offset::Utc::now();
let start = end - chrono::Duration::hours(5);

let rates = client
    .get_historic_rates("BTC-USD", 3600)
    .range(start, end)
    .json()
    .await?;
 
println!("{}", serde_json::to_string_pretty(&rates).unwrap());

impl<'a, T: Params<'a> + ClientOID<'a>> QueryBuilder<T>[src]

pub fn client_oid(self, value: &'a str) -> Self[src]

Sets uuid as part of this order

Example


let response = client.place_market_order("BTC-USD", "buy", QTY::Size(10.00))
    .client_oid("<client_oid>")
    .json()
    .await?;
 
println!("{}", serde_json::to_string_pretty(&response).unwrap());

impl<'a, T: Params<'a> + Limit<'a>> QueryBuilder<T>[src]

pub fn stp(self, value: &'a str) -> Self[src]

Sets Self-trade prevention flag.

Example

let response = client
    .place_limit_order("BTC-USD", "sell", 7000.00, 10.00)
    .stp("dc")
    .json()
    .await?;
 
println!("{}", serde_json::to_string_pretty(&response).unwrap());

pub fn stop_price(self, value: f64) -> Self[src]

Turns sell limit order into a stop loss or a stop entry for a buy limit order.

Example

let response = client
    .place_limit_order("BTC-USD", "sell", 7000.00, 10.00)
    .stop_price(7010.00)
    .json()
    .await?;
 
println!("{}", serde_json::to_string_pretty(&response).unwrap());

pub fn time_in_force(self, value: &'a str) -> Self[src]

Sets time in force policy. (default is GTC) Valid inputs are: "GTC", "GTT", "IOC", "FOK".

Example

let response = client
    .place_limit_order("BTC-USD", "sell", 7000.00, 10.00)
    .time_in_force("GTT")
    .json()
    .await?;
 
println!("{}", serde_json::to_string_pretty(&response).unwrap());

pub fn cancel_after(self, value: &'a str) -> Self[src]

Sets time before order is cancelled Valid inputs are: "min", "hour", "day".

Example

let response = client
    .place_limit_order("BTC-USD", "sell", 7000.00, 10.00)
    .cancel_after("min")
    .json()
    .await?;
 
println!("{}", serde_json::to_string_pretty(&response).unwrap());

pub fn post_only(self, value: bool) -> Self[src]

The post-only flag indicates that the order should only make liquidity. If any part of the order results in taking liquidity, the order will be rejected and no part of it will execute. Invalid when time_in_force is IOC or FOK.

Example

let response = client
    .place_limit_order("BTC-USD", "sell", 7000.00, 10.00)
    .post_only(true)
    .json()
    .await?;
 
println!("{}", serde_json::to_string_pretty(&response).unwrap());

impl<'a, T: Params<'a> + Report<'a>> QueryBuilder<T>[src]

pub fn format(self, value: &'a str) -> Self[src]

Sets format of output report. Valid inputs are "pdf" or "csv" (defualt is pdf)

Example

use cbpro::client::{AuthenticatedClient, SANDBOX_URL, RPT};
use chrono::{ TimeZone, Utc };
let start_date = Utc.ymd(2018, 8, 10).and_hms(0, 0, 0);
let end_date = Utc.ymd(2018, 8, 28).and_hms(0, 0, 0);

let rates = client.create_report(start_date, end_date, RPT::Fills { product_id: "BTC-USD" })
    .format("pdf")
    .email("<email>")
    .json()
    .await?;
 
println!("{}", serde_json::to_string_pretty(&rates).unwrap());

pub fn email(self, value: &'a str) -> Self[src]

Sets to send report to. Valid inputs are "pdf" or "csv" (defualt is pdf)

Example

use cbpro::client::{AuthenticatedClient, SANDBOX_URL, RPT};
use chrono::{ TimeZone, Utc };
let start_date = Utc.ymd(2018, 8, 10).and_hms(0, 0, 0);
let end_date = Utc.ymd(2018, 8, 28).and_hms(0, 0, 0);

let rates = client
    .create_report(start_date, end_date, RPT::Fills { product_id: "BTC-USD" })
    .email("<email>")
    .json()
    .await?;
 
println!("{}", serde_json::to_string_pretty(&rates).unwrap());

Auto Trait Implementations

impl<T> !RefUnwindSafe for QueryBuilder<T>

impl<T> Send for QueryBuilder<T> where
    T: Send

impl<T> Sync for QueryBuilder<T> where
    T: Sync

impl<T> Unpin for QueryBuilder<T> where
    T: Unpin

impl<T> !UnwindSafe for QueryBuilder<T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,