polyte_clob/ws/
subscription.rs

1//! WebSocket subscription message types.
2
3use serde::{Deserialize, Serialize};
4
5use super::auth::ApiCredentials;
6
7/// WebSocket endpoint URL for market channel
8pub const WS_MARKET_URL: &str = "wss://ws-subscriptions-clob.polymarket.com/ws/market";
9
10/// WebSocket endpoint URL for user channel
11pub const WS_USER_URL: &str = "wss://ws-subscriptions-clob.polymarket.com/ws/user";
12
13/// Channel type for WebSocket subscription
14#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
15#[serde(rename_all = "lowercase")]
16pub enum ChannelType {
17    /// Market channel for public order book and price updates
18    Market,
19    /// User channel for authenticated order and trade updates
20    User,
21}
22
23/// Subscription message for market channel
24#[derive(Debug, Clone, Serialize, Deserialize)]
25pub struct MarketSubscription {
26    /// Asset IDs (token IDs) to subscribe to
27    pub assets_ids: Vec<String>,
28    /// Channel type (always "market")
29    #[serde(rename = "type")]
30    pub channel_type: ChannelType,
31}
32
33impl MarketSubscription {
34    /// Create a new market subscription
35    pub fn new(assets_ids: Vec<String>) -> Self {
36        Self {
37            assets_ids,
38            channel_type: ChannelType::Market,
39        }
40    }
41}
42
43/// Subscription message for user channel
44#[derive(Debug, Clone, Serialize, Deserialize)]
45pub struct UserSubscription {
46    /// Market condition IDs to subscribe to
47    pub markets: Vec<String>,
48    /// Authentication credentials
49    pub auth: ApiCredentials,
50    /// Channel type (always "user")
51    #[serde(rename = "type")]
52    pub channel_type: ChannelType,
53}
54
55impl UserSubscription {
56    /// Create a new user subscription
57    pub fn new(markets: Vec<String>, credentials: ApiCredentials) -> Self {
58        Self {
59            markets,
60            auth: credentials,
61            channel_type: ChannelType::User,
62        }
63    }
64}