1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
//! # Bybit Rust API
//!
//! A comprehensive, type-safe Rust SDK for the [Bybit V5 API](https://bybit-exchange.github.io/docs/v5/guide).
//!
//! Covers **all 129 REST endpoints** across 13 modules plus
//! **full WebSocket support** with 17 streaming channels.
//!
//! ## Features
// Bybit API endpoints naturally have many optional parameters;
// this is an intentional design choice for ergonomic usage.
//!
//! - **REST API**: 129/129 endpoints (Market, Trade, Account, Position, Asset, User, Broker, etc.)
//! - **WebSocket Public**: Orderbook (snapshot/delta), Trade, Ticker, Kline, Liquidation
//! - **WebSocket Private**: Position, Execution, Order, Wallet, Greeks, DCP
//! - **WebSocket Trade**: Place, amend, cancel orders via WebSocket
//! - **Auto-reconnect**: Exponential backoff with automatic re-subscription
//! - **Rate limiting**: Token-bucket limiter for REST and WS
//! - **Authentication**: HMAC-SHA256 signing (REST + WS)
//! - **Type-safe**: Full serde types for all request/response structures
//! - **Error handling**: Structured `BybitError` with all API error codes
//! - **Async**: Built on tokio, implements `futures::Stream` for WS
//!
//! ## Quick Start
//!
//! ### REST (public endpoint, no API key)
//!
//! ```rust,no_run
//! use bybit_rust_api::rest::{ApiKeyPair, MarketClient, RestClient};
//! use bybit_rust_api::{Category, Interval};
//!
//! #[tokio::main]
//! async fn main() -> anyhow::Result<()> {
//! let keys = ApiKeyPair::new("public".into(), String::new(), String::new());
//! let client = RestClient::new(keys, "https://api.bybit.com".into());
//! let market = MarketClient::new(client);
//!
//! let time = market.get_server_time().await?;
//! println!("Server time: {}", time.result.time_second);
//! Ok(())
//! }
//! ```
//!
//! ### REST (private endpoint, with API key from env)
//!
//! ```rust,no_run
//! use bybit_rust_api::rest::{ApiKeyPair, OrderClient, RestClient};
//! use bybit_rust_api::rest::order::dto::PlaceOrderRequest;
//! use bybit_rust_api::{Category, OrderType, Side};
//!
//! #[tokio::main]
//! async fn main() -> anyhow::Result<()> {
//! dotenvy::dotenv().ok();
//! let keys = ApiKeyPair::from_env()?;
//! let client = RestClient::new(keys, "https://api.bybit.com".into());
//! let order = OrderClient::new(client);
//!
//! let req = PlaceOrderRequest {
//! category: Category::Spot,
//! symbol: "BTCUSDT".into(),
//! side: Side::Buy,
//! order_type: OrderType::Limit,
//! qty: "0.001".into(),
//! price: Some("40000".into()),
//! ..Default::default()
//! };
//! let resp = order.place_order(req).await?;
//! println!("Order ID: {}", resp.result.order_id);
//! Ok(())
//! }
//! ```
//!
//! ### WebSocket (real-time streaming)
//!
//! ```rust,no_run
//! use bybit_rust_api::ws::{WsClient, topics};
//! use futures_util::StreamExt;
//!
//! #[tokio::main]
//! async fn main() -> anyhow::Result<()> {
//! let mut client = WsClient::connect(
//! "wss://stream.bybit.com/v5/public/linear"
//! ).await?;
//!
//! client.subscribe(vec![
//! topics::orderbook(1, "BTCUSDT"),
//! topics::trade("BTCUSDT"),
//! ]).await?;
//!
//! while let Some(msg) = client.next().await {
//! println!("Topic: {:?}", msg.topic());
//! }
//! Ok(())
//! }
//! ```
//!
//! ### CLI
//!
//! ```bash
//! cargo install bybit-rust-api
//! bybit-cli time
//! bybit-cli ticker BTCUSDT
//! bybit-cli kline BTCUSDT 1h 5
//! bybit-cli orderbook BTCUSDT 5
//! ```
//!
//! ## Environment Variables
//!
//! | Variable | Description |
//! |---|---|
//! | `BYBIT_API_KEY` | API key for private endpoints |
//! | `BYBIT_API_SECRET` | API secret for signing |
//! | `BYBIT_TESTNET_API_KEY` | Testnet API key |
//! | `BYBIT_TESTNET_API_SECRET` | Testnet API secret |
//!
//! ## Module Overview
//!
//! | Module | Description |
//! |---|---|
//! | `rest` | REST API clients (Market, Order, Account, Position, Asset, etc.) |
//! | `ws` | WebSocket streams (public, private, trade) |
//! | `rest::enums` | Type-safe enums (Category, Side, Interval, OrderType, etc.) |
//! | `rest::errors` | Error types (`BybitError`, `ErrorCodes`) |
//! | `consts` | API endpoint URLs |
//! | `utils` | HMAC signing, rate limiter |
//!
//! ## Crate Features
//!
//! No feature flags — everything is included by default.
//! TLS is handled via `rustls` (no OpenSSL dependency).
// Re-export commonly used types at the top level
pub use ;
// Re-export common enums directly
pub use ;
// Organized sub-modules for easier exploration