binance_api/
config.rs

1#[derive(Debug)]
2pub struct Endpoints {
3    pub rest_api: String,
4    pub web_socket: String,
5}
6
7#[derive(Debug)]
8/// Configuration for the connection to API.
9pub struct Config {
10    /// spot connections configuration
11    pub spot: Endpoints,
12    /// futures connections configuration
13    pub futures: Endpoints,
14    /// The number of milliseconds after `timestamp` the request is valid for.
15    ///
16    /// It is recommended to use a small `recv_window` of 5_000 or less.
17    /// The max cannot go beyond 60_000.
18    ///
19    /// More on it: <https://binance-docs.github.io/apidocs/spot/en/#timing-security>
20    pub recv_window: u16,
21}
22
23impl Default for Config {
24    /// Configure binance with default production endpoints
25    fn default() -> Self {
26        Self {
27            spot: Endpoints {
28                // <https://binance-docs.github.io/apidocs/spot/en/#general-api-information>
29                rest_api: "https://api.binance.com".into(),
30                // <https://binance-docs.github.io/apidocs/spot/en/#websocket-market-streams>
31                web_socket: "wss://stream.binance.com:9443".into(),
32            },
33            futures: Endpoints {
34                // <https://binance-docs.github.io/apidocs/futures/en/#general-api-information>
35                rest_api: "https://fapi.binance.com".into(),
36                // <https://binance-docs.github.io/apidocs/futures/en/#websocket-market-streams>
37                web_socket: "wss://fstream.binance.com:9443".into(),
38            },
39            recv_window: 5000,
40        }
41    }
42}
43
44impl Config {
45    /// Configure binance with all testnet endpoints
46    pub fn testnet() -> Self {
47        Self {
48            // <https://testnet.binance.vision/#faq-how-to-use>
49            spot: Endpoints {
50                rest_api: "https://testnet.binance.vision".into(),
51                web_socket: "wss://testnet.binance.vision".into(),
52            },
53            // <https://binance-docs.github.io/apidocs/futures/en/#testnet>
54            futures: Endpoints {
55                rest_api: "https://testnet.binancefuture.com".into(),
56                web_socket: "wss://testnet.binancefuture.com".into(),
57            },
58            recv_window: 5000,
59        }
60    }
61}