pub struct BybitWebSocketClient { /* private fields */ }Expand description
Public/market data WebSocket client for Bybit.
Implementations§
Source§impl BybitWebSocketClient
impl BybitWebSocketClient
Sourcepub fn new_public(url: Option<String>, heartbeat: Option<u64>) -> Self
pub fn new_public(url: Option<String>, heartbeat: Option<u64>) -> Self
Creates a new Bybit public WebSocket client.
Sourcepub fn new_public_with(
product_type: BybitProductType,
environment: BybitEnvironment,
url: Option<String>,
heartbeat: Option<u64>,
) -> Self
pub fn new_public_with( product_type: BybitProductType, environment: BybitEnvironment, url: Option<String>, heartbeat: Option<u64>, ) -> Self
Creates a new Bybit public WebSocket client targeting the specified product/environment.
§Panics
Panics if the retry manager cannot be created.
Sourcepub fn new_private(
environment: BybitEnvironment,
credential: Credential,
url: Option<String>,
heartbeat: Option<u64>,
) -> Self
pub fn new_private( environment: BybitEnvironment, credential: Credential, url: Option<String>, heartbeat: Option<u64>, ) -> Self
Creates a new Bybit private WebSocket client.
§Panics
Panics if the retry manager cannot be created.
Sourcepub fn new_trade(
environment: BybitEnvironment,
credential: Credential,
url: Option<String>,
heartbeat: Option<u64>,
) -> Self
pub fn new_trade( environment: BybitEnvironment, credential: Credential, url: Option<String>, heartbeat: Option<u64>, ) -> Self
Creates a new Bybit trade WebSocket client for order operations.
§Panics
Panics if the retry manager cannot be created.
Sourcepub async fn connect(&mut self) -> BybitWsResult<()>
pub async fn connect(&mut self) -> BybitWsResult<()>
Sourcepub async fn close(&mut self) -> BybitWsResult<()>
pub async fn close(&mut self) -> BybitWsResult<()>
Disconnects the WebSocket client and stops the background task.
Sourcepub async fn wait_until_active(&self, timeout_secs: f64) -> BybitWsResult<()>
pub async fn wait_until_active(&self, timeout_secs: f64) -> BybitWsResult<()>
Waits until the WebSocket client becomes active or times out.
§Errors
Returns an error if the timeout is exceeded before the client becomes active.
Sourcepub async fn subscribe(&self, topics: Vec<String>) -> BybitWsResult<()>
pub async fn subscribe(&self, topics: Vec<String>) -> BybitWsResult<()>
Subscribe to the provided topic strings.
Sourcepub async fn unsubscribe(&self, topics: Vec<String>) -> BybitWsResult<()>
pub async fn unsubscribe(&self, topics: Vec<String>) -> BybitWsResult<()>
Unsubscribe from the provided topics.
Sourcepub fn stream(
&mut self,
) -> impl Stream<Item = BybitWebSocketMessage> + Send + 'static
pub fn stream( &mut self, ) -> impl Stream<Item = BybitWebSocketMessage> + Send + 'static
Returns a stream of parsed BybitWebSocketMessage items.
§Panics
Panics if called before Self::connect or if the stream has already been taken.
Sourcepub fn subscription_count(&self) -> usize
pub fn subscription_count(&self) -> usize
Returns the number of currently registered subscriptions.
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 instruments(&self) -> &Arc<DashMap<InstrumentId, InstrumentAny>>
pub fn instruments(&self) -> &Arc<DashMap<InstrumentId, InstrumentAny>>
Returns a reference to the instruments cache.
Sourcepub fn set_account_id(&mut self, account_id: AccountId)
pub fn set_account_id(&mut self, account_id: AccountId)
Sets the account ID for account message parsing.
Sourcepub fn account_id(&self) -> Option<AccountId>
pub fn account_id(&self) -> Option<AccountId>
Returns the account ID if set.
Sourcepub fn product_type(&self) -> Option<BybitProductType>
pub fn product_type(&self) -> Option<BybitProductType>
Returns the product type for public connections.
Sourcepub fn quote_cache(&self) -> &Arc<RwLock<QuoteCache>>
pub fn quote_cache(&self) -> &Arc<RwLock<QuoteCache>>
Returns a reference to the quote cache.
Sourcepub async fn subscribe_orderbook(
&self,
instrument_id: InstrumentId,
depth: u32,
) -> BybitWsResult<()>
pub async fn subscribe_orderbook( &self, instrument_id: InstrumentId, depth: u32, ) -> BybitWsResult<()>
Subscribes to orderbook updates for a specific instrument.
§Errors
Returns an error if the subscription request fails.
§References
https://bybit-exchange.github.io/docs/v5/websocket/public/orderbook
Sourcepub async fn unsubscribe_orderbook(
&self,
instrument_id: InstrumentId,
depth: u32,
) -> BybitWsResult<()>
pub async fn unsubscribe_orderbook( &self, instrument_id: InstrumentId, depth: u32, ) -> BybitWsResult<()>
Unsubscribes from orderbook updates for a specific instrument.
Sourcepub async fn subscribe_trades(
&self,
instrument_id: InstrumentId,
) -> BybitWsResult<()>
pub async fn subscribe_trades( &self, instrument_id: InstrumentId, ) -> BybitWsResult<()>
Subscribes to public trade updates for a specific instrument.
§Errors
Returns an error if the subscription request fails.
§References
https://bybit-exchange.github.io/docs/v5/websocket/public/trade
Sourcepub async fn unsubscribe_trades(
&self,
instrument_id: InstrumentId,
) -> BybitWsResult<()>
pub async fn unsubscribe_trades( &self, instrument_id: InstrumentId, ) -> BybitWsResult<()>
Unsubscribes from public trade updates for a specific instrument.
Sourcepub async fn subscribe_ticker(
&self,
instrument_id: InstrumentId,
) -> BybitWsResult<()>
pub async fn subscribe_ticker( &self, instrument_id: InstrumentId, ) -> BybitWsResult<()>
Subscribes to ticker updates for a specific instrument.
§Errors
Returns an error if the subscription request fails.
§References
https://bybit-exchange.github.io/docs/v5/websocket/public/ticker
Sourcepub async fn unsubscribe_ticker(
&self,
instrument_id: InstrumentId,
) -> BybitWsResult<()>
pub async fn unsubscribe_ticker( &self, instrument_id: InstrumentId, ) -> BybitWsResult<()>
Unsubscribes from ticker updates for a specific instrument.
Sourcepub async fn subscribe_klines(
&self,
instrument_id: InstrumentId,
interval: impl Into<String>,
) -> BybitWsResult<()>
pub async fn subscribe_klines( &self, instrument_id: InstrumentId, interval: impl Into<String>, ) -> BybitWsResult<()>
Subscribes to kline/candlestick updates for a specific instrument.
§Errors
Returns an error if the subscription request fails.
§References
https://bybit-exchange.github.io/docs/v5/websocket/public/kline
Sourcepub async fn unsubscribe_klines(
&self,
instrument_id: InstrumentId,
interval: impl Into<String>,
) -> BybitWsResult<()>
pub async fn unsubscribe_klines( &self, instrument_id: InstrumentId, interval: impl Into<String>, ) -> BybitWsResult<()>
Unsubscribes from kline/candlestick updates for a specific instrument.
Sourcepub async fn subscribe_orders(&self) -> BybitWsResult<()>
pub async fn subscribe_orders(&self) -> BybitWsResult<()>
Subscribes to order updates.
§Errors
Returns an error if the subscription request fails or if not authenticated.
§References
https://bybit-exchange.github.io/docs/v5/websocket/private/order
Sourcepub async fn unsubscribe_orders(&self) -> BybitWsResult<()>
pub async fn unsubscribe_orders(&self) -> BybitWsResult<()>
Unsubscribes from order updates.
Sourcepub async fn subscribe_executions(&self) -> BybitWsResult<()>
pub async fn subscribe_executions(&self) -> BybitWsResult<()>
Subscribes to execution/fill updates.
§Errors
Returns an error if the subscription request fails or if not authenticated.
§References
https://bybit-exchange.github.io/docs/v5/websocket/private/execution
Sourcepub async fn unsubscribe_executions(&self) -> BybitWsResult<()>
pub async fn unsubscribe_executions(&self) -> BybitWsResult<()>
Unsubscribes from execution/fill updates.
Sourcepub async fn subscribe_positions(&self) -> BybitWsResult<()>
pub async fn subscribe_positions(&self) -> BybitWsResult<()>
Subscribes to position updates.
§Errors
Returns an error if the subscription request fails or if not authenticated.
§References
https://bybit-exchange.github.io/docs/v5/websocket/private/position
Sourcepub async fn unsubscribe_positions(&self) -> BybitWsResult<()>
pub async fn unsubscribe_positions(&self) -> BybitWsResult<()>
Unsubscribes from position updates.
Sourcepub async fn subscribe_wallet(&self) -> BybitWsResult<()>
pub async fn subscribe_wallet(&self) -> BybitWsResult<()>
Subscribes to wallet/balance updates.
§Errors
Returns an error if the subscription request fails or if not authenticated.
§References
https://bybit-exchange.github.io/docs/v5/websocket/private/wallet
Sourcepub async fn unsubscribe_wallet(&self) -> BybitWsResult<()>
pub async fn unsubscribe_wallet(&self) -> BybitWsResult<()>
Unsubscribes from wallet/balance updates.
Sourcepub async fn place_order(
&self,
params: BybitWsPlaceOrderParams,
) -> BybitWsResult<()>
pub async fn place_order( &self, params: BybitWsPlaceOrderParams, ) -> BybitWsResult<()>
Places an order via WebSocket.
§Errors
Returns an error if the order request fails or if not authenticated.
§References
https://bybit-exchange.github.io/docs/v5/websocket/trade/guideline
Sourcepub async fn amend_order(
&self,
params: BybitWsAmendOrderParams,
) -> BybitWsResult<()>
pub async fn amend_order( &self, params: BybitWsAmendOrderParams, ) -> BybitWsResult<()>
Amends an existing order via WebSocket.
§Errors
Returns an error if the amend request fails or if not authenticated.
§References
https://bybit-exchange.github.io/docs/v5/websocket/trade/guideline
Sourcepub async fn cancel_order(
&self,
params: BybitWsCancelOrderParams,
) -> BybitWsResult<()>
pub async fn cancel_order( &self, params: BybitWsCancelOrderParams, ) -> BybitWsResult<()>
Cancels an order via WebSocket.
§Errors
Returns an error if the cancel request fails or if not authenticated.
§References
https://bybit-exchange.github.io/docs/v5/websocket/trade/guideline
Sourcepub async fn batch_place_orders(
&self,
orders: Vec<BybitWsPlaceOrderParams>,
) -> BybitWsResult<()>
pub async fn batch_place_orders( &self, orders: Vec<BybitWsPlaceOrderParams>, ) -> BybitWsResult<()>
Batch creates multiple orders via WebSocket.
§Errors
Returns an error if the batch request fails or if not authenticated.
§References
https://bybit-exchange.github.io/docs/v5/websocket/trade/guideline
Sourcepub async fn batch_amend_orders(
&self,
orders: Vec<BybitWsAmendOrderParams>,
) -> BybitWsResult<()>
pub async fn batch_amend_orders( &self, orders: Vec<BybitWsAmendOrderParams>, ) -> BybitWsResult<()>
Batch amends multiple orders via WebSocket.
§Errors
Returns an error if the batch request fails or if not authenticated.
Sourcepub async fn batch_cancel_orders(
&self,
orders: Vec<BybitWsCancelOrderParams>,
) -> BybitWsResult<()>
pub async fn batch_cancel_orders( &self, orders: Vec<BybitWsCancelOrderParams>, ) -> BybitWsResult<()>
Batch cancels multiple orders via WebSocket.
§Errors
Returns an error if the batch request fails or if not authenticated.
Sourcepub async fn submit_order(
&self,
product_type: BybitProductType,
instrument_id: InstrumentId,
client_order_id: ClientOrderId,
order_side: OrderSide,
order_type: OrderType,
quantity: Quantity,
time_in_force: Option<TimeInForce>,
price: Option<Price>,
trigger_price: Option<Price>,
post_only: Option<bool>,
reduce_only: Option<bool>,
) -> BybitWsResult<()>
pub async fn submit_order( &self, product_type: BybitProductType, instrument_id: InstrumentId, client_order_id: ClientOrderId, order_side: OrderSide, order_type: OrderType, quantity: Quantity, time_in_force: Option<TimeInForce>, price: Option<Price>, trigger_price: Option<Price>, post_only: Option<bool>, reduce_only: Option<bool>, ) -> BybitWsResult<()>
Submits an order using Nautilus domain objects.
§Errors
Returns an error if order submission fails or if not authenticated.
Sourcepub async fn modify_order(
&self,
product_type: BybitProductType,
instrument_id: InstrumentId,
venue_order_id: Option<VenueOrderId>,
client_order_id: Option<ClientOrderId>,
quantity: Option<Quantity>,
price: Option<Price>,
) -> BybitWsResult<()>
pub async fn modify_order( &self, product_type: BybitProductType, instrument_id: InstrumentId, venue_order_id: Option<VenueOrderId>, client_order_id: Option<ClientOrderId>, quantity: Option<Quantity>, price: Option<Price>, ) -> BybitWsResult<()>
Modifies an existing order using Nautilus domain objects.
§Errors
Returns an error if modification fails or if not authenticated.
Sourcepub async fn cancel_order_by_id(
&self,
product_type: BybitProductType,
instrument_id: InstrumentId,
venue_order_id: Option<VenueOrderId>,
client_order_id: Option<ClientOrderId>,
) -> BybitWsResult<()>
pub async fn cancel_order_by_id( &self, product_type: BybitProductType, instrument_id: InstrumentId, venue_order_id: Option<VenueOrderId>, client_order_id: Option<ClientOrderId>, ) -> BybitWsResult<()>
Cancels an order using Nautilus domain objects.
§Errors
Returns an error if cancellation fails or if not authenticated.
Trait Implementations§
Source§impl Clone for BybitWebSocketClient
impl Clone for BybitWebSocketClient
Source§impl Debug for BybitWebSocketClient
impl Debug for BybitWebSocketClient
Source§impl<'py> IntoPyObject<'py> for BybitWebSocketClient
impl<'py> IntoPyObject<'py> for BybitWebSocketClient
Source§type Target = BybitWebSocketClient
type Target = BybitWebSocketClient
Source§type Output = Bound<'py, <BybitWebSocketClient as IntoPyObject<'py>>::Target>
type Output = Bound<'py, <BybitWebSocketClient 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 BybitWebSocketClient
impl PyClass for BybitWebSocketClient
Source§impl PyClassImpl for BybitWebSocketClient
impl PyClassImpl for BybitWebSocketClient
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 = /// Public/market data WebSocket client for Bybit.
const RAW_DOC: &'static CStr = /// Public/market data WebSocket client for Bybit.
Source§const DOC: &'static CStr
const DOC: &'static CStr
text_signature if a constructor is defined. Read moreSource§type ThreadChecker = SendablePyClass<BybitWebSocketClient>
type ThreadChecker = SendablePyClass<BybitWebSocketClient>
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<'a, 'holder, 'py> PyFunctionArgument<'a, 'holder, 'py, false> for &'holder BybitWebSocketClient
impl<'a, 'holder, 'py> PyFunctionArgument<'a, 'holder, 'py, false> for &'holder BybitWebSocketClient
Source§impl<'a, 'holder, 'py> PyFunctionArgument<'a, 'holder, 'py, false> for &'holder mut BybitWebSocketClient
impl<'a, 'holder, 'py> PyFunctionArgument<'a, 'holder, 'py, false> for &'holder mut BybitWebSocketClient
Source§impl PyMethods<BybitWebSocketClient> for PyClassImplCollector<BybitWebSocketClient>
impl PyMethods<BybitWebSocketClient> for PyClassImplCollector<BybitWebSocketClient>
fn py_methods(self) -> &'static PyClassItems
Source§impl PyTypeInfo for BybitWebSocketClient
impl PyTypeInfo for BybitWebSocketClient
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 BybitWebSocketClient
Auto Trait Implementations§
impl Freeze for BybitWebSocketClient
impl !RefUnwindSafe for BybitWebSocketClient
impl Send for BybitWebSocketClient
impl Sync for BybitWebSocketClient
impl Unpin for BybitWebSocketClient
impl !UnwindSafe for BybitWebSocketClient
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