pub struct BitmexWebSocketClient { /* private fields */ }
Expand description
Provides a WebSocket client for connecting to the BitMEX real-time API.
Implementations§
Source§impl BitmexWebSocketClient
impl BitmexWebSocketClient
Sourcepub fn new(
url: Option<String>,
api_key: Option<String>,
api_secret: Option<String>,
account_id: Option<AccountId>,
heartbeat: Option<u64>,
) -> Result<Self>
pub fn new( url: Option<String>, api_key: Option<String>, api_secret: Option<String>, account_id: Option<AccountId>, heartbeat: Option<u64>, ) -> Result<Self>
Creates a new BitmexWebSocketClient
instance.
§Errors
Returns an error if only one of api_key
or api_secret
is provided (both or neither required).
Sourcepub fn from_env() -> Result<Self>
pub fn from_env() -> Result<Self>
Creates a new authenticated BitmexWebSocketClient
using environment variables.
§Errors
Returns an error if environment variables are not set or credentials are invalid.
Sourcepub fn initialize_instruments_cache(&mut self, instruments: Vec<InstrumentAny>)
pub fn initialize_instruments_cache(&mut self, instruments: Vec<InstrumentAny>)
Initialize the instruments cache with the given instruments
.
Sourcepub async fn connect(&mut self) -> Result<(), BitmexWsError>
pub async fn connect(&mut self) -> Result<(), BitmexWsError>
Sourcepub async fn wait_until_active(
&self,
timeout_secs: f64,
) -> Result<(), BitmexWsError>
pub async fn wait_until_active( &self, timeout_secs: f64, ) -> Result<(), BitmexWsError>
Wait until the WebSocket connection is active.
§Errors
Returns an error if the connection times out.
Sourcepub fn stream(&mut self) -> impl Stream<Item = NautilusWsMessage> + use<>
pub fn stream(&mut self) -> impl Stream<Item = NautilusWsMessage> + use<>
Provides the internal stream as a channel-based stream.
§Panics
This function panics:
- If the websocket is not connected.
- If
stream
has already been called somewhere else (stream receiver is then taken).
Sourcepub async fn close(&mut self) -> Result<(), BitmexWsError>
pub async fn close(&mut self) -> Result<(), BitmexWsError>
Sourcepub fn subscription_count(&self) -> usize
pub fn subscription_count(&self) -> usize
Get the current number of active subscriptions.
Sourcepub fn get_subscriptions(&self, instrument_id: InstrumentId) -> Vec<String>
pub fn get_subscriptions(&self, instrument_id: InstrumentId) -> Vec<String>
Get active subscriptions for a specific instrument.
Sourcepub async fn subscribe_instruments(&self) -> Result<(), BitmexWsError>
pub async fn subscribe_instruments(&self) -> Result<(), BitmexWsError>
Subscribe to instrument updates for all instruments on the venue.
§Errors
Returns an error if the WebSocket is not connected or if the subscription fails.
Sourcepub async fn subscribe_instrument(
&self,
instrument_id: InstrumentId,
) -> Result<(), BitmexWsError>
pub async fn subscribe_instrument( &self, instrument_id: InstrumentId, ) -> Result<(), BitmexWsError>
Subscribe to instrument updates (mark/index prices) for the specified instrument.
§Errors
Returns an error if the WebSocket is not connected or if the subscription fails.
Sourcepub async fn subscribe_book(
&self,
instrument_id: InstrumentId,
) -> Result<(), BitmexWsError>
pub async fn subscribe_book( &self, instrument_id: InstrumentId, ) -> Result<(), BitmexWsError>
Subscribe to order book updates for the specified instrument.
§Errors
Returns an error if the WebSocket is not connected or if the subscription fails.
Sourcepub async fn subscribe_book_25(
&self,
instrument_id: InstrumentId,
) -> Result<(), BitmexWsError>
pub async fn subscribe_book_25( &self, instrument_id: InstrumentId, ) -> Result<(), BitmexWsError>
Subscribe to order book L2 (25 levels) updates for the specified instrument.
§Errors
Returns an error if the WebSocket is not connected or if the subscription fails.
Sourcepub async fn subscribe_book_depth10(
&self,
instrument_id: InstrumentId,
) -> Result<(), BitmexWsError>
pub async fn subscribe_book_depth10( &self, instrument_id: InstrumentId, ) -> Result<(), BitmexWsError>
Subscribe to order book depth 10 updates for the specified instrument.
§Errors
Returns an error if the WebSocket is not connected or if the subscription fails.
Sourcepub async fn subscribe_quotes(
&self,
instrument_id: InstrumentId,
) -> Result<(), BitmexWsError>
pub async fn subscribe_quotes( &self, instrument_id: InstrumentId, ) -> Result<(), BitmexWsError>
Subscribe to quote updates for the specified instrument.
Note: Index symbols (starting with ‘.’) do not have quotes and will be silently ignored.
§Errors
Returns an error if the WebSocket is not connected or if the subscription fails.
Sourcepub async fn subscribe_trades(
&self,
instrument_id: InstrumentId,
) -> Result<(), BitmexWsError>
pub async fn subscribe_trades( &self, instrument_id: InstrumentId, ) -> Result<(), BitmexWsError>
Subscribe to trade updates for the specified instrument.
Note: Index symbols (starting with ‘.’) do not have trades and will be silently ignored.
§Errors
Returns an error if the WebSocket is not connected or if the subscription fails.
Sourcepub async fn subscribe_mark_prices(
&self,
instrument_id: InstrumentId,
) -> Result<(), BitmexWsError>
pub async fn subscribe_mark_prices( &self, instrument_id: InstrumentId, ) -> Result<(), BitmexWsError>
Subscribe to mark price updates for the specified instrument.
§Errors
Returns an error if the WebSocket is not connected or if the subscription fails.
Sourcepub async fn subscribe_index_prices(
&self,
instrument_id: InstrumentId,
) -> Result<(), BitmexWsError>
pub async fn subscribe_index_prices( &self, instrument_id: InstrumentId, ) -> Result<(), BitmexWsError>
Subscribe to index price updates for the specified instrument.
§Errors
Returns an error if the WebSocket is not connected or if the subscription fails.
Sourcepub async fn subscribe_funding_rates(
&self,
instrument_id: InstrumentId,
) -> Result<(), BitmexWsError>
pub async fn subscribe_funding_rates( &self, instrument_id: InstrumentId, ) -> Result<(), BitmexWsError>
Subscribe to funding rate updates for the specified instrument.
§Errors
Returns an error if the WebSocket is not connected or if the subscription fails.
Sourcepub async fn subscribe_bars(
&self,
bar_type: BarType,
) -> Result<(), BitmexWsError>
pub async fn subscribe_bars( &self, bar_type: BarType, ) -> Result<(), BitmexWsError>
Subscribe to bar updates for the specified bar type.
§Errors
Returns an error if the WebSocket is not connected or if the subscription fails.
Sourcepub async fn unsubscribe_instruments(&self) -> Result<(), BitmexWsError>
pub async fn unsubscribe_instruments(&self) -> Result<(), BitmexWsError>
Unsubscribe from instrument updates for all instruments on the venue.
§Errors
Returns an error if the WebSocket is not connected or if the unsubscription fails.
Sourcepub async fn unsubscribe_instrument(
&self,
instrument_id: InstrumentId,
) -> Result<(), BitmexWsError>
pub async fn unsubscribe_instrument( &self, instrument_id: InstrumentId, ) -> Result<(), BitmexWsError>
Unsubscribe from instrument updates (mark/index prices) for the specified instrument.
§Errors
Returns an error if the WebSocket is not connected or if the unsubscription fails.
Sourcepub async fn unsubscribe_book(
&self,
instrument_id: InstrumentId,
) -> Result<(), BitmexWsError>
pub async fn unsubscribe_book( &self, instrument_id: InstrumentId, ) -> Result<(), BitmexWsError>
Unsubscribe from order book updates for the specified instrument.
§Errors
Returns an error if the WebSocket is not connected or if the unsubscription fails.
Sourcepub async fn unsubscribe_book_25(
&self,
instrument_id: InstrumentId,
) -> Result<(), BitmexWsError>
pub async fn unsubscribe_book_25( &self, instrument_id: InstrumentId, ) -> Result<(), BitmexWsError>
Unsubscribe from order book L2 (25 levels) updates for the specified instrument.
§Errors
Returns an error if the WebSocket is not connected or if the unsubscription fails.
Sourcepub async fn unsubscribe_book_depth10(
&self,
instrument_id: InstrumentId,
) -> Result<(), BitmexWsError>
pub async fn unsubscribe_book_depth10( &self, instrument_id: InstrumentId, ) -> Result<(), BitmexWsError>
Unsubscribe from order book depth 10 updates for the specified instrument.
§Errors
Returns an error if the WebSocket is not connected or if the unsubscription fails.
Sourcepub async fn unsubscribe_quotes(
&self,
instrument_id: InstrumentId,
) -> Result<(), BitmexWsError>
pub async fn unsubscribe_quotes( &self, instrument_id: InstrumentId, ) -> Result<(), BitmexWsError>
Unsubscribe from quote updates for the specified instrument.
§Errors
Returns an error if the WebSocket is not connected or if the unsubscription fails.
Sourcepub async fn unsubscribe_trades(
&self,
instrument_id: InstrumentId,
) -> Result<(), BitmexWsError>
pub async fn unsubscribe_trades( &self, instrument_id: InstrumentId, ) -> Result<(), BitmexWsError>
Unsubscribe from trade updates for the specified instrument.
§Errors
Returns an error if the WebSocket is not connected or if the unsubscription fails.
Sourcepub async fn unsubscribe_mark_prices(
&self,
instrument_id: InstrumentId,
) -> Result<(), BitmexWsError>
pub async fn unsubscribe_mark_prices( &self, instrument_id: InstrumentId, ) -> Result<(), BitmexWsError>
Unsubscribe from mark price updates for the specified instrument.
§Errors
Returns an error if the WebSocket is not connected or if the unsubscription fails.
Sourcepub async fn unsubscribe_index_prices(
&self,
instrument_id: InstrumentId,
) -> Result<(), BitmexWsError>
pub async fn unsubscribe_index_prices( &self, instrument_id: InstrumentId, ) -> Result<(), BitmexWsError>
Unsubscribe from index price updates for the specified instrument.
§Errors
Returns an error if the WebSocket is not connected or if the unsubscription fails.
Sourcepub async fn unsubscribe_funding_rates(
&self,
instrument_id: InstrumentId,
) -> Result<(), BitmexWsError>
pub async fn unsubscribe_funding_rates( &self, instrument_id: InstrumentId, ) -> Result<(), BitmexWsError>
Unsubscribe from funding rate updates for the specified instrument.
§Errors
Returns an error if the WebSocket is not connected or if the unsubscription fails.
Sourcepub async fn unsubscribe_bars(
&self,
bar_type: BarType,
) -> Result<(), BitmexWsError>
pub async fn unsubscribe_bars( &self, bar_type: BarType, ) -> Result<(), BitmexWsError>
Unsubscribe from bar updates for the specified bar type.
§Errors
Returns an error if the WebSocket is not connected or if the unsubscription fails.
Sourcepub async fn subscribe_orders(&self) -> Result<(), BitmexWsError>
pub async fn subscribe_orders(&self) -> Result<(), BitmexWsError>
Subscribe to order updates for the authenticated account.
§Errors
Returns an error if the WebSocket is not connected, not authenticated, or if the subscription fails.
Sourcepub async fn subscribe_executions(&self) -> Result<(), BitmexWsError>
pub async fn subscribe_executions(&self) -> Result<(), BitmexWsError>
Subscribe to execution updates for the authenticated account.
§Errors
Returns an error if the WebSocket is not connected, not authenticated, or if the subscription fails.
Sourcepub async fn subscribe_positions(&self) -> Result<(), BitmexWsError>
pub async fn subscribe_positions(&self) -> Result<(), BitmexWsError>
Subscribe to position updates for the authenticated account.
§Errors
Returns an error if the WebSocket is not connected, not authenticated, or if the subscription fails.
Sourcepub async fn subscribe_margin(&self) -> Result<(), BitmexWsError>
pub async fn subscribe_margin(&self) -> Result<(), BitmexWsError>
Subscribe to margin updates for the authenticated account.
§Errors
Returns an error if the WebSocket is not connected, not authenticated, or if the subscription fails.
Sourcepub async fn subscribe_wallet(&self) -> Result<(), BitmexWsError>
pub async fn subscribe_wallet(&self) -> Result<(), BitmexWsError>
Subscribe to wallet updates for the authenticated account.
§Errors
Returns an error if the WebSocket is not connected, not authenticated, or if the subscription fails.
Sourcepub async fn unsubscribe_orders(&self) -> Result<(), BitmexWsError>
pub async fn unsubscribe_orders(&self) -> Result<(), BitmexWsError>
Unsubscribe from order updates for the authenticated account.
§Errors
Returns an error if the WebSocket is not connected or if the unsubscription fails.
Sourcepub async fn unsubscribe_executions(&self) -> Result<(), BitmexWsError>
pub async fn unsubscribe_executions(&self) -> Result<(), BitmexWsError>
Unsubscribe from execution updates for the authenticated account.
§Errors
Returns an error if the WebSocket is not connected or if the unsubscription fails.
Sourcepub async fn unsubscribe_positions(&self) -> Result<(), BitmexWsError>
pub async fn unsubscribe_positions(&self) -> Result<(), BitmexWsError>
Unsubscribe from position updates for the authenticated account.
§Errors
Returns an error if the WebSocket is not connected or if the unsubscription fails.
Sourcepub async fn unsubscribe_margin(&self) -> Result<(), BitmexWsError>
pub async fn unsubscribe_margin(&self) -> Result<(), BitmexWsError>
Unsubscribe from margin updates for the authenticated account.
§Errors
Returns an error if the WebSocket is not connected or if the unsubscription fails.
Sourcepub async fn unsubscribe_wallet(&self) -> Result<(), BitmexWsError>
pub async fn unsubscribe_wallet(&self) -> Result<(), BitmexWsError>
Unsubscribe from wallet updates for the authenticated account.
§Errors
Returns an error if the WebSocket is not connected or if the unsubscription fails.
Trait Implementations§
Source§impl Clone for BitmexWebSocketClient
impl Clone for BitmexWebSocketClient
Source§fn clone(&self) -> BitmexWebSocketClient
fn clone(&self) -> BitmexWebSocketClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for BitmexWebSocketClient
impl Debug for BitmexWebSocketClient
Source§impl<'py> IntoPyObject<'py> for BitmexWebSocketClient
impl<'py> IntoPyObject<'py> for BitmexWebSocketClient
Source§type Target = BitmexWebSocketClient
type Target = BitmexWebSocketClient
Source§type Output = Bound<'py, <BitmexWebSocketClient as IntoPyObject<'py>>::Target>
type Output = Bound<'py, <BitmexWebSocketClient 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 BitmexWebSocketClient
impl PyClass for BitmexWebSocketClient
Source§impl PyClassImpl for BitmexWebSocketClient
impl PyClassImpl for BitmexWebSocketClient
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§type ThreadChecker = SendablePyClass<BitmexWebSocketClient>
type ThreadChecker = SendablePyClass<BitmexWebSocketClient>
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<BitmexWebSocketClient> for PyClassImplCollector<BitmexWebSocketClient>
impl PyClassNewTextSignature<BitmexWebSocketClient> for PyClassImplCollector<BitmexWebSocketClient>
fn new_text_signature(self) -> Option<&'static str>
Source§impl<'a, 'py> PyFunctionArgument<'a, 'py, false> for &'a BitmexWebSocketClient
impl<'a, 'py> PyFunctionArgument<'a, 'py, false> for &'a BitmexWebSocketClient
Source§impl<'a, 'py> PyFunctionArgument<'a, 'py, false> for &'a mut BitmexWebSocketClient
impl<'a, 'py> PyFunctionArgument<'a, 'py, false> for &'a mut BitmexWebSocketClient
Source§impl PyMethods<BitmexWebSocketClient> for PyClassImplCollector<BitmexWebSocketClient>
impl PyMethods<BitmexWebSocketClient> for PyClassImplCollector<BitmexWebSocketClient>
fn py_methods(self) -> &'static PyClassItems
Source§impl PyTypeInfo for BitmexWebSocketClient
impl PyTypeInfo for BitmexWebSocketClient
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 BitmexWebSocketClient
Auto Trait Implementations§
impl Freeze for BitmexWebSocketClient
impl !RefUnwindSafe for BitmexWebSocketClient
impl Send for BitmexWebSocketClient
impl Sync for BitmexWebSocketClient
impl Unpin for BitmexWebSocketClient
impl !UnwindSafe for BitmexWebSocketClient
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FromPyObject<'_> for Twhere
T: PyClass + Clone,
impl<T> FromPyObject<'_> for Twhere
T: PyClass + Clone,
§fn extract_bound(obj: &Bound<'_, PyAny>) -> Result<T, PyErr>
fn extract_bound(obj: &Bound<'_, PyAny>) -> Result<T, PyErr>
§impl<'py, T> FromPyObjectBound<'_, 'py> for Twhere
T: FromPyObject<'py>,
impl<'py, T> FromPyObjectBound<'_, 'py> for Twhere
T: FromPyObject<'py>,
§fn from_py_object_bound(ob: Borrowed<'_, 'py, PyAny>) -> Result<T, PyErr>
fn from_py_object_bound(ob: Borrowed<'_, 'py, PyAny>) -> Result<T, PyErr>
§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 more