crypto_rest_client/exchanges/
coinbase_pro.rs

1use super::utils::http_get;
2use crate::error::Result;
3use std::collections::BTreeMap;
4
5const BASE_URL: &str = "https://api.exchange.coinbase.com";
6
7/// The REST client for CoinbasePro.
8///
9/// CoinbasePro has only Spot market.
10///
11///   * REST API doc: <https://docs.cloud.coinbase.com/exchange/reference>
12///   * Trading at: <https://pro.coinbase.com/>
13///   * Rate Limits: <https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getaccounts#rate-limits>
14///   * This endpoint has a custom rate limit by profile ID: 25 requests per
15///     second, up to 50 requests per second in bursts
16pub struct CoinbaseProRestClient {
17    _api_key: Option<String>,
18    _api_secret: Option<String>,
19}
20
21impl CoinbaseProRestClient {
22    pub fn new(api_key: Option<String>, api_secret: Option<String>) -> Self {
23        CoinbaseProRestClient { _api_key: api_key, _api_secret: api_secret }
24    }
25
26    /// List the latest trades for a product.
27    ///
28    /// `/products/{symbol}/trades`
29    ///
30    /// For example: <https://api.pro.coinbase.com/products/BTC-USD/trades>
31    pub fn fetch_trades(symbol: &str) -> Result<String> {
32        gen_api!(format!("/products/{symbol}/trades"))
33    }
34
35    /// Get the latest Level2 orderbook snapshot.
36    ///
37    /// Top 50 bids and asks (aggregated) are returned.
38    ///
39    /// For example: <https://api.pro.coinbase.com/products/BTC-USD/book?level=2>
40    pub fn fetch_l2_snapshot(symbol: &str) -> Result<String> {
41        gen_api!(format!("/products/{symbol}/book?level=2"))
42    }
43
44    /// Get the latest Level3 orderbook snapshot.
45    ///
46    /// Full order book (non aggregated) are returned.
47    ///
48    /// For example: <https://api.pro.coinbase.com/products/BTC-USD/book?level=3>
49    pub fn fetch_l3_snapshot(symbol: &str) -> Result<String> {
50        gen_api!(format!("/products/{symbol}/book?level=3"))
51    }
52}