use super::{
consts::{
BINANCE_FUTURES_COIN_DEMO_HTTP_URL, BINANCE_FUTURES_COIN_HTTP_URL,
BINANCE_FUTURES_COIN_TESTNET_HTTP_URL, BINANCE_FUTURES_COIN_TESTNET_WS_URL,
BINANCE_FUTURES_COIN_WS_URL, BINANCE_FUTURES_USD_DEMO_HTTP_URL,
BINANCE_FUTURES_USD_HTTP_URL, BINANCE_FUTURES_USD_TESTNET_HTTP_URL,
BINANCE_FUTURES_USD_TESTNET_WS_URL, BINANCE_FUTURES_USD_WS_URL, BINANCE_OPTIONS_HTTP_URL,
BINANCE_OPTIONS_WS_URL, BINANCE_SPOT_DEMO_HTTP_URL, BINANCE_SPOT_DEMO_WS_URL,
BINANCE_SPOT_HTTP_URL, BINANCE_SPOT_TESTNET_HTTP_URL, BINANCE_SPOT_TESTNET_WS_URL,
BINANCE_SPOT_WS_URL,
},
enums::{BinanceEnvironment, BinanceProductType},
};
#[must_use]
pub fn get_http_base_url(
product_type: BinanceProductType,
environment: BinanceEnvironment,
) -> &'static str {
match (product_type, environment) {
(BinanceProductType::Spot | BinanceProductType::Margin, BinanceEnvironment::Mainnet) => {
BINANCE_SPOT_HTTP_URL
}
(BinanceProductType::UsdM, BinanceEnvironment::Mainnet) => BINANCE_FUTURES_USD_HTTP_URL,
(BinanceProductType::CoinM, BinanceEnvironment::Mainnet) => BINANCE_FUTURES_COIN_HTTP_URL,
(BinanceProductType::Options, BinanceEnvironment::Mainnet) => BINANCE_OPTIONS_HTTP_URL,
(BinanceProductType::Spot | BinanceProductType::Margin, BinanceEnvironment::Testnet) => {
BINANCE_SPOT_TESTNET_HTTP_URL
}
(BinanceProductType::UsdM, BinanceEnvironment::Testnet) => {
BINANCE_FUTURES_USD_TESTNET_HTTP_URL
}
(BinanceProductType::CoinM, BinanceEnvironment::Testnet) => {
BINANCE_FUTURES_COIN_TESTNET_HTTP_URL
}
(BinanceProductType::Options, BinanceEnvironment::Testnet) => BINANCE_OPTIONS_HTTP_URL,
(BinanceProductType::Spot | BinanceProductType::Margin, BinanceEnvironment::Demo) => {
BINANCE_SPOT_DEMO_HTTP_URL
}
(BinanceProductType::UsdM, BinanceEnvironment::Demo) => BINANCE_FUTURES_USD_DEMO_HTTP_URL,
(BinanceProductType::CoinM, BinanceEnvironment::Demo) => BINANCE_FUTURES_COIN_DEMO_HTTP_URL,
(BinanceProductType::Options, BinanceEnvironment::Demo) => BINANCE_OPTIONS_HTTP_URL,
}
}
#[must_use]
pub fn get_ws_base_url(
product_type: BinanceProductType,
environment: BinanceEnvironment,
) -> &'static str {
match (product_type, environment) {
(BinanceProductType::Spot | BinanceProductType::Margin, BinanceEnvironment::Mainnet) => {
BINANCE_SPOT_WS_URL
}
(BinanceProductType::UsdM, BinanceEnvironment::Mainnet) => BINANCE_FUTURES_USD_WS_URL,
(BinanceProductType::CoinM, BinanceEnvironment::Mainnet) => BINANCE_FUTURES_COIN_WS_URL,
(BinanceProductType::Options, BinanceEnvironment::Mainnet) => BINANCE_OPTIONS_WS_URL,
(BinanceProductType::Spot | BinanceProductType::Margin, BinanceEnvironment::Testnet) => {
BINANCE_SPOT_TESTNET_WS_URL
}
(BinanceProductType::UsdM, BinanceEnvironment::Testnet) => {
BINANCE_FUTURES_USD_TESTNET_WS_URL
}
(BinanceProductType::CoinM, BinanceEnvironment::Testnet) => {
BINANCE_FUTURES_COIN_TESTNET_WS_URL
}
(BinanceProductType::Options, BinanceEnvironment::Testnet) => BINANCE_OPTIONS_WS_URL,
(BinanceProductType::Spot | BinanceProductType::Margin, BinanceEnvironment::Demo) => {
BINANCE_SPOT_DEMO_WS_URL
}
(BinanceProductType::UsdM, BinanceEnvironment::Demo) => BINANCE_FUTURES_USD_TESTNET_WS_URL,
(BinanceProductType::CoinM, BinanceEnvironment::Demo) => {
BINANCE_FUTURES_COIN_TESTNET_WS_URL
}
(BinanceProductType::Options, BinanceEnvironment::Demo) => BINANCE_OPTIONS_WS_URL,
}
}
#[cfg(test)]
mod tests {
use rstest::rstest;
use super::*;
#[rstest]
fn test_http_url_spot_mainnet() {
let url = get_http_base_url(BinanceProductType::Spot, BinanceEnvironment::Mainnet);
assert_eq!(url, "https://api.binance.com");
}
#[rstest]
fn test_http_url_spot_testnet() {
let url = get_http_base_url(BinanceProductType::Spot, BinanceEnvironment::Testnet);
assert_eq!(url, "https://testnet.binance.vision");
}
#[rstest]
fn test_http_url_spot_demo() {
let url = get_http_base_url(BinanceProductType::Spot, BinanceEnvironment::Demo);
assert_eq!(url, "https://demo-api.binance.com");
}
#[rstest]
fn test_http_url_usdm_mainnet() {
let url = get_http_base_url(BinanceProductType::UsdM, BinanceEnvironment::Mainnet);
assert_eq!(url, "https://fapi.binance.com");
}
#[rstest]
fn test_http_url_usdm_testnet() {
let url = get_http_base_url(BinanceProductType::UsdM, BinanceEnvironment::Testnet);
assert_eq!(url, "https://demo-fapi.binance.com");
}
#[rstest]
fn test_http_url_coinm_mainnet() {
let url = get_http_base_url(BinanceProductType::CoinM, BinanceEnvironment::Mainnet);
assert_eq!(url, "https://dapi.binance.com");
}
#[rstest]
fn test_http_url_usdm_demo() {
let url = get_http_base_url(BinanceProductType::UsdM, BinanceEnvironment::Demo);
assert_eq!(url, "https://demo-fapi.binance.com");
}
#[rstest]
fn test_http_url_coinm_demo() {
let url = get_http_base_url(BinanceProductType::CoinM, BinanceEnvironment::Demo);
assert_eq!(url, "https://testnet.binancefuture.com");
}
#[rstest]
fn test_ws_url_spot_mainnet() {
let url = get_ws_base_url(BinanceProductType::Spot, BinanceEnvironment::Mainnet);
assert_eq!(url, "wss://stream.binance.com:9443/ws");
}
#[rstest]
fn test_ws_url_spot_demo() {
let url = get_ws_base_url(BinanceProductType::Spot, BinanceEnvironment::Demo);
assert_eq!(url, "wss://demo-stream.binance.com/ws");
}
#[rstest]
fn test_ws_url_usdm_mainnet() {
let url = get_ws_base_url(BinanceProductType::UsdM, BinanceEnvironment::Mainnet);
assert_eq!(url, "wss://fstream.binance.com/ws");
}
#[rstest]
fn test_ws_url_usdm_testnet() {
let url = get_ws_base_url(BinanceProductType::UsdM, BinanceEnvironment::Testnet);
assert_eq!(url, "wss://fstream.binancefuture.com/ws");
}
}