acta_maker_sdk/ws/managed/
endpoint.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2#[non_exhaustive]
3pub enum MakerWsEndpoint {
4 Quote,
5 Data,
6 Vault,
8}
9
10impl MakerWsEndpoint {
11 const fn path(self) -> &'static str {
12 match self {
13 Self::Quote => "/maker",
14 Self::Data => "/maker/data",
15 Self::Vault => "/vault",
16 }
17 }
18}
19
20#[must_use]
22pub fn normalize_maker_ws_url_for_endpoint(url: &str, endpoint: MakerWsEndpoint) -> String {
23 format!("{}{}", ws_base_url(url), endpoint.path())
24}
25
26pub(crate) fn ws_base_url(url: &str) -> String {
28 let url = url.trim().trim_end_matches('/');
29 let url: std::borrow::Cow<'_, str> = if let Some(rest) = url.strip_prefix("http://") {
30 format!("ws://{rest}").into()
31 } else if let Some(rest) = url.strip_prefix("https://") {
32 format!("wss://{rest}").into()
33 } else {
34 url.into()
35 };
36 let base = if let Some(base) = url.strip_suffix("/maker/data") {
37 base
38 } else if let Some(base) = url.strip_suffix("/maker") {
39 base
40 } else if let Some(base) = url.strip_suffix("/vault") {
41 base
42 } else if let Some(base) = url.strip_suffix("/taker") {
43 base
44 } else {
45 url.as_ref()
46 };
47 base.to_owned()
48}
49
50#[must_use]
51pub fn normalize_maker_ws_url(url: &str) -> String {
52 normalize_maker_ws_url_for_endpoint(url, MakerWsEndpoint::Quote)
53}
54
55#[must_use]
56pub fn normalize_maker_data_ws_url(url: &str) -> String {
57 normalize_maker_ws_url_for_endpoint(url, MakerWsEndpoint::Data)
58}