pub struct LightconeWebSocketClient { /* private fields */ }Expand description
Main WebSocket client for Lightcone
§Example
use lightcone_sdk::websocket::*;
use futures_util::StreamExt;
#[tokio::main]
async fn main() -> Result<(), WebSocketError> {
let mut client = LightconeWebSocketClient::connect("ws://api.lightcone.xyz:8081/ws").await?;
client.subscribe_book_updates(vec!["market1:ob1".to_string()]).await?;
while let Some(event) = client.next().await {
match event {
WsEvent::BookUpdate { orderbook_id, is_snapshot } => {
if let Some(book) = client.get_orderbook(&orderbook_id) {
println!("Best bid: {:?}", book.best_bid());
}
}
_ => {}
}
}
Ok(())
}Implementations§
Source§impl LightconeWebSocketClient
impl LightconeWebSocketClient
Sourcepub async fn connect_default() -> WsResult<Self>
pub async fn connect_default() -> WsResult<Self>
Sourcepub async fn connect(url: &str) -> WsResult<Self>
pub async fn connect(url: &str) -> WsResult<Self>
Connect to a WebSocket server with default configuration
Sourcepub async fn connect_authenticated(signing_key: &SigningKey) -> WsResult<Self>
pub async fn connect_authenticated(signing_key: &SigningKey) -> WsResult<Self>
Connect to the default Lightcone WebSocket server with authentication.
This method:
- Authenticates with the Lightcone API using the provided signing key
- Obtains an auth token
- Connects to the WebSocket server with the auth token
§Arguments
signing_key- The Ed25519 signing key for authentication
§Example
use ed25519_dalek::SigningKey;
let signing_key = SigningKey::from_bytes(&secret_key_bytes);
let client = LightconeWebSocketClient::connect_authenticated(&signing_key).await?;
client.subscribe_user(pubkey.to_string()).await?;Sourcepub async fn connect_authenticated_with_config(
signing_key: &SigningKey,
config: WebSocketConfig,
) -> WsResult<Self>
pub async fn connect_authenticated_with_config( signing_key: &SigningKey, config: WebSocketConfig, ) -> WsResult<Self>
Connect to the default Lightcone WebSocket server with authentication and custom config.
Sourcepub async fn connect_with_auth(url: &str, auth_token: String) -> WsResult<Self>
pub async fn connect_with_auth(url: &str, auth_token: String) -> WsResult<Self>
Connect to a WebSocket server with a pre-obtained auth token.
Use this if you already have an auth token from a previous authentication.
§Arguments
url- The WebSocket URL to connect toauth_token- The auth token obtained from authentication
Sourcepub async fn connect_with_config(
url: &str,
config: WebSocketConfig,
) -> WsResult<Self>
pub async fn connect_with_config( url: &str, config: WebSocketConfig, ) -> WsResult<Self>
Connect to a WebSocket server with custom configuration
Sourcepub async fn subscribe_book_updates(
&mut self,
orderbook_ids: Vec<String>,
) -> WsResult<()>
pub async fn subscribe_book_updates( &mut self, orderbook_ids: Vec<String>, ) -> WsResult<()>
Subscribe to orderbook updates
Sourcepub async fn subscribe_trades(
&mut self,
orderbook_ids: Vec<String>,
) -> WsResult<()>
pub async fn subscribe_trades( &mut self, orderbook_ids: Vec<String>, ) -> WsResult<()>
Subscribe to trade executions
Sourcepub async fn subscribe_user(&mut self, user: String) -> WsResult<()>
pub async fn subscribe_user(&mut self, user: String) -> WsResult<()>
Subscribe to user events
Sourcepub async fn subscribe_price_history(
&mut self,
orderbook_id: String,
resolution: String,
include_ohlcv: bool,
) -> WsResult<()>
pub async fn subscribe_price_history( &mut self, orderbook_id: String, resolution: String, include_ohlcv: bool, ) -> WsResult<()>
Subscribe to price history
Sourcepub async fn subscribe_market(&mut self, market_pubkey: String) -> WsResult<()>
pub async fn subscribe_market(&mut self, market_pubkey: String) -> WsResult<()>
Subscribe to market events
Sourcepub async fn unsubscribe_book_updates(
&mut self,
orderbook_ids: Vec<String>,
) -> WsResult<()>
pub async fn unsubscribe_book_updates( &mut self, orderbook_ids: Vec<String>, ) -> WsResult<()>
Unsubscribe from orderbook updates
Sourcepub async fn unsubscribe_trades(
&mut self,
orderbook_ids: Vec<String>,
) -> WsResult<()>
pub async fn unsubscribe_trades( &mut self, orderbook_ids: Vec<String>, ) -> WsResult<()>
Unsubscribe from trades
Sourcepub async fn unsubscribe_user(&mut self, user: String) -> WsResult<()>
pub async fn unsubscribe_user(&mut self, user: String) -> WsResult<()>
Unsubscribe from user events
Sourcepub async fn unsubscribe_price_history(
&mut self,
orderbook_id: String,
resolution: String,
) -> WsResult<()>
pub async fn unsubscribe_price_history( &mut self, orderbook_id: String, resolution: String, ) -> WsResult<()>
Unsubscribe from price history
Sourcepub async fn unsubscribe_market(
&mut self,
market_pubkey: String,
) -> WsResult<()>
pub async fn unsubscribe_market( &mut self, market_pubkey: String, ) -> WsResult<()>
Unsubscribe from market events
Sourcepub async fn disconnect(&mut self) -> WsResult<()>
pub async fn disconnect(&mut self) -> WsResult<()>
Disconnect from the server
Sourcepub fn is_task_running(&self) -> bool
pub fn is_task_running(&self) -> bool
Check if the connection task is still running
Sourcepub fn connection_state(&self) -> ConnectionState
pub fn connection_state(&self) -> ConnectionState
Get the current connection state
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Check if connected
Sourcepub fn is_authenticated(&self) -> bool
pub fn is_authenticated(&self) -> bool
Check if the connection is authenticated
Sourcepub fn auth_credentials(&self) -> Option<&AuthCredentials>
pub fn auth_credentials(&self) -> Option<&AuthCredentials>
Get the authentication credentials if available
Sourcepub fn user_pubkey(&self) -> Option<&str>
pub fn user_pubkey(&self) -> Option<&str>
Get the user’s public key if authenticated
Sourcepub async fn get_orderbook(&self, orderbook_id: &str) -> Option<LocalOrderbook>
pub async fn get_orderbook(&self, orderbook_id: &str) -> Option<LocalOrderbook>
Get a reference to the local orderbook state.
Sourcepub async fn get_user_state(&self, user: &str) -> Option<UserState>
pub async fn get_user_state(&self, user: &str) -> Option<UserState>
Get a reference to the local user state.
Sourcepub async fn get_price_history(
&self,
orderbook_id: &str,
resolution: &str,
) -> Option<PriceHistory>
pub async fn get_price_history( &self, orderbook_id: &str, resolution: &str, ) -> Option<PriceHistory>
Get a reference to the price history state.
Sourcepub fn config(&self) -> &WebSocketConfig
pub fn config(&self) -> &WebSocketConfig
Get the configuration
Trait Implementations§
Source§impl Stream for LightconeWebSocketClient
impl Stream for LightconeWebSocketClient
impl<'__pin> Unpin for LightconeWebSocketClientwhere
PinnedFieldsOf<__Origin<'__pin>>: Unpin,
Auto Trait Implementations§
impl Freeze for LightconeWebSocketClient
impl !RefUnwindSafe for LightconeWebSocketClient
impl Send for LightconeWebSocketClient
impl Sync for LightconeWebSocketClient
impl !UnwindSafe for LightconeWebSocketClient
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<St> StreamExt for St
impl<St> StreamExt for St
Source§fn next(&mut self) -> Next<'_, Self>where
Self: Unpin,
fn next(&mut self) -> Next<'_, Self>where
Self: Unpin,
None if the
stream is finished. Read moreSource§fn try_next<T, E>(&mut self) -> TryNext<'_, Self>
fn try_next<T, E>(&mut self) -> TryNext<'_, Self>
Source§fn map<T, F>(self, f: F) -> Map<Self, F>
fn map<T, F>(self, f: F) -> Map<Self, F>
Source§fn map_while<T, F>(self, f: F) -> MapWhile<Self, F>
fn map_while<T, F>(self, f: F) -> MapWhile<Self, F>
None. Read moreSource§fn then<F, Fut>(self, f: F) -> Then<Self, Fut, F>
fn then<F, Fut>(self, f: F) -> Then<Self, Fut, F>
Source§fn merge<U>(self, other: U) -> Merge<Self, U>
fn merge<U>(self, other: U) -> Merge<Self, U>
Source§fn filter<F>(self, f: F) -> Filter<Self, F>
fn filter<F>(self, f: F) -> Filter<Self, F>
Source§fn filter_map<T, F>(self, f: F) -> FilterMap<Self, F>
fn filter_map<T, F>(self, f: F) -> FilterMap<Self, F>
Source§fn fuse(self) -> Fuse<Self>where
Self: Sized,
fn fuse(self) -> Fuse<Self>where
Self: Sized,
None. Read moreSource§fn take(self, n: usize) -> Take<Self>where
Self: Sized,
fn take(self, n: usize) -> Take<Self>where
Self: Sized,
n items of the underlying stream. Read moreSource§fn take_while<F>(self, f: F) -> TakeWhile<Self, F>
fn take_while<F>(self, f: F) -> TakeWhile<Self, F>
true. Read moreSource§fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
n first items of the
underlying stream. Read moreSource§fn skip_while<F>(self, f: F) -> SkipWhile<Self, F>
fn skip_while<F>(self, f: F) -> SkipWhile<Self, F>
true. Read moreSource§fn all<F>(&mut self, f: F) -> AllFuture<'_, Self, F>
fn all<F>(&mut self, f: F) -> AllFuture<'_, Self, F>
Source§fn any<F>(&mut self, f: F) -> AnyFuture<'_, Self, F>
fn any<F>(&mut self, f: F) -> AnyFuture<'_, Self, F>
Source§fn chain<U>(self, other: U) -> Chain<Self, U>
fn chain<U>(self, other: U) -> Chain<Self, U>
Source§fn fold<B, F>(self, init: B, f: F) -> FoldFuture<Self, B, F>
fn fold<B, F>(self, init: B, f: F) -> FoldFuture<Self, B, F>
Source§fn collect<T>(
self,
) -> Collect<Self, T, <T as FromStreamPriv<Self::Item>>::InternalCollection>
fn collect<T>( self, ) -> Collect<Self, T, <T as FromStreamPriv<Self::Item>>::InternalCollection>
Source§fn timeout(self, duration: Duration) -> Timeout<Self>where
Self: Sized,
fn timeout(self, duration: Duration) -> Timeout<Self>where
Self: Sized,
Source§fn timeout_repeating(self, interval: Interval) -> TimeoutRepeating<Self>where
Self: Sized,
fn timeout_repeating(self, interval: Interval) -> TimeoutRepeating<Self>where
Self: Sized,
Source§fn throttle(self, duration: Duration) -> Throttle<Self>where
Self: Sized,
fn throttle(self, duration: Duration) -> Throttle<Self>where
Self: Sized,
Source§fn chunks_timeout(
self,
max_size: usize,
duration: Duration,
) -> ChunksTimeout<Self>where
Self: Sized,
fn chunks_timeout(
self,
max_size: usize,
duration: Duration,
) -> ChunksTimeout<Self>where
Self: Sized,
Source§impl<T> StreamExt for T
impl<T> StreamExt for T
Source§fn next(&mut self) -> Next<'_, Self>where
Self: Unpin,
fn next(&mut self) -> Next<'_, Self>where
Self: Unpin,
Source§fn into_future(self) -> StreamFuture<Self>
fn into_future(self) -> StreamFuture<Self>
Source§fn map<T, F>(self, f: F) -> Map<Self, F>
fn map<T, F>(self, f: F) -> Map<Self, F>
Source§fn enumerate(self) -> Enumerate<Self>where
Self: Sized,
fn enumerate(self) -> Enumerate<Self>where
Self: Sized,
Source§fn filter<Fut, F>(self, f: F) -> Filter<Self, Fut, F>
fn filter<Fut, F>(self, f: F) -> Filter<Self, Fut, F>
Source§fn filter_map<Fut, T, F>(self, f: F) -> FilterMap<Self, Fut, F>
fn filter_map<Fut, T, F>(self, f: F) -> FilterMap<Self, Fut, F>
Source§fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
Source§fn collect<C>(self) -> Collect<Self, C>
fn collect<C>(self) -> Collect<Self, C>
Source§fn unzip<A, B, FromA, FromB>(self) -> Unzip<Self, FromA, FromB>
fn unzip<A, B, FromA, FromB>(self) -> Unzip<Self, FromA, FromB>
Source§fn concat(self) -> Concat<Self>
fn concat(self) -> Concat<Self>
Source§fn count(self) -> Count<Self>where
Self: Sized,
fn count(self) -> Count<Self>where
Self: Sized,
Source§fn fold<T, Fut, F>(self, init: T, f: F) -> Fold<Self, Fut, T, F>
fn fold<T, Fut, F>(self, init: T, f: F) -> Fold<Self, Fut, T, F>
Source§fn any<Fut, F>(self, f: F) -> Any<Self, Fut, F>
fn any<Fut, F>(self, f: F) -> Any<Self, Fut, F>
true if any element in stream satisfied a predicate. Read moreSource§fn all<Fut, F>(self, f: F) -> All<Self, Fut, F>
fn all<Fut, F>(self, f: F) -> All<Self, Fut, F>
true if all element in stream satisfied a predicate. Read moreSource§fn flatten(self) -> Flatten<Self>
fn flatten(self) -> Flatten<Self>
Source§fn flatten_unordered(
self,
limit: impl Into<Option<usize>>,
) -> FlattenUnorderedWithFlowController<Self, ()>
fn flatten_unordered( self, limit: impl Into<Option<usize>>, ) -> FlattenUnorderedWithFlowController<Self, ()>
Source§fn flat_map_unordered<U, F>(
self,
limit: impl Into<Option<usize>>,
f: F,
) -> FlatMapUnordered<Self, U, F>
fn flat_map_unordered<U, F>( self, limit: impl Into<Option<usize>>, f: F, ) -> FlatMapUnordered<Self, U, F>
StreamExt::map but flattens nested Streams
and polls them concurrently, yielding items in any order, as they made
available. Read moreSource§fn scan<S, B, Fut, F>(self, initial_state: S, f: F) -> Scan<Self, S, Fut, F>
fn scan<S, B, Fut, F>(self, initial_state: S, f: F) -> Scan<Self, S, Fut, F>
StreamExt::fold that holds internal state
and produces a new stream. Read moreSource§fn skip_while<Fut, F>(self, f: F) -> SkipWhile<Self, Fut, F>
fn skip_while<Fut, F>(self, f: F) -> SkipWhile<Self, Fut, F>
true. Read moreSource§fn take_while<Fut, F>(self, f: F) -> TakeWhile<Self, Fut, F>
fn take_while<Fut, F>(self, f: F) -> TakeWhile<Self, Fut, F>
true. Read moreSource§fn take_until<Fut>(self, fut: Fut) -> TakeUntil<Self, Fut>
fn take_until<Fut>(self, fut: Fut) -> TakeUntil<Self, Fut>
Source§fn for_each<Fut, F>(self, f: F) -> ForEach<Self, Fut, F>
fn for_each<Fut, F>(self, f: F) -> ForEach<Self, Fut, F>
Source§fn for_each_concurrent<Fut, F>(
self,
limit: impl Into<Option<usize>>,
f: F,
) -> ForEachConcurrent<Self, Fut, F>
fn for_each_concurrent<Fut, F>( self, limit: impl Into<Option<usize>>, f: F, ) -> ForEachConcurrent<Self, Fut, F>
Source§fn take(self, n: usize) -> Take<Self>where
Self: Sized,
fn take(self, n: usize) -> Take<Self>where
Self: Sized,
n items of the underlying stream. Read moreSource§fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
n items of the underlying stream. Read moreSource§fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
Source§fn boxed<'a>(self) -> Pin<Box<dyn Stream<Item = Self::Item> + Send + 'a>>
fn boxed<'a>(self) -> Pin<Box<dyn Stream<Item = Self::Item> + Send + 'a>>
Source§fn boxed_local<'a>(self) -> Pin<Box<dyn Stream<Item = Self::Item> + 'a>>where
Self: Sized + 'a,
fn boxed_local<'a>(self) -> Pin<Box<dyn Stream<Item = Self::Item> + 'a>>where
Self: Sized + 'a,
Source§fn buffered(self, n: usize) -> Buffered<Self>
fn buffered(self, n: usize) -> Buffered<Self>
Source§fn buffer_unordered(self, n: usize) -> BufferUnordered<Self>
fn buffer_unordered(self, n: usize) -> BufferUnordered<Self>
Source§fn zip<St>(self, other: St) -> Zip<Self, St>
fn zip<St>(self, other: St) -> Zip<Self, St>
Source§fn peekable(self) -> Peekable<Self>where
Self: Sized,
fn peekable(self) -> Peekable<Self>where
Self: Sized,
peek method. Read moreSource§fn chunks(self, capacity: usize) -> Chunks<Self>where
Self: Sized,
fn chunks(self, capacity: usize) -> Chunks<Self>where
Self: Sized,
Source§fn ready_chunks(self, capacity: usize) -> ReadyChunks<Self>where
Self: Sized,
fn ready_chunks(self, capacity: usize) -> ReadyChunks<Self>where
Self: Sized,
Source§fn forward<S>(self, sink: S) -> Forward<Self, S>
fn forward<S>(self, sink: S) -> Forward<Self, S>
Source§fn split<Item>(self) -> (SplitSink<Self, Item>, SplitStream<Self>)
fn split<Item>(self) -> (SplitSink<Self, Item>, SplitStream<Self>)
Source§fn inspect<F>(self, f: F) -> Inspect<Self, F>
fn inspect<F>(self, f: F) -> Inspect<Self, F>
Source§fn left_stream<B>(self) -> Either<Self, B>
fn left_stream<B>(self) -> Either<Self, B>
Source§fn right_stream<B>(self) -> Either<B, Self>
fn right_stream<B>(self) -> Either<B, Self>
Source§fn poll_next_unpin(&mut self, cx: &mut Context<'_>) -> Poll<Option<Self::Item>>where
Self: Unpin,
fn poll_next_unpin(&mut self, cx: &mut Context<'_>) -> Poll<Option<Self::Item>>where
Self: Unpin,
Stream::poll_next on Unpin
stream types.