xapi_okx/client/order_book_trading.rs
1use crate::{client::Okx, data::ticker::OkxTicker};
2use serde_json::json;
3use tokio::sync::mpsc;
4use xapi_shared::{data::crypto_symbol::CryptoSymbol, ws::error::SharedWsError};
5
6impl Okx {
7 /// Retrieve the last traded price, bid price, ask price and 24-hour trading volume of instruments. Best ask price may be lower than the best bid price during the pre-open period.
8 /// The fastest rate is 1 update/100ms. There will be no update if the event is not triggered. The events which can trigger update: trade, the change on best ask/bid.
9 ///
10 /// <https://www.okx.com/docs-v5/en/#order-book-trading-market-data-ws-tickers-channel>
11 pub async fn subscribe_ticker(
12 &self,
13 inst_id: &CryptoSymbol,
14 ) -> Result<mpsc::Receiver<Result<Vec<OkxTicker>, SharedWsError>>, SharedWsError> {
15 self.executor
16 .subscribe_stream(
17 self.executor.get_endpoint().get_ws_pub_base_url().as_str(),
18 json!({"channel": "tickers", "instId": inst_id.as_str()}),
19 )
20 .await
21 }
22}