pub struct CoinbaseWebSocketClient { /* private fields */ }Expand description
WebSocket client for Coinbase Advanced Trade market data and user streams.
Manages connection lifecycle, subscription state, and JWT authentication.
Spawns a FeedHandler task that parses raw messages into Nautilus types.
Implementations§
Source§impl CoinbaseWebSocketClient
impl CoinbaseWebSocketClient
Sourcepub fn new(
url: &str,
transport_backend: TransportBackend,
proxy_url: Option<String>,
) -> Self
pub fn new( url: &str, transport_backend: TransportBackend, proxy_url: Option<String>, ) -> Self
Creates a new CoinbaseWebSocketClient for public market data.
Sourcepub fn with_socket_control(self, control: SocketControl) -> Self
pub fn with_socket_control(self, control: SocketControl) -> Self
Configures socket state reporting and reconnect control.
Sourcepub fn with_credential(
url: &str,
credential: CoinbaseCredential,
transport_backend: TransportBackend,
proxy_url: Option<String>,
) -> Self
pub fn with_credential( url: &str, credential: CoinbaseCredential, transport_backend: TransportBackend, proxy_url: Option<String>, ) -> Self
Creates a new CoinbaseWebSocketClient with credentials for authenticated channels.
Sourcepub async fn set_account_id(&mut self, account_id: AccountId)
pub async fn set_account_id(&mut self, account_id: AccountId)
Sets the account ID used when emitting user-channel execution reports.
Propagates to the feed handler when the connection is active so that subsequent user events carry the correct account identifier.
Sourcepub async fn initialize_instruments(&self, instruments: Vec<InstrumentAny>)
pub async fn initialize_instruments(&self, instruments: Vec<InstrumentAny>)
Bulk-populates the instrument cache.
Safe to call before or after Self::connect. When called before
connect, instruments are picked up by the initial InitializeInstruments
command the client sends to the handler; when called after, a fresh
InitializeInstruments command is sent to refresh the handler’s cache.
Sourcepub async fn connect(&mut self) -> Result<()>
pub async fn connect(&mut self) -> Result<()>
Establishes the WebSocket connection and spawns the feed handler.
Sourcepub async fn subscribe(
&self,
channel: CoinbaseWsChannel,
product_ids: &[Ustr],
) -> Result<()>
pub async fn subscribe( &self, channel: CoinbaseWsChannel, product_ids: &[Ustr], ) -> Result<()>
Subscribes to a channel for the given product IDs.
Sourcepub async fn unsubscribe(
&self,
channel: CoinbaseWsChannel,
product_ids: &[Ustr],
) -> Result<()>
pub async fn unsubscribe( &self, channel: CoinbaseWsChannel, product_ids: &[Ustr], ) -> Result<()>
Unsubscribes from a channel for the given product IDs.
Sourcepub async fn next_message(&mut self) -> Option<NautilusWsMessage>
pub async fn next_message(&mut self) -> Option<NautilusWsMessage>
Returns the next parsed message from the feed handler.
Sourcepub async fn disconnect(&mut self) -> Result<()>
pub async fn disconnect(&mut self) -> Result<()>
Disconnects the WebSocket and stops the feed handler.
Sourcepub fn is_reconnecting(&self) -> bool
pub fn is_reconnecting(&self) -> bool
Returns true if the WebSocket is reconnecting after a transport drop.
Sourcepub fn instruments(&self) -> &Arc<AtomicMap<InstrumentId, InstrumentAny>> ⓘ
pub fn instruments(&self) -> &Arc<AtomicMap<InstrumentId, InstrumentAny>> ⓘ
Returns a reference to the instrument cache.
Sourcepub fn subscription_aliases(&self) -> &Arc<AtomicMap<Ustr, Ustr>> ⓘ
pub fn subscription_aliases(&self) -> &Arc<AtomicMap<Ustr, Ustr>> ⓘ
Returns a reference to the canonical-to-subscribed alias map.
Sourcepub fn register_subscription_alias(&self, canonical: Ustr, subscribed: Ustr)
pub fn register_subscription_alias(&self, canonical: Ustr, subscribed: Ustr)
Records that inbound messages carrying canonical should be re-keyed to
subscribed. Caller is the data/exec client at subscribe or submit time
when the local product id differs from Coinbase’s canonical alias.
Sourcepub fn unregister_subscription_alias(&self, canonical: &Ustr)
pub fn unregister_subscription_alias(&self, canonical: &Ustr)
Removes an alias registration. Safe to call if no entry exists.
Sourcepub fn subscriptions(&self) -> &SubscriptionState
pub fn subscriptions(&self) -> &SubscriptionState
Returns the subscription state.
Sourcepub async fn update_instrument(&self, instrument: InstrumentAny)
pub async fn update_instrument(&self, instrument: InstrumentAny)
Updates an instrument in the cache and notifies the handler.
Sourcepub fn take_out_rx(&mut self) -> Option<UnboundedReceiver<NautilusWsMessage>>
pub fn take_out_rx(&mut self) -> Option<UnboundedReceiver<NautilusWsMessage>>
Takes the output message receiver, leaving None in its place.
Used by the data client to move the receiver into a background consumption task.
Sourcepub fn register_bar_type(&mut self, key: String, bar_type: BarType)
pub fn register_bar_type(&mut self, key: String, bar_type: BarType)
Registers a bar type locally without notifying the handler.
Used by the data client to persist registrations on the original client before cloning for async command dispatch.
Sourcepub async fn add_bar_type(&mut self, key: String, bar_type: BarType)
pub async fn add_bar_type(&mut self, key: String, bar_type: BarType)
Registers a bar type for candle parsing.
Trait Implementations§
Source§impl Clone for CoinbaseWebSocketClient
impl Clone for CoinbaseWebSocketClient
Source§impl Debug for CoinbaseWebSocketClient
impl Debug for CoinbaseWebSocketClient
Source§impl Drop for CoinbaseWebSocketClient
impl Drop for CoinbaseWebSocketClient
Auto Trait Implementations§
impl !Freeze for CoinbaseWebSocketClient
impl !RefUnwindSafe for CoinbaseWebSocketClient
impl !UnwindSafe for CoinbaseWebSocketClient
impl Send for CoinbaseWebSocketClient
impl Sync for CoinbaseWebSocketClient
impl Unpin for CoinbaseWebSocketClient
impl UnsafeUnpin for CoinbaseWebSocketClient
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§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