Trait barter_data::Subscriber
source · [−]pub trait Subscriber {
type SubResponse: Validator + DeserializeOwned;
fn base_url() -> &'static str;
fn build_subscription_meta(
subscriptions: &[Subscription]
) -> Result<SubscriptionMeta, SocketError>;
fn subscribe<'life0, 'async_trait>(
subscriptions: &'life0 [Subscription]
) -> Pin<Box<dyn Future<Output = Result<(WebSocket, SubscriptionIds), SocketError>> + Send + 'async_trait>>
where
'life0: 'async_trait,
Self: Send + 'async_trait,
{ ... }
fn validate<'life0, 'async_trait>(
ids: SubscriptionIds,
websocket: &'life0 mut WebSocket,
expected_responses: usize
) -> Pin<Box<dyn Future<Output = Result<SubscriptionIds, SocketError>> + Send + 'async_trait>>
where
'life0: 'async_trait,
Self: Send + 'async_trait,
{ ... }
fn subscription_timeout() -> Duration { ... }
}Expand description
Trait that defines how a subscriber will establish a WebSocket connection with an exchange,
and action Subscriptions. This must be implemented when integrating a new exchange.
Required Associated Types
sourcetype SubResponse: Validator + DeserializeOwned
type SubResponse: Validator + DeserializeOwned
Deserialisable type that this Subscriber expects to receive from the exchange in
response to Subscription requests. Implements Validator in order to determine
if the SubResponse communicates a successful outcome.
Required Methods
sourcefn base_url() -> &'static str
fn base_url() -> &'static str
Returns the Base URL of the exchange to establish a connection with.
sourcefn build_subscription_meta(
subscriptions: &[Subscription]
) -> Result<SubscriptionMeta, SocketError>
fn build_subscription_meta(
subscriptions: &[Subscription]
) -> Result<SubscriptionMeta, SocketError>
Uses the provided Barter Subscriptions to build exchange specific subscription
payloads. Generates a SubscriptionIds Hashmap that is used by an ExchangeTransformer
to identify the Barter Subscriptions associated with received messages.
Provided Methods
sourcefn subscribe<'life0, 'async_trait>(
subscriptions: &'life0 [Subscription]
) -> Pin<Box<dyn Future<Output = Result<(WebSocket, SubscriptionIds), SocketError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: Send + 'async_trait,
fn subscribe<'life0, 'async_trait>(
subscriptions: &'life0 [Subscription]
) -> Pin<Box<dyn Future<Output = Result<(WebSocket, SubscriptionIds), SocketError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: Send + 'async_trait,
Initialises a WebSocket connection, actions the provided collection of Barter
Subscriptions, and validates that the Subscription were accepted by the exchange.
sourcefn validate<'life0, 'async_trait>(
ids: SubscriptionIds,
websocket: &'life0 mut WebSocket,
expected_responses: usize
) -> Pin<Box<dyn Future<Output = Result<SubscriptionIds, SocketError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: Send + 'async_trait,
fn validate<'life0, 'async_trait>(
ids: SubscriptionIds,
websocket: &'life0 mut WebSocket,
expected_responses: usize
) -> Pin<Box<dyn Future<Output = Result<SubscriptionIds, SocketError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: Send + 'async_trait,
Uses the provided WebSocket connection to consume Subscription responses and
validate their outcomes.
sourcefn subscription_timeout() -> Duration
fn subscription_timeout() -> Duration
Return the expected Duration in which the exchange will respond to all actioned
WebSocket Subscription requests.
Default: 10 seconds