crypto_rest_client/exchanges/binance/
binance_option.rs

1use super::{super::utils::http_get, utils::*};
2use crate::error::Result;
3use std::collections::BTreeMap;
4
5const BASE_URL: &str = "https://vapi.binance.com";
6
7/// Binance Option market.
8///
9/// * REST API doc: <https://binance-docs.github.io/apidocs/voptions/en/>
10/// * Trading at: <https://voptions.binance.com/en>
11pub struct BinanceOptionRestClient {
12    _api_key: Option<String>,
13    _api_secret: Option<String>,
14}
15
16impl BinanceOptionRestClient {
17    pub fn new(api_key: Option<String>, api_secret: Option<String>) -> Self {
18        BinanceOptionRestClient { _api_key: api_key, _api_secret: api_secret }
19    }
20
21    /// Get most recent trades.
22    ///
23    /// 500 recent trades are returned.
24    ///
25    /// For example: <https://voptions.binance.com/options-api/v1/public/market/trades?symbol=BTC-210129-40000-C&limit=500&t=1609956688000>
26    pub fn fetch_trades(symbol: &str, start_time: Option<u64>) -> Result<String> {
27        check_symbol(symbol);
28        let t = start_time;
29        gen_api_binance!(format!("/vapi/v1/trades?symbol={symbol}&limit=500"), t)
30    }
31
32    /// Get a Level2 snapshot of orderbook.
33    ///
34    /// For example: <https://vapi.binance.com/vapi/v1/depth?symbol=BTC-211001-30000-P&limit=1000>
35    pub fn fetch_l2_snapshot(symbol: &str) -> Result<String> {
36        check_symbol(symbol);
37        let symbol = Some(symbol);
38        let limit = Some(1000);
39        gen_api_binance!("/vapi/v1/depth", symbol, limit)
40    }
41}