CoinbasePublicClient

Struct CoinbasePublicClient 

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

Coinbase Pro public API client. Use build() method to instantiate.

Implementations§

Source§

impl CoinbasePublicClient

Source

pub fn new() -> Self

Instantiate a new Coinbase public client using default parameters.

Source

pub fn builder() -> CoinbaseClientBuilder<'static>

Builder to construct CoinbasePublicClient instances. Parameters not passed to the builder default to the constants defined under ‘Default Constants’.

§Arguments
  • ‘api_url’ - API URL . Defaults to const COINBASE_API_URL (https://api.pro.coinbase.com)
  • ‘request_timeout’ - HTTP request timeout (in seconds). Defaults to const DEFAULT_REQUEST_TIMEOUT (30).
  • ‘rate_limit’ - Number of requests per second allowed. Set to zero to disable rate-limiting. Defaults to const DEFAULT_RATE_LIMIT (3).
  • ‘burst_size’ - Number of requests that can be burst when rate-limiting is enabled. Defaults to const DEFAULT_BURST_SIZE (6).
§Example
        use coinbase_pro_api::CoinbasePublicClient;

        let client = CoinbasePublicClient::builder()
           .request_timeout(30)
           .rate_limit(3)
           .burst_size(6)
           .api_url("https://api.pro.coinbase.com")
           .build();
Source

pub async fn get_products(&self) -> Result<String, Error>

Get list of available markets to trade.

Source

pub async fn get_product(&self, product_id: &str) -> Result<String, Error>

Returns information about a single market

§Arguments
  • ‘product_id’ - market identifier formatted as ‘BASE-QUOTE’, such as ‘ETH-USD’. String can be lowercase or uppercase.
Source

pub async fn get_product_orderbook( &self, product_id: &str, level: OBLevel, ) -> Result<String, Error>

Returns up to a full (level 3) orderbook from a single market.

§Arguments
  • ‘product_id’ - market identifier formatted as ‘BASE-QUOTE’, such as ‘ETH-USD’. String can be lowercase or uppercase.

  • ‘level’ - Level 1 will return the best bid and best ask. Level 2 will return the 50 best bid and ask levels, aggregated. Level 3 will return the full orderbook, unaggregated.

Source

pub async fn get_product_ticker( &self, product_id: &str, ) -> Result<String, Error>

Returns snapshot about the last trade, best bid/ask and 24h volume.

§Arguments
  • ‘product_id’ - market identifier formatted as ‘BASE-QUOTE’, such as ‘ETH-USD’. String can be lowercase or uppercase.
Source

pub async fn get_product_trades( &self, product_id: &str, after: Option<u64>, ) -> Result<String, Error>

Returns a product’s latest trades.

§Arguments
  • ‘product_id’ - market identifier formatted as ‘BASE-QUOTE’, such as ‘ETH-USD’. String can be lowercase or uppercase.
  • ‘after’ - optional parameter: pass in a ‘Some(u64)’ to parameterize a lower bound for recent trades, and exclude trades from the response that have a lower sequence.
Source

pub async fn get_product_historic_rates( &self, product_id: &str, start_opt: Option<DateTime<Utc>>, end_opt: Option<DateTime<Utc>>, granularity_opt: Option<Granularity>, ) -> Result<String, Error>

Return’s a product’s historic rates.

§Arguments
  • ‘product_id’ - market identifier formatted as ‘BASE-QUOTE’, such as ‘ETH-USD’. String can be lowercase or uppercase.
  • ‘start’ - optional parameter: Start DateTime
  • ‘end’ - optional parameter: End DateTime
  • ‘granularity’ - optional parameter: candle size in seconds

The chrono crate’s ‘to_rfc3339’ method can generate the correct datetime strings.

Candle schema is [timestamp, low, high, open, close, volume].

If start, end, and granularity parameters are left None, Coinbase will return 300 1-minute candles. Coinbase does not publish data for periods where no trades occur. Coinbase will reject requests for more than 300 candles of any size.

Source

pub async fn get_product_24h_stats( &self, product_id: &str, ) -> Result<String, Error>

Returns a product’s 24h stats.

§Arguments
  • ‘product_id’ - market identifier formatted as ‘BASE-QUOTE’, such as ‘ETH-USD’. String can be lowercase or uppercase.
Source

pub async fn get_currencies(&self) -> Result<String, Error>

Returns currencies supported by Coinbase.

Source

pub async fn get_time(&self) -> Result<String, Error>

Returns Coinbase’s server time in both epoch and ISO format.

Trait Implementations§

Source§

impl Debug for CoinbasePublicClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CoinbasePublicClient

Source§

fn default() -> Self

Returns the “default value” for a type. 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> 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<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,