mod discovery;
mod stream;
pub use discovery::{discover_markets, ShortFormMarket};
pub use stream::ShortFormStream;
use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ShortFormInterval {
FiveMin,
FifteenMin,
Hourly,
}
impl ShortFormInterval {
pub fn window_seconds(self) -> i64 {
match self {
Self::FiveMin => 300,
Self::FifteenMin => 900,
Self::Hourly => 3600,
}
}
pub fn slug_suffix(self) -> &'static str {
match self {
Self::FiveMin => "5m",
Self::FifteenMin => "15m",
Self::Hourly => "hourly",
}
}
pub fn price_variant(self) -> &'static str {
match self {
Self::FiveMin => "fiveminute",
Self::FifteenMin => "fifteen",
Self::Hourly => "hourly",
}
}
}
impl fmt::Display for ShortFormInterval {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::FiveMin => write!(f, "5m"),
Self::FifteenMin => write!(f, "15m"),
Self::Hourly => write!(f, "1h"),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Coin {
Btc,
Eth,
Sol,
Xrp,
Doge,
Hype,
Bnb,
}
impl Coin {
pub fn id(self) -> &'static str {
match self {
Self::Btc => "btc",
Self::Eth => "eth",
Self::Sol => "sol",
Self::Xrp => "xrp",
Self::Doge => "doge",
Self::Hype => "hype",
Self::Bnb => "bnb",
}
}
pub fn symbol(self) -> &'static str {
match self {
Self::Btc => "BTC",
Self::Eth => "ETH",
Self::Sol => "SOL",
Self::Xrp => "XRP",
Self::Doge => "DOGE",
Self::Hype => "HYPE",
Self::Bnb => "BNB",
}
}
pub fn full_name(self) -> &'static str {
match self {
Self::Btc => "bitcoin",
Self::Eth => "ethereum",
Self::Sol => "solana",
Self::Xrp => "xrp",
Self::Doge => "dogecoin",
Self::Hype => "hype",
Self::Bnb => "bnb",
}
}
pub fn all() -> &'static [Coin] {
&[
Self::Btc,
Self::Eth,
Self::Sol,
Self::Xrp,
Self::Doge,
Self::Hype,
Self::Bnb,
]
}
}
#[derive(Debug)]
pub enum ShortFormMessage {
Event(crate::types::events::PolyNodeEvent),
Rotation(RotationInfo),
Error(String),
}
#[derive(Debug, Clone)]
pub struct RotationInfo {
pub interval: ShortFormInterval,
pub markets: Vec<ShortFormMarket>,
pub window_start: i64,
pub window_end: i64,
pub time_remaining: i64,
}
pub struct ShortFormBuilder<'a> {
pub(crate) client: &'a crate::PolyNodeClient,
pub(crate) interval: ShortFormInterval,
pub(crate) coins: Option<Vec<Coin>>,
pub(crate) rotation_buffer: u64,
}
impl<'a> ShortFormBuilder<'a> {
pub fn coins(mut self, coins: &[Coin]) -> Self {
self.coins = Some(coins.to_vec());
self
}
pub fn rotation_buffer(mut self, seconds: u64) -> Self {
self.rotation_buffer = seconds;
self
}
pub async fn start(self) -> crate::Result<ShortFormStream> {
ShortFormStream::start(
self.client,
self.interval,
self.coins.unwrap_or_else(|| Coin::all().to_vec()),
self.rotation_buffer,
)
.await
}
}