use crate::types::ws::channels::WsSubscriptionArg;
use crate::types::ws::events::WsConnectionType;
pub fn route_subscription(arg: &WsSubscriptionArg) -> WsConnectionType {
if arg.is_business() {
return WsConnectionType::Business;
}
if arg.is_private() {
return WsConnectionType::Private;
}
WsConnectionType::Public
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_route_public() {
let arg = WsSubscriptionArg::with_inst_id("tickers", "BTC-USDT");
assert_eq!(route_subscription(&arg), WsConnectionType::Public);
let arg = WsSubscriptionArg::with_inst_type("event-contract-markets", "EVENTS");
assert_eq!(route_subscription(&arg), WsConnectionType::Public);
}
#[test]
fn test_route_private() {
let arg = WsSubscriptionArg::channel_only("orders");
assert_eq!(route_subscription(&arg), WsConnectionType::Private);
let arg = WsSubscriptionArg::channel_only("account");
assert_eq!(route_subscription(&arg), WsConnectionType::Private);
let arg = WsSubscriptionArg::channel_only("adl-warning");
assert_eq!(route_subscription(&arg), WsConnectionType::Private);
}
#[test]
fn test_route_business() {
let channels = [
"candle1m",
"mark-price-candle1H",
"index-candle1D",
"orders-algo",
"algo-advance",
"deposit-info",
"withdrawal-info",
"grid-orders-spot",
"grid-orders-contract",
"grid-orders-moon",
"grid-positions",
"grid-sub-orders",
"algo-recurring-buy",
];
for channel in channels {
let arg = WsSubscriptionArg::channel_only(channel);
assert_eq!(route_subscription(&arg), WsConnectionType::Business);
}
}
}