pub struct TitanClient { /* private fields */ }Expand description
Titan Exchange WebSocket client.
Thread-safe client for interacting with the Titan Exchange API.
Can be shared across axum handlers via Arc<TitanClient>.
Implementations§
Source§impl TitanClient
impl TitanClient
Sourcepub async fn new(config: TitanConfig) -> Result<Self, TitanClientError>
pub async fn new(config: TitanConfig) -> Result<Self, TitanClientError>
Create a new client with the given configuration.
Connects eagerly and fetches server info to determine stream limits.
Sourcepub async fn state_receiver(&self) -> Receiver<ConnectionState>
pub async fn state_receiver(&self) -> Receiver<ConnectionState>
Returns a watch receiver for connection state changes.
Use this to observe state transitions (Connected, Reconnecting, Disconnected).
Sourcepub async fn state(&self) -> ConnectionState
pub async fn state(&self) -> ConnectionState
Get the current connection state.
Sourcepub async fn is_connected(&self) -> bool
pub async fn is_connected(&self) -> bool
Returns true if currently connected.
Sourcepub async fn wait_for_connected(&self) -> Result<(), TitanClientError>
pub async fn wait_for_connected(&self) -> Result<(), TitanClientError>
Wait until the connection is established.
Returns immediately if already connected. Returns error if connection is permanently closed.
Sourcepub async fn active_stream_count(&self) -> u32
pub async fn active_stream_count(&self) -> u32
Get the current active stream count.
Sourcepub async fn queued_stream_count(&self) -> usize
pub async fn queued_stream_count(&self) -> usize
Get the current queue length.
Sourcepub async fn close(&self) -> Result<(), TitanClientError>
pub async fn close(&self) -> Result<(), TitanClientError>
Graceful shutdown: stops all streams, then closes WebSocket.
This method:
- Sends StopStream for all active streams
- Clears the stream manager
- Closes the WebSocket connection
After calling this, the client cannot be reused.
Sourcepub async fn get_info(&self) -> Result<ServerInfo, TitanClientError>
pub async fn get_info(&self) -> Result<ServerInfo, TitanClientError>
Get server info and connection limits.
Sourcepub async fn get_venues(&self) -> Result<VenueInfo, TitanClientError>
pub async fn get_venues(&self) -> Result<VenueInfo, TitanClientError>
Get available venues.
Sourcepub async fn list_providers(
&self,
) -> Result<Vec<ProviderInfo>, TitanClientError>
pub async fn list_providers( &self, ) -> Result<Vec<ProviderInfo>, TitanClientError>
List available providers.
Sourcepub async fn get_swap_price(
&self,
request: SwapPriceRequest,
) -> Result<SwapPrice, TitanClientError>
pub async fn get_swap_price( &self, request: SwapPriceRequest, ) -> Result<SwapPrice, TitanClientError>
Get a point-in-time swap price.
Sourcepub async fn new_swap_quote_stream(
&self,
request: SwapQuoteRequest,
) -> Result<QuoteStream, TitanClientError>
pub async fn new_swap_quote_stream( &self, request: SwapQuoteRequest, ) -> Result<QuoteStream, TitanClientError>
Start a new swap quote stream.
Returns a QuoteStream that yields SwapQuotes updates.
The stream automatically sends StopStream when dropped.
If the server’s max concurrent streams limit is reached, the request will be queued and started automatically when a slot becomes available.
Auto Trait Implementations§
impl Freeze for TitanClient
impl !RefUnwindSafe for TitanClient
impl Send for TitanClient
impl Sync for TitanClient
impl Unpin for TitanClient
impl !UnwindSafe for TitanClient
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 more