pub struct CoinApiWebSocketClient { /* private fields */ }Expand description
Authenticated, data-only CoinAPI WebSocket client using one connection.
CoinAPI tiers can limit an organization to one concurrent connection. Subscription changes send
a hello that replaces the whole session scope; changes applied together share one hello,
and the client sends at most one every two seconds, including across connection recreation.
Because CoinAPI combines every listed data type, symbol, and period, the client drops frames
outside the subscribed pairs; the provider still bills for them. A scope can list only one
book type. Removing the last subscription closes the connection, and the next subscription
opens a new one. Reconnects replay the scope and emit CoinApiWsMessage::Reconnected.
Implementations§
Source§impl CoinApiWebSocketClient
impl CoinApiWebSocketClient
Sourcepub fn new(
api_key: SecretString,
config: CoinApiWebSocketConfig,
) -> Result<(Self, UnboundedReceiver<CoinApiWsMessage>), Error>
pub fn new( api_key: SecretString, config: CoinApiWebSocketConfig, ) -> Result<(Self, UnboundedReceiver<CoinApiWsMessage>), Error>
Creates a client and the receiver for its messages without connecting.
§Errors
Returns an error if the credentials, endpoint, or proxy URL are invalid.
Sourcepub async fn subscribe(&self, subscription: Subscription) -> Result<(), Error>
pub async fn subscribe(&self, subscription: Subscription) -> Result<(), Error>
Adds a subscription, connecting on first use.
Returns once the new scope is queued for sending; the first data frame confirms it.
§Errors
Returns an error if validation, connecting, or sending fails. A book type other than the one already subscribed is a validation error. A failed send leaves the pair unsubscribed.
Sourcepub async fn unsubscribe(&self, subscription: Subscription) -> Result<(), Error>
pub async fn unsubscribe(&self, subscription: Subscription) -> Result<(), Error>
Removes a subscription.
CoinAPI does not acknowledge the replacement scope, so frames still in flight for the pair are dropped locally.
§Errors
Returns an error if validation or sending fails. A failed send keeps the pair subscribed.
Sourcepub async fn apply(
&self,
changes: &[ScopeChange],
) -> Result<Vec<(ScopeChange, Error)>, Error>
pub async fn apply( &self, changes: &[ScopeChange], ) -> Result<Vec<(ScopeChange, Error)>, Error>
Applies scope changes in order and sends one hello for the resulting scope.
Connects when a subscribe finds no connection, and closes the connection when the scope
becomes empty, since an empty hello is a terminal protocol error. The hello waits until
two seconds after the client’s previous one. Returns once the scope is queued for
sending, with each change rejected by validation, including a book type other than the
one already subscribed.
§Errors
Returns an error if connecting or sending fails; every change in the batch is reverted.
Sourcepub async fn resubscribe(
&self,
subscription: Subscription,
paused: impl FnOnce(),
) -> Result<(), Error>
pub async fn resubscribe( &self, subscription: Subscription, paused: impl FnOnce(), ) -> Result<(), Error>
Restarts a subscribed book pair’s stream so CoinAPI sends it a fresh snapshot.
CoinAPI replays nothing for a repeated scope, but restarts a pair’s sequence with a snapshot when the pair leaves the scope and returns. The client sends the scope without the pair’s symbol, then the full scope two seconds later, so other symbols keep streaming. When no other symbol is subscribed, the removal scope keeps the symbol’s other channels instead, or lists only its trades when the book is the whole scope; the client drops those unsubscribed trades. The connection stays open, since a one-connection tier rejects a second one.
Restarts on a connection start at least five seconds apart, because CoinAPI closes a
connection that exceeds its per-IP hello rate. Subscription changes wait while a restart
is pending. Calls paused as soon as a scope without the pair’s symbol is queued, since
that pauses the symbol’s other channels; the call happens even if the restart is then
cancelled. Returns once both scopes are queued for sending.
§Errors
Returns an error if the pair is not a subscribed book pair or sending fails.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for CoinApiWebSocketClient
impl !RefUnwindSafe for CoinApiWebSocketClient
impl !UnwindSafe for CoinApiWebSocketClient
impl Send for CoinApiWebSocketClient
impl Sync for CoinApiWebSocketClient
impl Unpin for CoinApiWebSocketClient
impl UnsafeUnpin for CoinApiWebSocketClient
Blanket Implementations§
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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