use std::time::Duration;
use serde_json::Value;
use tokio_tungstenite::tungstenite::Message;
use url::Url;
use crate::core::traits::Credentials;
use crate::core::types::{AccountType, WebSocketError};
use super::{
stream_kind::StreamKind,
stream_spec::StreamSpec,
topic_registry::{TopicKey, TopicRegistry},
};
pub trait WsProtocol: Send + Sync + 'static {
fn name(&self) -> &'static str;
fn endpoint(&self, account_type: AccountType, testnet: bool) -> Url;
fn ping_frame(&self) -> Option<Message>;
fn ping_interval(&self) -> Duration {
Duration::from_secs(30)
}
fn subscribe_frame(&self, spec: &StreamSpec) -> Result<Message, WebSocketError>;
fn unsubscribe_frame(&self, spec: &StreamSpec) -> Result<Message, WebSocketError>;
fn auth_frame(&self, credentials: &Credentials) -> Option<Result<Message, WebSocketError>>;
fn auth_ack_timeout(&self) -> Duration {
Duration::from_secs(5)
}
fn is_auth_ack(&self, raw: &Value) -> bool {
let _ = raw;
false
}
fn extract_topic(&self, raw: &Value) -> Option<TopicKey>;
fn is_pong(&self, raw: &Value) -> bool {
let _ = raw;
false
}
fn is_subscribe_ack(&self, raw: &Value) -> bool {
let _ = raw;
false
}
fn topic_registry(&self, account_type: AccountType) -> &TopicRegistry;
fn unsupported_by_exchange(&self, account_type: AccountType) -> &'static [StreamKind] {
let _ = account_type;
&[]
}
fn requires_auth_kinds(&self, account_type: AccountType) -> &'static [StreamKind] {
let _ = account_type;
&[]
}
fn decode_binary(&self, bytes: &[u8]) -> Result<Value, WebSocketError> {
crate::core::websocket::transport::decode_binary_default(bytes)
}
fn pre_connect_hook<'a>(
&'a self,
_http: &'a reqwest::Client,
_account_type: AccountType,
_testnet: bool,
) -> std::pin::Pin<
Box<dyn std::future::Future<Output = Result<Option<Url>, WebSocketError>> + Send + 'a>,
> {
Box::pin(std::future::ready(Ok(None)))
}
}