pub trait AssetInfoProvider: Send + Sync {
type SubscriptionError: Display;
type ListeningError: Display;
// Required methods
fn subscribe<'life0, 'life1, 'async_trait>(
&'life0 mut self,
ids: &'life1 [String],
) -> Pin<Box<dyn Future<Output = Result<(), Self::SubscriptionError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn next<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Option<Result<Data, Self::ListeningError>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn try_close<'async_trait>(
self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait;
}Expand description
Trait for providers that can stream asset information from WebSocket APIs.
This trait defines the interface that WebSocket-based asset information providers
must implement. Providers are responsible for subscribing to asset updates,
receiving and parsing WebSocket messages, and converting them into Data structures.
Required Associated Types§
Sourcetype SubscriptionError: Display
type SubscriptionError: Display
The type returned in the event of a subscription failure.
This should be a custom error type that implements the Display trait and captures all possible error conditions during subscription.
Sourcetype ListeningError: Display
type ListeningError: Display
The type returned in the event of a message reception failure.
This should be a custom error type that implements the Display trait and captures all possible error conditions during message reception.
Required Methods§
Sourcefn subscribe<'life0, 'life1, 'async_trait>(
&'life0 mut self,
ids: &'life1 [String],
) -> Pin<Box<dyn Future<Output = Result<(), Self::SubscriptionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn subscribe<'life0, 'life1, 'async_trait>(
&'life0 mut self,
ids: &'life1 [String],
) -> Pin<Box<dyn Future<Output = Result<(), Self::SubscriptionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Subscribes to asset updates for the specified asset IDs.
This method should send subscription requests to the WebSocket API for each of the specified asset IDs, configuring the connection to receive updates for these assets.
§Errors
Returns a subscription-specific error if the operation fails, such as when the API rejects the subscription request or the request can’t be sent.
Sourcefn next<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Option<Result<Data, Self::ListeningError>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn next<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Option<Result<Data, Self::ListeningError>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Waits for and returns the next data update from the WebSocket.
This method should wait for the next WebSocket message, parse it, and return the appropriate data structure. It returns None if the connection has been closed.
§Returns
Some(Ok(Data))- If a message was successfully received and parsedSome(Err(ListeningError))- If there was an error receiving or parsing the messageNone- If the connection has been closed
Sourcefn try_close<'async_trait>(
self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
fn try_close<'async_trait>(
self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
Attempts to gracefully close the WebSocket connection.
This method should send a close frame to the WebSocket server and perform any necessary cleanup. It may fail silently if the connection is already closed.