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
//! # dhan-rs
//!
//! An **unofficial** Rust client library for the
//! [DhanHQ Broker API v2](https://dhanhq.co/docs/v2/).
//!
//! ## ⚠️ AI-Generated Code Disclaimer
//!
//! **This entire crate was generated by AI.** While it compiles and follows the
//! DhanHQ API v2 specification, it has **not been extensively tested** against
//! the live API. Before using this in production or with real money, please:
//!
//! - Review the source code thoroughly
//! - Write your own integration tests
//! - Validate all order placement, modification, and cancellation flows
//! - Verify WebSocket market feed parsing against real data
//!
//! **The authors accept no responsibility for financial losses incurred through
//! the use of this library.**
//!
//! ## Overview
//!
//! `dhan-rs` provides a broad, strongly-typed async Rust client for documented
//! DhanHQ v2 REST endpoints and WebSocket protocols. Dhan's HTML and linked
//! OpenAPI sources contain conflicts, and live authenticated compatibility is
//! not certified:
//!
//! - **80 REST API methods** covering orders, portfolio, Data APIs, Global
//! Stocks, instruments, historical data, option chains, funds, and more
//! - **Live Market Feed** with a low-level stream and supervised manager
//! - **Live Order Updates** with low-level and managed/reconciling APIs
//! - **Separate 20-level and 200-level Full Market Depth streams**
//! - **Rich error handling** with [`DhanError`] covering API errors, HTTP
//! errors, JSON deserialization errors, and WebSocket errors
//!
//! ## Quick Start
//!
//! ```no_run
//! use dhan_rs::DhanClient;
//! use dhan_rs::types::orders::PlaceOrderRequest;
//! use dhan_rs::types::enums::*;
//!
//! #[tokio::main]
//! async fn main() -> dhan_rs::Result<()> {
//! // Create a client with your DhanHQ credentials
//! let client = DhanClient::new("your-client-id", "your-access-token");
//!
//! // Place an order
//! let req = PlaceOrderRequest {
//! dhan_client_id: "your-client-id".into(),
//! correlation_id: None,
//! transaction_type: TransactionType::BUY,
//! exchange_segment: ExchangeSegment::NSE_EQ,
//! product_type: ProductType::INTRADAY,
//! order_type: OrderType::LIMIT,
//! validity: Validity::DAY,
//! security_id: "1333".into(),
//! quantity: 1,
//! price: Some(1500.0),
//! disclosed_quantity: None,
//! trigger_price: None,
//! after_market_order: None,
//! amo_time: None,
//! bo_profit_value: None,
//! bo_stop_loss_value: None,
//! };
//! let response = client.place_order(&req).await?;
//! println!("Order placed: {:?}", response);
//!
//! // Fetch holdings
//! let holdings = client.get_holdings().await?;
//! println!("Holdings: {} instruments", holdings.len());
//!
//! Ok(())
//! }
//! ```
//!
//! ## WebSocket Streaming
//!
//! ### Market Feed (Binary)
//!
//! ```no_run
//! use dhan_rs::ws::market_feed::{MarketFeedStream, Instrument};
//! use dhan_rs::types::enums::FeedRequestCode;
//! use futures_util::StreamExt;
//!
//! # #[tokio::main]
//! # async fn main() -> dhan_rs::Result<()> {
//! let mut stream = MarketFeedStream::connect("client-id", "token").await?;
//!
//! let instruments = vec![Instrument::new("NSE_EQ", "1333")];
//! stream.subscribe(FeedRequestCode::SubscribeTicker, &instruments).await?;
//!
//! while let Some(event) = stream.next().await {
//! println!("{event:?}");
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ### Order Updates (JSON)
//!
//! ```no_run
//! use dhan_rs::ws::order_update::OrderUpdateStream;
//! use futures_util::StreamExt;
//!
//! # #[tokio::main]
//! # async fn main() -> dhan_rs::Result<()> {
//! let mut stream = OrderUpdateStream::connect("client-id", "token").await?;
//!
//! while let Some(msg) = stream.next().await {
//! match msg {
//! Ok(update) => println!("Order update: {:?}", update.Data.Status),
//! Err(e) => eprintln!("Error: {e}"),
//! }
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ## Module Organization
//!
//! - [`client`] — The [`DhanClient`] HTTP client with authentication
//! - [`error`] — [`DhanError`] enum and [`Result`] alias
//! - [`constants`] — Base URLs, WebSocket URLs, rate limit values
//! - [`types`] — Request/response structs and shared enums
//! - [`api`] — REST endpoint implementations (methods on `DhanClient`)
//! - [`ws`] — Standard feed, order updates, and Full Market Depth streaming
//!
//! ## Feature Flags
//!
//! The optional `cli` feature enables the `ws_check` diagnostic binary and its
//! `tracing-subscriber` dependency. Library functionality is available by
//! default.
/// Re-export the main client type at crate root for convenience.
pub use DhanClient;
/// Re-export the error type and Result alias.
pub use ;