Skip to main content

OkxWs

Struct OkxWs 

Source
pub struct OkxWs<C: WsConnector = TungsteniteConnector> { /* private fields */ }
Expand description

OKX WebSocket client.

Implementations§

Source§

impl OkxWs<TungsteniteConnector>

Source

pub fn public() -> OkxWsBuilder<TungsteniteConnector>

Start building a public WebSocket client.

Source

pub fn business() -> OkxWsBuilder<TungsteniteConnector>

Start building a business WebSocket client.

Source

pub fn private(credentials: Credentials) -> OkxWsBuilder<TungsteniteConnector>

Start building a private WebSocket client.

Source§

impl<C: WsConnector> OkxWs<C>

Source

pub async fn subscribe(&mut self, args: &[Arg]) -> Result<(), Error>

Subscribe to one or more channel arguments.

OKX docs: https://www.okx.com/docs-v5/en/#overview-websocket-subscribe

Source

pub async fn unsubscribe(&mut self, args: &[Arg]) -> Result<(), Error>

Unsubscribe from one or more channel arguments.

OKX docs: https://www.okx.com/docs-v5/en/#overview-websocket-unsubscribe

Source

pub async fn next_event(&mut self) -> Result<Option<WsEvent>, Error>

Receive and decode the next WebSocket event.

Source

pub async fn close(&mut self) -> Result<(), Error>

Close the WebSocket connection.

Source§

impl<C: WsConnector> OkxWs<C>

Source

pub async fn send_request<A: Serialize>( &mut self, id: impl Into<String>, op: impl Into<String>, args: &[A], ) -> Result<(), Error>

Send a raw WebSocket operation request.

The response is returned asynchronously through WsEvent::Operation.

OKX docs: https://www.okx.com/docs-v5/en/#overview-websocket

Source

pub async fn send_request_with_expiry<A: Serialize>( &mut self, id: impl Into<String>, op: impl Into<String>, exp_time: Option<String>, args: &[A], ) -> Result<(), Error>

Send a raw WebSocket operation request with an optional effective deadline.

exp_time is a Unix timestamp in milliseconds. OKX discards the request when it reaches the matching trading engine after this deadline.

OKX docs: https://www.okx.com/docs-v5/en/#overview-websocket

Source§

impl<C: WsConnector> OkxWs<C>

Source

pub async fn place_spread_order_ws( &mut self, id: impl Into<String>, request: &PlaceSpreadOrderRequest, ) -> Result<(), Error>

Send sprd-order to place a spread order over the business WebSocket.

OKX docs: https://www.okx.com/docs-v5/en/#spread-trading-websocket-trade-api-ws-place-order

Source

pub async fn amend_spread_order_ws( &mut self, id: impl Into<String>, request: &AmendSpreadOrderRequest, ) -> Result<(), Error>

Send sprd-amend-order to amend a spread order over the business WebSocket.

OKX docs: https://www.okx.com/docs-v5/en/#spread-trading-websocket-trade-api-ws-amend-order

Source

pub async fn cancel_spread_order_ws( &mut self, id: impl Into<String>, request: &CancelSpreadOrderRequest, ) -> Result<(), Error>

Send sprd-cancel-order to cancel a spread order over the business WebSocket.

OKX docs: https://www.okx.com/docs-v5/en/#spread-trading-websocket-trade-api-ws-cancel-order

Source

pub async fn mass_cancel_spread_ws( &mut self, id: impl Into<String>, request: &MassCancelSpreadOrdersRequest, ) -> Result<(), Error>

Send sprd-mass-cancel to cancel spread orders over the business WebSocket.

OKX docs: https://www.okx.com/docs-v5/en/#spread-trading-websocket-trade-api-ws-cancel-all-orders

Source§

impl<C: WsConnector> OkxWs<C>

Source

pub async fn place_order_ws( &mut self, id: impl Into<String>, request: &PlaceOrderRequest<'_>, ) -> Result<(), Error>

Send order to place one order over WebSocket.

OKX docs: https://www.okx.com/docs-v5/en/#order-book-trading-trade-ws-place-order

Source

pub async fn place_orders_ws( &mut self, id: impl Into<String>, requests: &[PlaceOrderRequest<'_>], ) -> Result<(), Error>

Send batch-orders to place multiple orders over WebSocket.

OKX docs: https://www.okx.com/docs-v5/en/#order-book-trading-trade-ws-place-multiple-orders

Source

pub async fn cancel_order_ws( &mut self, id: impl Into<String>, request: &CancelOrderRequest<'_>, ) -> Result<(), Error>

Send cancel-order to cancel one order over WebSocket.

OKX docs: https://www.okx.com/docs-v5/en/#order-book-trading-trade-ws-cancel-order

Source

pub async fn cancel_orders_ws( &mut self, id: impl Into<String>, requests: &[CancelOrderRequest<'_>], ) -> Result<(), Error>

Send batch-cancel-orders to cancel multiple orders over WebSocket.

OKX docs: https://www.okx.com/docs-v5/en/#order-book-trading-trade-ws-cancel-multiple-orders

Source

pub async fn amend_order_ws( &mut self, id: impl Into<String>, request: &AmendOrderRequest<'_>, ) -> Result<(), Error>

Send amend-order to amend one order over WebSocket.

OKX docs: https://www.okx.com/docs-v5/en/#order-book-trading-trade-ws-amend-order

Source

pub async fn amend_orders_ws( &mut self, id: impl Into<String>, requests: &[AmendOrderRequest<'_>], ) -> Result<(), Error>

Send batch-amend-orders to amend multiple orders over WebSocket.

OKX docs: https://www.okx.com/docs-v5/en/#order-book-trading-trade-ws-amend-multiple-orders

Source

pub async fn mass_cancel_ws( &mut self, id: impl Into<String>, request: &MassCancelRequest, ) -> Result<(), Error>

Send mass-cancel to cancel market-maker-protection orders.

OKX docs: https://www.okx.com/docs-v5/en/#order-book-trading-trade-ws-mass-cancel-order

Auto Trait Implementations§

§

impl<C> Freeze for OkxWs<C>
where C: Freeze, <C as WsConnector>::Conn: Freeze,

§

impl<C> RefUnwindSafe for OkxWs<C>

§

impl<C> Send for OkxWs<C>

§

impl<C> Sync for OkxWs<C>
where <C as WsConnector>::Conn: Sync,

§

impl<C> Unpin for OkxWs<C>
where C: Unpin, <C as WsConnector>::Conn: Unpin,

§

impl<C> UnsafeUnpin for OkxWs<C>

§

impl<C> UnwindSafe for OkxWs<C>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more