use url::Url;
pub struct BnEndpoint {
rest_base_url: Url,
ws_api_base_url: Url,
ws_stream_base_url: Url,
}
impl BnEndpoint {
pub fn new_spot() -> Self {
Self {
rest_base_url: Url::parse("https://api.binance.com").unwrap(),
ws_api_base_url: Url::parse("wss://ws-api.binance.com:443/ws-api/v3").unwrap(),
ws_stream_base_url: Url::parse("wss://stream.binance.com:9443/stream").unwrap(),
}
}
pub fn new_spot_testnet() -> Self {
Self {
rest_base_url: Url::parse("https://testnet.binance.vision/api").unwrap(),
ws_api_base_url: Url::parse("wss://ws-api.testnet.binance.vision/ws-api/v3").unwrap(),
ws_stream_base_url: Url::parse("wss://stream.testnet.binance.vision:443/stream")
.unwrap(),
}
}
pub fn new_usdm() -> Self {
Self {
rest_base_url: Url::parse("https://fapi.binance.com/").unwrap(),
ws_api_base_url: Url::parse("wss://ws-fapi.binance.com/ws-fapi/v1").unwrap(),
ws_stream_base_url: Url::parse("wss://fstream.binance.com/stream").unwrap(),
}
}
pub fn new_usdm_testnet() -> Self {
Self {
rest_base_url: Url::parse("https://testnet.binancefuture.com").unwrap(),
ws_api_base_url: Url::parse("wss://testnet.binancefuture.com/ws-fapi/v1").unwrap(),
ws_stream_base_url: Url::parse("wss://stream.binancefuture.com/stream").unwrap(),
}
}
pub fn build_rest_api_url(&self, path: &str) -> Url {
self.rest_base_url
.join(path)
.inspect_err(|err| tracing::error!("fail to build url: {err}"))
.unwrap()
}
pub fn get_ws_api_base_url(&self) -> &Url {
&self.ws_api_base_url
}
pub fn get_ws_stream_base_url(&self) -> &Url {
&self.ws_stream_base_url
}
}