QueryBuilder

Struct QueryBuilder 

Source
pub struct QueryBuilder<T> { /* private fields */ }
Expand description

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 belonging to this struct can be chained and calling the same method more than once will overwrite the previously set value.

Implementations§

Source§

impl<'a, T: Params<'a>> QueryBuilder<T>

Source

pub async fn text(self) -> Result<String>

Source

pub async fn json<J: DeserializeOwned>(self) -> Result<J>

General terminal method

§Example
let products = client
    .get_products()
    .json::<serde_json::Value>()
    .await?;
 
println!("{}", serde_json::to_string_pretty(&products).unwrap());
Source§

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

Source

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

Sets product id

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

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

Source

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

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

§Example
let order_book = client.get_product_order_book("BTC-USD")
    .level(3)
    .json::<serde_json::Value>()
    .await?;
 
println!("{}", serde_json::to_string_pretty(&order_book).unwrap());
Source§

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

Source

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

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

§Example
let mut pages = client.get_trades("BTC-USD")
    .limit(10)
    .after(7102310) // after or before but not both
    .paginate::<serde_json::Value>()?; // or .json::<serde_json::Value>().await? for a single request

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

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

Gets newer page from the trade id specified.

Source

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

Gets older page from the trade id specified.

Source

pub fn paginate<J: DeserializeOwned>(self) -> Result<Pages<'a, J>>

Terminal method returning a stream of json pages

Source§

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

Source

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

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

§Example
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::<serde_json::Value>()
    .await?;
 
println!("{}", serde_json::to_string_pretty(&rates).unwrap());
Source§

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

Source

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

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::<serde_json::Value>()
    .await?;
 
println!("{}", serde_json::to_string_pretty(&response).unwrap());
Source§

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

Source

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

Sets Self-trade prevention flag.

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

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

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::<serde_json::Value>()
    .await?;
 
println!("{}", serde_json::to_string_pretty(&response).unwrap());
Source

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

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::<serde_json::Value>()
    .await?;
 
println!("{}", serde_json::to_string_pretty(&response).unwrap());
Source

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

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::<serde_json::Value>()
    .await?;
 
println!("{}", serde_json::to_string_pretty(&response).unwrap());
Source

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

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::<serde_json::Value>()
    .await?;
 
println!("{}", serde_json::to_string_pretty(&response).unwrap());
Source§

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

Source

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

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

§Example
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::<serde_json::Value>()
    .await?;
 
println!("{}", serde_json::to_string_pretty(&rates).unwrap());
Source

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

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

§Example
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::<serde_json::Value>()
    .await?;
 
println!("{}", serde_json::to_string_pretty(&rates).unwrap());

Auto Trait Implementations§

§

impl<T> !Freeze for QueryBuilder<T>

§

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§

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