pub struct HyperliquidWebSocketClient { /* private fields */ }
Expand description
High-level Hyperliquid WebSocket client that provides standardized domain methods.
This client uses Arc<RwLock<>> for internal state to support Clone and safe sharing across async tasks, following the same pattern as other exchange adapters (OKX, Bitmex, Bybit).
Implementations§
Source§impl HyperliquidWebSocketClient
impl HyperliquidWebSocketClient
Sourcepub fn new(url: String) -> Self
pub fn new(url: String) -> Self
Creates a new Hyperliquid WebSocket client without connecting.
The connection will be established when ensure_connected()
is called.
Sourcepub fn add_instrument(&self, instrument: InstrumentAny)
pub fn add_instrument(&self, instrument: InstrumentAny)
Adds an instrument to the cache for parsing WebSocket messages.
Sourcepub fn get_instrument(&self, id: &InstrumentId) -> Option<InstrumentAny>
pub fn get_instrument(&self, id: &InstrumentId) -> Option<InstrumentAny>
Gets an instrument from the cache by ID.
Sourcepub fn get_instrument_by_symbol(&self, symbol: &Ustr) -> Option<InstrumentAny>
pub fn get_instrument_by_symbol(&self, symbol: &Ustr) -> Option<InstrumentAny>
Gets an instrument from the cache by symbol.
Sourcepub async fn connect(url: &str) -> Result<Self>
pub async fn connect(url: &str) -> Result<Self>
Creates a new Hyperliquid WebSocket client and establishes connection.
Sourcepub async fn ensure_connected(&self) -> Result<()>
pub async fn ensure_connected(&self) -> Result<()>
Establishes the WebSocket connection if not already connected.
Sourcepub async fn is_connected(&self) -> bool
pub async fn is_connected(&self) -> bool
Returns true if the WebSocket is connected.
Sourcepub async fn subscribe_order_updates(&self, user: &str) -> Result<()>
pub async fn subscribe_order_updates(&self, user: &str) -> Result<()>
Subscribe to order updates for a specific user address.
Ensures connection is established before subscribing.
Sourcepub async fn subscribe_user_events(&self, user: &str) -> Result<()>
pub async fn subscribe_user_events(&self, user: &str) -> Result<()>
Subscribe to user events (fills, funding, liquidations) for a specific user address.
Ensures connection is established before subscribing.
Sourcepub async fn subscribe_all_user_channels(&self, user: &str) -> Result<()>
pub async fn subscribe_all_user_channels(&self, user: &str) -> Result<()>
Subscribe to all user channels (order updates + user events) for convenience.
Sourcepub async fn subscribe_trades(&self, coin: Ustr) -> Result<()>
pub async fn subscribe_trades(&self, coin: Ustr) -> Result<()>
Subscribe to trades for a specific coin.
Ensures connection is established before subscribing.
Sourcepub async fn unsubscribe_trades(&self, coin: Ustr) -> Result<()>
pub async fn unsubscribe_trades(&self, coin: Ustr) -> Result<()>
Unsubscribe from trades for a specific coin.
Ensures connection is established before unsubscribing.
Sourcepub async fn subscribe_book(&self, coin: Ustr) -> Result<()>
pub async fn subscribe_book(&self, coin: Ustr) -> Result<()>
Subscribe to L2 order book for a specific coin.
Ensures connection is established before subscribing.
Sourcepub async fn unsubscribe_book(&self, coin: Ustr) -> Result<()>
pub async fn unsubscribe_book(&self, coin: Ustr) -> Result<()>
Unsubscribe from L2 order book for a specific coin.
Ensures connection is established before unsubscribing.
Sourcepub async fn subscribe_bbo(&self, coin: Ustr) -> Result<()>
pub async fn subscribe_bbo(&self, coin: Ustr) -> Result<()>
Subscribe to BBO (best bid/offer) for a specific coin.
Ensures connection is established before subscribing.
Sourcepub async fn unsubscribe_bbo(&self, coin: Ustr) -> Result<()>
pub async fn unsubscribe_bbo(&self, coin: Ustr) -> Result<()>
Unsubscribe from BBO (best bid/offer) for a specific coin.
Ensures connection is established before unsubscribing.
Sourcepub async fn subscribe_candle(&self, coin: Ustr, interval: String) -> Result<()>
pub async fn subscribe_candle(&self, coin: Ustr, interval: String) -> Result<()>
Subscribe to candlestick data for a specific coin and interval.
Ensures connection is established before subscribing.
Sourcepub async fn unsubscribe_candle(
&self,
coin: Ustr,
interval: String,
) -> Result<()>
pub async fn unsubscribe_candle( &self, coin: Ustr, interval: String, ) -> Result<()>
Unsubscribe from candlestick data for a specific coin and interval.
Ensures connection is established before unsubscribing.
Sourcepub async fn next_event(&self) -> Option<HyperliquidWsMessage>
pub async fn next_event(&self) -> Option<HyperliquidWsMessage>
Get the next event from the WebSocket stream. Returns None when the connection is closed or the receiver is exhausted.
Sourcepub async fn is_reconnecting(&self) -> bool
pub async fn is_reconnecting(&self) -> bool
Returns true if the WebSocket is reconnecting.
Sourcepub async fn is_disconnecting(&self) -> bool
pub async fn is_disconnecting(&self) -> bool
Returns true if the WebSocket is disconnecting.
Sourcepub async fn disconnect(&self) -> Result<()>
pub async fn disconnect(&self) -> Result<()>
Disconnect the WebSocket client.
Sourcepub async fn send_raw(&self, request: &HyperliquidWsRequest) -> Result<()>
pub async fn send_raw(&self, request: &HyperliquidWsRequest) -> Result<()>
Escape hatch: send raw requests for tests/power users.
Ensures connection is established before sending.
Sourcepub async fn info_l2_book(
&self,
coin: &str,
timeout: Duration,
) -> HyperliquidResult<HyperliquidL2Book>
pub async fn info_l2_book( &self, coin: &str, timeout: Duration, ) -> HyperliquidResult<HyperliquidL2Book>
High-level: call info l2Book (WS post)
Ensures connection is established before making the request.
Sourcepub async fn post_info_raw(
&self,
payload: Value,
timeout: Duration,
) -> HyperliquidResult<PostResponsePayload>
pub async fn post_info_raw( &self, payload: Value, timeout: Duration, ) -> HyperliquidResult<PostResponsePayload>
High-level: fire arbitrary info (WS post) returning raw payload.
Ensures connection is established before making the request.
Sourcepub async fn post_action_raw(
&self,
action: ActionPayload,
timeout: Duration,
) -> HyperliquidResult<PostResponsePayload>
pub async fn post_action_raw( &self, action: ActionPayload, timeout: Duration, ) -> HyperliquidResult<PostResponsePayload>
High-level: fire action (already signed ActionPayload)
Ensures connection is established before making the request.
Trait Implementations§
Source§impl Clone for HyperliquidWebSocketClient
impl Clone for HyperliquidWebSocketClient
Source§fn clone(&self) -> HyperliquidWebSocketClient
fn clone(&self) -> HyperliquidWebSocketClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for HyperliquidWebSocketClient
impl Debug for HyperliquidWebSocketClient
Source§impl<'py> IntoPyObject<'py> for HyperliquidWebSocketClient
impl<'py> IntoPyObject<'py> for HyperliquidWebSocketClient
Source§type Target = HyperliquidWebSocketClient
type Target = HyperliquidWebSocketClient
Source§type Output = Bound<'py, <HyperliquidWebSocketClient as IntoPyObject<'py>>::Target>
type Output = Bound<'py, <HyperliquidWebSocketClient 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 HyperliquidWebSocketClient
impl PyClass for HyperliquidWebSocketClient
Source§impl PyClassImpl for HyperliquidWebSocketClient
impl PyClassImpl for HyperliquidWebSocketClient
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 = /// High-level Hyperliquid WebSocket client that provides standardized domain methods.
///
/// This client uses Arc<RwLock<>> for internal state to support Clone and safe sharing
/// across async tasks, following the same pattern as other exchange adapters (OKX, Bitmex, Bybit).
const RAW_DOC: &'static CStr = /// High-level Hyperliquid WebSocket client that provides standardized domain methods. /// /// This client uses Arc<RwLock<>> for internal state to support Clone and safe sharing /// across async tasks, following the same pattern as other exchange adapters (OKX, Bitmex, Bybit).
Source§const DOC: &'static CStr
const DOC: &'static CStr
text_signature
if a constructor is defined. Read moreSource§type ThreadChecker = SendablePyClass<HyperliquidWebSocketClient>
type ThreadChecker = SendablePyClass<HyperliquidWebSocketClient>
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 HyperliquidWebSocketClient
impl PyClassNewTextSignature for HyperliquidWebSocketClient
const TEXT_SIGNATURE: &'static str = "(url)"
Source§impl<'a, 'holder, 'py> PyFunctionArgument<'a, 'holder, 'py, false> for &'holder HyperliquidWebSocketClient
impl<'a, 'holder, 'py> PyFunctionArgument<'a, 'holder, 'py, false> for &'holder HyperliquidWebSocketClient
Source§impl<'a, 'holder, 'py> PyFunctionArgument<'a, 'holder, 'py, false> for &'holder mut HyperliquidWebSocketClient
impl<'a, 'holder, 'py> PyFunctionArgument<'a, 'holder, 'py, false> for &'holder mut HyperliquidWebSocketClient
Source§impl PyMethods<HyperliquidWebSocketClient> for PyClassImplCollector<HyperliquidWebSocketClient>
impl PyMethods<HyperliquidWebSocketClient> for PyClassImplCollector<HyperliquidWebSocketClient>
fn py_methods(self) -> &'static PyClassItems
Source§impl PyTypeInfo for HyperliquidWebSocketClient
impl PyTypeInfo for HyperliquidWebSocketClient
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 HyperliquidWebSocketClient
Auto Trait Implementations§
impl Freeze for HyperliquidWebSocketClient
impl !RefUnwindSafe for HyperliquidWebSocketClient
impl Send for HyperliquidWebSocketClient
impl Sync for HyperliquidWebSocketClient
impl Unpin for HyperliquidWebSocketClient
impl !UnwindSafe for HyperliquidWebSocketClient
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> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§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 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> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§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,
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.