nautilus_okx/websocket/
subscription.rs1use ustr::Ustr;
19
20use crate::{
21 common::enums::OKXInstrumentType,
22 websocket::{
23 enums::OKXWsChannel,
24 messages::{OKXSubscriptionArg, OKXWebSocketArg},
25 },
26};
27
28fn topic_from_parts(
29 channel: &OKXWsChannel,
30 inst_id: Option<&Ustr>,
31 inst_family: Option<&Ustr>,
32 inst_type: Option<&OKXInstrumentType>,
33 bar: Option<&Ustr>,
34) -> String {
35 let base = channel.as_ref();
36
37 if let Some(inst_id) = inst_id {
38 let inst_id = inst_id.as_str();
39
40 if let Some(bar) = bar {
41 format!("{base}:{inst_id}:{}", bar.as_str())
42 } else {
43 format!("{base}:{inst_id}")
44 }
45 } else if let Some(inst_family) = inst_family {
46 format!("{base}:{}", inst_family.as_str())
47 } else if let Some(inst_type) = inst_type {
48 format!("{base}:{}", inst_type.as_ref())
49 } else {
50 base.to_string()
51 }
52}
53
54pub(crate) fn topic_from_subscription_arg(arg: &OKXSubscriptionArg) -> String {
55 topic_from_parts(
56 &arg.channel,
57 arg.inst_id.as_ref(),
58 arg.inst_family.as_ref(),
59 arg.inst_type.as_ref(),
60 None,
61 )
62}
63
64pub(crate) fn topic_from_websocket_arg(arg: &OKXWebSocketArg) -> String {
65 topic_from_parts(
66 &arg.channel,
67 arg.inst_id.as_ref(),
68 arg.inst_family.as_ref(),
69 arg.inst_type.as_ref(),
70 arg.bar.as_ref(),
71 )
72}