crypto_rest_client/exchanges/binance/binance_linear.rs
1use super::{super::utils::http_get, utils::*};
2use crate::error::Result;
3use std::collections::BTreeMap;
4
5const BASE_URL: &str = "https://fapi.binance.com";
6
7/// Binance USDT-margined Future and Swap market.
8///
9/// * REST API doc: <https://binance-docs.github.io/apidocs/futures/en/>
10/// * Trading at: <https://www.binance.com/en/futures/BTC_USDT>
11/// * Rate Limits: <https://binance-docs.github.io/apidocs/futures/en/#limits>
12/// * 2400 request weight per minute
13pub struct BinanceLinearRestClient {
14 _api_key: Option<String>,
15 _api_secret: Option<String>,
16}
17
18impl BinanceLinearRestClient {
19 pub fn new(api_key: Option<String>, api_secret: Option<String>) -> Self {
20 BinanceLinearRestClient { _api_key: api_key, _api_secret: api_secret }
21 }
22
23 /// Get compressed, aggregate trades.
24 ///
25 /// Equivalent to `/fapi/v1/aggTrades` with `limit=1000`
26 ///
27 /// For example:
28 ///
29 /// - <https://fapi.binance.com/fapi/v1/aggTrades?symbol=BTCUSDT&limit=1000>
30 /// - <https://fapi.binance.com/fapi/v1/aggTrades?symbol=BTCUSDT_210625&limit=1000>
31 pub fn fetch_agg_trades(
32 symbol: &str,
33 from_id: Option<u64>,
34 start_time: Option<u64>,
35 end_time: Option<u64>,
36 ) -> Result<String> {
37 check_symbol(symbol);
38 let symbol = Some(symbol);
39 let limit = Some(1000);
40 gen_api_binance!("/fapi/v1/aggTrades", symbol, from_id, start_time, end_time, limit)
41 }
42
43 /// Get a Level2 snapshot of orderbook.
44 ///
45 /// Equivalent to `/fapi/v1/depth` with `limit=1000`
46 ///
47 /// For example:
48 ///
49 /// - <https://fapi.binance.com/fapi/v1/depth?symbol=BTCUSDT&limit=1000>
50 /// - <https://fapi.binance.com/fapi/v1/depth?symbol=BTCUSDT_211231&limit=1000>
51 pub fn fetch_l2_snapshot(symbol: &str) -> Result<String> {
52 check_symbol(symbol);
53 let symbol = Some(symbol);
54 let limit = Some(1000);
55 gen_api_binance!("/fapi/v1/depth", symbol, limit)
56 }
57
58 /// Get open interest.
59 ///
60 /// For example:
61 ///
62 /// - <https://fapi.binance.com/fapi/v1/openInterest?symbol=BTCUSDT>
63 /// - <https://fapi.binance.com/fapi/v1/openInterest?symbol=BTCUSDT_211231>
64 pub fn fetch_open_interest(symbol: &str) -> Result<String> {
65 check_symbol(symbol);
66 let symbol = Some(symbol);
67 gen_api_binance!("/fapi/v1/openInterest", symbol)
68 }
69}