use std::sync::Arc;
use crate::shared::config::WebSocketClientConfig;
pub(in crate::api_v2) mod error;
mod lnm;
pub(in crate::api_v2) mod models;
pub(in crate::api_v2) mod repositories;
pub(in crate::api_v2) mod state;
use error::Result;
use lnm::LnmWebSocketRepo;
use repositories::WebSocketRepository;
use tokio::sync::Mutex;
pub type WebSocketConnection = Arc<dyn WebSocketRepository>;
#[deprecated(
since = "0.4.1",
note = "LN Markets disabled the v2 WebSocket API on Mar 31 2026. Retained for reference only."
)]
pub struct WebSocketClient {
config: WebSocketClientConfig,
domain: String,
conn: Mutex<Option<WebSocketConnection>>,
}
#[allow(deprecated)]
impl WebSocketClient {
pub fn new(config: impl Into<WebSocketClientConfig>, domain: impl ToString) -> Arc<Self> {
Arc::new(Self {
config: config.into(),
domain: domain.to_string(),
conn: Mutex::new(None),
})
}
pub async fn connect(&self) -> Result<WebSocketConnection> {
let mut conn_guard = self.conn.lock().await;
if let Some(conn) = conn_guard.as_ref()
&& conn.is_connected().await
{
return Ok(conn.clone());
}
let new_conn =
Arc::new(LnmWebSocketRepo::new(self.config.clone(), self.domain.clone()).await?);
*conn_guard = Some(new_conn.clone());
Ok(new_conn)
}
pub async fn reset(&self) {
let mut conn_guard = self.conn.lock().await;
*conn_guard = None;
}
}