crypto_rest_client/exchanges/binance/
binance_spot.rs

1use super::{super::utils::http_get, utils::*};
2use crate::error::Result;
3use std::collections::BTreeMap;
4
5const BASE_URL: &str = "https://api.binance.com";
6
7/// Binance Spot market.
8///
9/// * RESTful API doc: <https://binance-docs.github.io/apidocs/spot/en/>
10/// * Trading at: <https://www.binance.com/en/trade/BTC_USDT>
11/// * Rate Limits: <https://binance-docs.github.io/apidocs/spot/en/#limits>
12///   * 1200 request weight per minute
13///   * 6100 raw requests per 5 minutes
14pub struct BinanceSpotRestClient {
15    _api_key: Option<String>,
16    _api_secret: Option<String>,
17}
18
19impl BinanceSpotRestClient {
20    pub fn new(api_key: Option<String>, api_secret: Option<String>) -> Self {
21        BinanceSpotRestClient { _api_key: api_key, _api_secret: api_secret }
22    }
23
24    /// Get compressed, aggregate trades.
25    ///
26    /// Equivalent to `/api/v3/aggTrades` with `limit=1000`
27    ///
28    /// For example: <https://api.binance.com/api/v3/aggTrades?symbol=BTCUSDT&limit=1000>
29    pub fn fetch_agg_trades(
30        symbol: &str,
31        from_id: Option<u64>,
32        start_time: Option<u64>,
33        end_time: Option<u64>,
34    ) -> Result<String> {
35        check_symbol(symbol);
36        let symbol = Some(symbol);
37        let limit = Some(1000);
38        gen_api_binance!("/api/v3/aggTrades", symbol, from_id, start_time, end_time, limit)
39    }
40
41    /// Get a Level2 snapshot of orderbook.
42    ///
43    /// Equivalent to `/api/v3/depth` with `limit=1000`
44    ///
45    /// For example: <https://api.binance.com/api/v3/depth?symbol=BTCUSDT&limit=1000>
46    pub fn fetch_l2_snapshot(symbol: &str) -> Result<String> {
47        check_symbol(symbol);
48        let symbol = Some(symbol);
49        let limit = Some(1000);
50        gen_api_binance!("/api/v3/depth", symbol, limit)
51    }
52}