rusty_bybit/
market.rs

1//! Market data endpoints
2//!
3//! Provides access to public market data including tickers, orderbook, klines, and instrument info.
4//!
5//! # Example
6//!
7//! ````rust,no_run
8//! use rusty_bybit::BybitClient;
9//!
10//! #[tokio::main]
11//! async fn main() {
12//!     let client = BybitClient::testnet();
13//!     let tickers = client.get_tickers("linear").await.unwrap();
14//!     println!("First ticker: {}", tickers.list[0].symbol);
15//! }
16//! ```
17
18use crate::client::BybitClient;
19use crate::error::Result;
20use crate::types::{InstrumentList, OrderBook, ServerTime, TickerList};
21
22impl BybitClient {
23    pub async fn get_server_time(&self) -> Result<ServerTime> {
24        self.get("/v5/market/time", None).await
25    }
26
27    pub async fn get_kline(
28        &self,
29        category: &str,
30        symbol: &str,
31        interval: &str,
32    ) -> Result<serde_json::Value> {
33        let query = vec![
34            ("category", category),
35            ("symbol", symbol),
36            ("interval", interval),
37        ];
38        self.get("/v5/market/kline", Some(query)).await
39    }
40
41    pub async fn get_tickers(&self, category: &str) -> Result<TickerList> {
42        let query = vec![("category", category)];
43        self.get("/v5/market/tickers", Some(query)).await
44    }
45
46    pub async fn get_orderbook(
47        &self,
48        category: &str,
49        symbol: &str,
50        limit: u32,
51    ) -> Result<OrderBook> {
52        let limit_str = limit.to_string();
53        let query = vec![
54            ("category", category),
55            ("symbol", symbol),
56            ("limit", limit_str.as_str()),
57        ];
58        self.get("/v5/market/orderbook", Some(query)).await
59    }
60
61    pub async fn get_instruments(&self, category: &str) -> Result<InstrumentList> {
62        let query = vec![("category", category)];
63        self.get("/v5/market/instruments-info", Some(query)).await
64    }
65}
66
67#[cfg(test)]
68mod tests {
69    #[test]
70    fn test_market_module_exists() {}
71}