crypto_rest_client/exchanges/dydx/
dydx_swap.rs

1use super::super::utils::http_get;
2use crate::error::Result;
3use std::collections::BTreeMap;
4
5const BASE_URL: &str = "https://api.dydx.exchange";
6
7/// dYdX perpetual RESTful client.
8///
9/// * REST API doc: <https://docs.dydx.exchange/>
10/// * Trading at: <https://trade.dydx.exchange/trade>
11/// * Rate Limits: <https://docs.dydx.exchange/#rate-limits>
12///   * 100 requests per 10 seconds
13pub struct DydxSwapRestClient {
14    _api_key: Option<String>,
15    _api_secret: Option<String>,
16}
17
18impl DydxSwapRestClient {
19    pub fn new(api_key: Option<String>, api_secret: Option<String>) -> Self {
20        DydxSwapRestClient { _api_key: api_key, _api_secret: api_secret }
21    }
22
23    /// Get a Level2 orderbook snapshot.
24    ///
25    /// All price levels are returned.
26    ///
27    /// For example: <https://api.dydx.exchange/v3/orderbook/BTC-USD>
28    pub fn fetch_l2_snapshot(symbol: &str) -> Result<String> {
29        gen_api!(format!("/v3/orderbook/{symbol}"))
30    }
31
32    /// Get open interest.
33    ///
34    /// For example: <https://api.dydx.exchange/v3/markets>
35    pub fn fetch_open_interest() -> Result<String> {
36        gen_api!("/v3/markets")
37    }
38}