pub struct KrakenSpotWebSocketClient { /* private fields */ }Expand description
WebSocket client for the Kraken Spot v2 streaming API.
Implementations§
Source§impl KrakenSpotWebSocketClient
impl KrakenSpotWebSocketClient
Sourcepub fn new(
config: KrakenDataClientConfig,
cancellation_token: CancellationToken,
) -> Self
pub fn new( config: KrakenDataClientConfig, cancellation_token: CancellationToken, ) -> Self
Creates a new client with the given configuration.
Sourcepub async fn connect(&mut self) -> Result<(), KrakenWsError>
pub async fn connect(&mut self) -> Result<(), KrakenWsError>
Connects to the WebSocket server.
Sourcepub async fn disconnect(&mut self) -> Result<(), KrakenWsError>
pub async fn disconnect(&mut self) -> Result<(), KrakenWsError>
Disconnects from the WebSocket server.
Sourcepub async fn close(&mut self) -> Result<(), KrakenWsError>
pub async fn close(&mut self) -> Result<(), KrakenWsError>
Closes the WebSocket connection.
Sourcepub async fn wait_until_active(
&self,
timeout_secs: f64,
) -> Result<(), KrakenWsError>
pub async fn wait_until_active( &self, timeout_secs: f64, ) -> Result<(), KrakenWsError>
Waits until the connection is active or timeout.
Sourcepub async fn authenticate(&self) -> Result<(), KrakenWsError>
pub async fn authenticate(&self) -> Result<(), KrakenWsError>
Authenticates with the Kraken API to enable private subscriptions.
Sourcepub fn cache_instruments(&self, instruments: Vec<InstrumentAny>)
pub fn cache_instruments(&self, instruments: Vec<InstrumentAny>)
Caches multiple instruments for symbol lookup.
Sourcepub fn cache_instrument(&self, instrument: InstrumentAny)
pub fn cache_instrument(&self, instrument: InstrumentAny)
Caches a single instrument for symbol lookup.
Sourcepub fn set_account_id(&self, account_id: AccountId)
pub fn set_account_id(&self, account_id: AccountId)
Sets the account ID for execution reports.
Must be called before subscribing to executions to properly generate OrderStatusReport and FillReport objects.
Sourcepub fn cache_client_order(
&self,
client_order_id: ClientOrderId,
instrument_id: InstrumentId,
trader_id: TraderId,
strategy_id: StrategyId,
)
pub fn cache_client_order( &self, client_order_id: ClientOrderId, instrument_id: InstrumentId, trader_id: TraderId, strategy_id: StrategyId, )
Caches order info for order tracking.
This should be called BEFORE submitting an order via HTTP to handle the race condition where WebSocket execution messages arrive before the HTTP response (which contains the venue_order_id).
Sourcepub fn cancel_all_requests(&self)
pub fn cancel_all_requests(&self)
Cancels all pending requests.
Sourcepub fn cancellation_token(&self) -> &CancellationToken
pub fn cancellation_token(&self) -> &CancellationToken
Returns the cancellation token for this client.
Sourcepub async fn subscribe(
&self,
channel: KrakenWsChannel,
symbols: Vec<Ustr>,
depth: Option<u32>,
) -> Result<(), KrakenWsError>
pub async fn subscribe( &self, channel: KrakenWsChannel, symbols: Vec<Ustr>, depth: Option<u32>, ) -> Result<(), KrakenWsError>
Subscribes to a channel for the given symbols.
Sourcepub async fn unsubscribe(
&self,
channel: KrakenWsChannel,
symbols: Vec<Ustr>,
) -> Result<(), KrakenWsError>
pub async fn unsubscribe( &self, channel: KrakenWsChannel, symbols: Vec<Ustr>, ) -> Result<(), KrakenWsError>
Unsubscribes from a channel for the given symbols.
Sourcepub async fn send_ping(&self) -> Result<(), KrakenWsError>
pub async fn send_ping(&self) -> Result<(), KrakenWsError>
Sends a ping message to keep the connection alive.
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Returns true if connected (not closed).
Sourcepub fn get_subscriptions(&self) -> Vec<String>
pub fn get_subscriptions(&self) -> Vec<String>
Returns all active subscriptions.
Sourcepub fn stream(&mut self) -> impl Stream<Item = NautilusWsMessage> + use<>
pub fn stream(&mut self) -> impl Stream<Item = NautilusWsMessage> + use<>
Returns a stream of WebSocket messages.
Sourcepub async fn subscribe_book(
&self,
instrument_id: InstrumentId,
depth: Option<u32>,
) -> Result<(), KrakenWsError>
pub async fn subscribe_book( &self, instrument_id: InstrumentId, depth: Option<u32>, ) -> Result<(), KrakenWsError>
Subscribes to order book updates for the given instrument.
Sourcepub async fn subscribe_quotes(
&self,
instrument_id: InstrumentId,
) -> Result<(), KrakenWsError>
pub async fn subscribe_quotes( &self, instrument_id: InstrumentId, ) -> Result<(), KrakenWsError>
Subscribes to quote updates for the given instrument.
Uses the order book channel with depth 10 for low-latency top-of-book quotes instead of the throttled ticker feed.
Sourcepub async fn subscribe_trades(
&self,
instrument_id: InstrumentId,
) -> Result<(), KrakenWsError>
pub async fn subscribe_trades( &self, instrument_id: InstrumentId, ) -> Result<(), KrakenWsError>
Subscribes to trade updates for the given instrument.
Sourcepub async fn subscribe_bars(
&self,
bar_type: BarType,
) -> Result<(), KrakenWsError>
pub async fn subscribe_bars( &self, bar_type: BarType, ) -> Result<(), KrakenWsError>
Subscribes to bar/OHLC updates for the given bar type.
§Errors
Returns an error if the bar aggregation is not supported by Kraken.
Sourcepub async fn subscribe_executions(
&self,
snap_orders: bool,
snap_trades: bool,
) -> Result<(), KrakenWsError>
pub async fn subscribe_executions( &self, snap_orders: bool, snap_trades: bool, ) -> Result<(), KrakenWsError>
Subscribes to execution updates (order and fill events).
Requires authentication - call authenticate() first.
Sourcepub async fn unsubscribe_book(
&self,
instrument_id: InstrumentId,
) -> Result<(), KrakenWsError>
pub async fn unsubscribe_book( &self, instrument_id: InstrumentId, ) -> Result<(), KrakenWsError>
Unsubscribes from order book updates for the given instrument.
Note: Will only actually unsubscribe if quotes are not also subscribed.
Sourcepub async fn unsubscribe_quotes(
&self,
instrument_id: InstrumentId,
) -> Result<(), KrakenWsError>
pub async fn unsubscribe_quotes( &self, instrument_id: InstrumentId, ) -> Result<(), KrakenWsError>
Unsubscribes from quote updates for the given instrument.
Sourcepub async fn unsubscribe_trades(
&self,
instrument_id: InstrumentId,
) -> Result<(), KrakenWsError>
pub async fn unsubscribe_trades( &self, instrument_id: InstrumentId, ) -> Result<(), KrakenWsError>
Unsubscribes from trade updates for the given instrument.
Sourcepub async fn unsubscribe_bars(
&self,
bar_type: BarType,
) -> Result<(), KrakenWsError>
pub async fn unsubscribe_bars( &self, bar_type: BarType, ) -> Result<(), KrakenWsError>
Unsubscribes from bar/OHLC updates for the given bar type.
§Errors
Returns an error if the bar aggregation is not supported by Kraken.
Trait Implementations§
Source§impl Clone for KrakenSpotWebSocketClient
impl Clone for KrakenSpotWebSocketClient
Source§impl Debug for KrakenSpotWebSocketClient
impl Debug for KrakenSpotWebSocketClient
Source§impl<'py> IntoPyObject<'py> for KrakenSpotWebSocketClient
impl<'py> IntoPyObject<'py> for KrakenSpotWebSocketClient
Source§type Target = KrakenSpotWebSocketClient
type Target = KrakenSpotWebSocketClient
Source§type Output = Bound<'py, <KrakenSpotWebSocketClient as IntoPyObject<'py>>::Target>
type Output = Bound<'py, <KrakenSpotWebSocketClient as IntoPyObject<'py>>::Target>
Source§fn into_pyobject(
self,
py: Python<'py>,
) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
fn into_pyobject( self, py: Python<'py>, ) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
Source§impl PyClass for KrakenSpotWebSocketClient
impl PyClass for KrakenSpotWebSocketClient
Source§impl PyClassImpl for KrakenSpotWebSocketClient
impl PyClassImpl for KrakenSpotWebSocketClient
Source§const IS_BASETYPE: bool = false
const IS_BASETYPE: bool = false
Source§const IS_SUBCLASS: bool = false
const IS_SUBCLASS: bool = false
Source§const IS_MAPPING: bool = false
const IS_MAPPING: bool = false
Source§const IS_SEQUENCE: bool = false
const IS_SEQUENCE: bool = false
Source§const IS_IMMUTABLE_TYPE: bool = false
const IS_IMMUTABLE_TYPE: bool = false
Source§const RAW_DOC: &'static CStr = /// WebSocket client for the Kraken Spot v2 streaming API.
const RAW_DOC: &'static CStr = /// WebSocket client for the Kraken Spot v2 streaming API.
Source§const DOC: &'static CStr
const DOC: &'static CStr
text_signature if a constructor is defined. Read moreSource§type ThreadChecker = SendablePyClass<KrakenSpotWebSocketClient>
type ThreadChecker = SendablePyClass<KrakenSpotWebSocketClient>
Source§type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
Source§type BaseNativeType = PyAny
type BaseNativeType = PyAny
PyAny by default, and when you declare
#[pyclass(extends=PyDict)], it’s PyDict.fn items_iter() -> PyClassItemsIter
fn lazy_type_object() -> &'static LazyTypeObject<Self>
fn dict_offset() -> Option<isize>
fn weaklist_offset() -> Option<isize>
Source§impl PyClassNewTextSignature for KrakenSpotWebSocketClient
impl PyClassNewTextSignature for KrakenSpotWebSocketClient
const TEXT_SIGNATURE: &'static str = "(environment=None, private=False, base_url=None, heartbeat_secs=None, api_key=None, api_secret=None)"
Source§impl PyMethods<KrakenSpotWebSocketClient> for PyClassImplCollector<KrakenSpotWebSocketClient>
impl PyMethods<KrakenSpotWebSocketClient> for PyClassImplCollector<KrakenSpotWebSocketClient>
fn py_methods(self) -> &'static PyClassItems
Source§impl PyTypeInfo for KrakenSpotWebSocketClient
impl PyTypeInfo for KrakenSpotWebSocketClient
Source§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
§fn type_object(py: Python<'_>) -> Bound<'_, PyType>
fn type_object(py: Python<'_>) -> Bound<'_, PyType>
§fn is_type_of(object: &Bound<'_, PyAny>) -> bool
fn is_type_of(object: &Bound<'_, PyAny>) -> bool
object is an instance of this type or a subclass of this type.§fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool
fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool
object is an instance of this type.impl DerefToPyAny for KrakenSpotWebSocketClient
impl ExtractPyClassWithClone for KrakenSpotWebSocketClient
Auto Trait Implementations§
impl Freeze for KrakenSpotWebSocketClient
impl !RefUnwindSafe for KrakenSpotWebSocketClient
impl Send for KrakenSpotWebSocketClient
impl Sync for KrakenSpotWebSocketClient
impl Unpin for KrakenSpotWebSocketClient
impl !UnwindSafe for KrakenSpotWebSocketClient
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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§impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
§fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
self into an owned Python object, dropping type information.§fn into_py_any(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>
fn into_py_any(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>
self into an owned Python object, dropping type information and unbinding it
from the 'py lifetime.§fn into_pyobject_or_pyerr(self, py: Python<'py>) -> Result<Self::Output, PyErr>
fn into_pyobject_or_pyerr(self, py: Python<'py>) -> Result<Self::Output, PyErr>
self into a Python object. Read moreSource§impl<'py, T> IntoPyObjectNautilusExt<'py> for Twhere
T: IntoPyObjectExt<'py>,
impl<'py, T> IntoPyObjectNautilusExt<'py> for Twhere
T: IntoPyObjectExt<'py>,
Source§fn into_py_any_unwrap(self, py: Python<'py>) -> Py<PyAny>
fn into_py_any_unwrap(self, py: Python<'py>) -> Py<PyAny>
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> PyErrArguments for T
impl<T> PyErrArguments for T
§impl<T> PyTypeCheck for Twhere
T: PyTypeInfo,
impl<T> PyTypeCheck for Twhere
T: PyTypeInfo,
§const NAME: &'static str = T::NAME
const NAME: &'static str = T::NAME
§fn type_check(object: &Bound<'_, PyAny>) -> bool
fn type_check(object: &Bound<'_, PyAny>) -> bool
§fn classinfo_object(py: Python<'_>) -> Bound<'_, PyAny>
fn classinfo_object(py: Python<'_>) -> Bound<'_, PyAny>
isinstance and issubclass function. Read more