#![cfg_attr(test, allow(clippy::duplicate_mod))]
pub mod client;
pub mod error;
pub mod event;
#[cfg(any(test, feature = "test-server"))]
#[doc(hidden)]
pub mod fixtures;
mod protocol;
#[cfg(test)]
#[path = "../../usdm/ws/scripted.rs"]
mod scripted;
pub mod stream;
pub mod supervised;
use std::{fmt, time::Duration};
pub use client::SpotWs;
pub use error::{SpotWsError, StopCause};
pub use event::{
AggTradeEvent, AvgPriceEvent, BookTickerEvent, KlineBar, KlineEvent, MiniTickerEvent,
PartialDepthEvent, Payload, TickerEvent, TradeEvent, Update,
};
pub use stream::{DepthLevels, DepthSpeed, InvalidStreamName, StreamName};
pub use supervised::{DisconnectReason, Event, MembershipHandle, SpotWsBuilder, SupervisedSpotWs};
pub const SPOT_WS_BASE: &str = "wss://stream.binance.com:9443";
pub const MAX_STREAMS_PER_CONNECTION: usize = crate::shared::ws::MAX_STREAMS_PER_CONNECTION;
pub const MAX_NAMES_PER_REQUEST: usize = 1024;
pub const MIN_REQUEST_INTERVAL: Duration = Duration::from_millis(500);
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum StreamPath {
Stream,
}
impl StreamPath {
pub const ALL: &'static [Self] = &[Self::Stream];
pub fn as_str(self) -> &'static str {
match self {
Self::Stream => "stream",
}
}
pub(crate) fn url(self, base: &str) -> String {
format!("{}/{}", base.trim_end_matches('/'), self.as_str())
}
}
impl fmt::Display for StreamPath {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn spot_has_one_path_and_it_is_stream() {
assert_eq!(StreamPath::ALL, &[StreamPath::Stream]);
assert_eq!(StreamPath::Stream.as_str(), "stream");
assert_eq!(StreamPath::Stream.to_string(), "stream");
}
#[test]
fn the_url_appends_the_one_path_to_the_base() {
assert_eq!(
StreamPath::Stream.url(SPOT_WS_BASE),
"wss://stream.binance.com:9443/stream"
);
assert_eq!(
StreamPath::Stream.url("ws://127.0.0.1:4000"),
"ws://127.0.0.1:4000/stream"
);
assert_eq!(
StreamPath::Stream.url("ws://127.0.0.1:4000/"),
"ws://127.0.0.1:4000/stream"
);
}
#[test]
fn the_limits_are_the_measured_ones() {
assert_eq!(MAX_STREAMS_PER_CONNECTION, 1024);
assert_eq!(MAX_NAMES_PER_REQUEST, 1024);
assert_eq!(MIN_REQUEST_INTERVAL, Duration::from_millis(500));
}
}