#[derive(Debug)]
pub struct Endpoints {
pub rest_api: String,
pub web_socket: String,
}
#[derive(Debug)]
/// Configuration for the connection to API.
pub struct Config {
/// spot connections configuration
pub spot: Endpoints,
/// futures connections configuration
pub futures: Endpoints,
/// The number of milliseconds after `timestamp` the request is valid for.
///
/// It is recommended to use a small `recv_window` of 5_000 or less.
/// The max cannot go beyond 60_000.
///
/// More on it: <https://binance-docs.github.io/apidocs/spot/en/#timing-security>
pub recv_window: u16,
}
impl Default for Config {
/// Configure binance with default production endpoints
fn default() -> Self {
Self {
spot: Endpoints {
// <https://binance-docs.github.io/apidocs/spot/en/#general-api-information>
rest_api: "https://api.binance.com".into(),
// <https://binance-docs.github.io/apidocs/spot/en/#websocket-market-streams>
web_socket: "wss://stream.binance.com:9443".into(),
},
futures: Endpoints {
// <https://binance-docs.github.io/apidocs/futures/en/#general-api-information>
rest_api: "https://fapi.binance.com".into(),
// <https://binance-docs.github.io/apidocs/futures/en/#websocket-market-streams>
web_socket: "wss://fstream.binance.com:9443".into(),
},
recv_window: 5000,
}
}
}
impl Config {
/// Configure binance with all testnet endpoints
pub fn testnet() -> Self {
Self {
// <https://testnet.binance.vision/#faq-how-to-use>
spot: Endpoints {
rest_api: "https://testnet.binance.vision".into(),
web_socket: "wss://testnet.binance.vision".into(),
},
// <https://binance-docs.github.io/apidocs/futures/en/#testnet>
futures: Endpoints {
rest_api: "https://testnet.binancefuture.com".into(),
web_socket: "wss://testnet.binancefuture.com".into(),
},
recv_window: 5000,
}
}
}