Struct Client

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

A client for the Bitvavo API.

Implementations§

Source§

impl Client

Source

pub fn new() -> Self

Create a new client for the Bitvavo API.

Source

pub async fn time(&self) -> Result<u64>

Get the current time.

use bitvavo_api as bitvavo;

let c = bitvavo::Client::new();
let t = c.time().await.unwrap();

println!("{t}");
Source

pub async fn assets(&self) -> Result<Vec<Asset>>

Get all the assets.

use bitvavo_api as bitvavo;

let c = bitvavo::Client::new();
let assets = c.assets().await.unwrap();

println!("Number of assets: {}", assets.len());
Source

pub async fn asset(&self, symbol: &str) -> Result<Asset>

Get the info of a particular asset.

use bitvavo_api as bitvavo;

let c = bitvavo::Client::new();
let asset = c.asset("BTC").await.unwrap();

println!("Number of decimals used for BTC: {}", asset.decimals);
Source

pub async fn markets(&self) -> Result<Vec<Market>>

Get all the markets.

use bitvavo_api as bitvavo;

let c = bitvavo::Client::new();
let markets = c.markets().await.unwrap();

println!("Number of markets: {}", markets.len());
Source

pub async fn market(&self, pair: &str) -> Result<Market>

Get market information for a specific market.

use bitvavo_api as bitvavo;

let c = bitvavo::Client::new();
let market = c.market("BTC-EUR").await.unwrap();

println!("Price precision of BTC-EUR: {}", market.price_precision);
Source

pub async fn order_book( &self, market: &str, depth: Option<u64>, ) -> Result<OrderBook>

Get the order book for a particular market.

use bitvavo_api as bitvavo;

let c = bitvavo::Client::new();
let ob = c.order_book("BTC-EUR", Some(2)).await.unwrap();

println!("Number of bids: {}", ob.bids.len());
Source

pub async fn trades( &self, market: &str, limit: Option<u64>, start: Option<u64>, end: Option<u64>, trade_id_from: Option<String>, trade_id_to: Option<String>, ) -> Result<Vec<Trade>>

Get the trades for a particular market.

use bitvavo_api as bitvavo;

let c = bitvavo::Client::new();
let trades = c.trades("BTC-EUR", None, None, None, None, None).await.unwrap();

println!("Number of trades: {}", trades.len());
Source

pub async fn candles( &self, market: &str, interval: CandleInterval, limit: Option<u16>, start: Option<u64>, end: Option<u64>, ) -> Result<Vec<OHLCV>>

Get candles for a particular market.

use bitvavo_api as bitvavo;
use bitvavo::types::CandleInterval;

let c = bitvavo::Client::new();
let cs = c.candles("BTC-EUR", CandleInterval::OneDay, Some(1), None, None).await.unwrap();

println!("High for BTC-EUR at {} was {}", cs[0].time, cs[0].high);
Source

pub async fn ticker_prices(&self) -> Result<Vec<TickerPrice>>

Get all the tickers.

use bitvavo_api as bitvavo;

let c = bitvavo::Client::new();
let ms = c.ticker_prices().await.unwrap();

println!("Number of markets: {}", ms.len());
Source

pub async fn ticker_price(&self, pair: &str) -> Result<TickerPrice>

Get the ticker for a particular market.

use bitvavo_api as bitvavo;

let c = bitvavo::Client::new();
let m = c.ticker_price("BTC-EUR").await.unwrap();

println!("Price for BTC-EUR: {}", m.price.unwrap_or_default());
Source

pub async fn ticker_books(&self) -> Result<Vec<TickerBook>>

Retrieve the highest buy and lowest sell prices currently available for all markets.

use bitvavo_api as bitvavo;

let c = bitvavo::Client::new();
let tb = c.ticker_books().await.unwrap();

println!("Number of tickers: {}", tb.len());
Source

pub async fn ticker_book(&self, market: &str) -> Result<TickerBook>

Retrieve the highest buy and lowest sell prices currently available for a given market.

use bitvavo_api as bitvavo;

let c = bitvavo::Client::new();
let tb = c.ticker_book("BTC-EUR").await.unwrap();

println!("Highest buy price for BTC-EUR: {}", tb.ask.unwrap());
Source

pub async fn tickers_24h(&self) -> Result<Vec<Ticker24h>>

Retrieve high, low, open, last, and volume information for trades for all markets over the previous 24h.

use bitvavo_api as bitvavo;

let c = bitvavo::Client::new();
let t24h = c.tickers_24h().await.unwrap();

println!("Number of tickers: {}", t24h.len());
Source

pub async fn ticker_24h(&self, market: &str) -> Result<Ticker24h>

Retrieve high, low, open, last, and volume information for trades for a given market over the previous 24h.

use bitvavo_api as bitvavo;

let c = bitvavo::Client::new();
let t24h = c.ticker_24h("BTC-EUR").await.unwrap();

println!("24h ask for BTC-EUR: {}", t24h.ask.unwrap());

Trait Implementations§

Source§

impl Default for Client

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

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