pub struct CoinbasePublicClient { /* private fields */ }Expand description
Coinbase Pro public API client. Use build() method to instantiate.
Implementations§
Source§impl CoinbasePublicClient
impl CoinbasePublicClient
Sourcepub fn builder() -> CoinbaseClientBuilder<'static>
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();Sourcepub async fn get_products(&self) -> Result<String, Error>
pub async fn get_products(&self) -> Result<String, Error>
Get list of available markets to trade.
Sourcepub async fn get_product(&self, product_id: &str) -> Result<String, Error>
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.
Sourcepub async fn get_product_orderbook(
&self,
product_id: &str,
level: OBLevel,
) -> Result<String, Error>
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.
Sourcepub async fn get_product_ticker(
&self,
product_id: &str,
) -> Result<String, Error>
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.
Sourcepub async fn get_product_trades(
&self,
product_id: &str,
after: Option<u64>,
) -> Result<String, Error>
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.
Sourcepub 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>
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.
Sourcepub async fn get_product_24h_stats(
&self,
product_id: &str,
) -> Result<String, Error>
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.
Sourcepub async fn get_currencies(&self) -> Result<String, Error>
pub async fn get_currencies(&self) -> Result<String, Error>
Returns currencies supported by Coinbase.