kiteconnect_async_wasm/models/mod.rs
1/*!
2# KiteConnect v1.0.3 Data Models
3
4This module provides comprehensive typed models for all KiteConnect API operations.
5The models are organized into domain-specific submodules and offer both legacy
6compatibility and enhanced v1.0.3 features.
7
8## Model Organization
9
10- **`common`**: Shared types, enums, errors, and response wrappers
11- **`auth`**: Authentication, sessions, user profiles, and margins
12- **`orders`**: Order management, trades, and order-related types
13- **`portfolio`**: Holdings, positions, and portfolio conversions
14- **`market_data`**: Instruments, quotes, market depth, and historical data
15- **`mutual_funds`**: MF orders, instruments, SIPs, and holdings
16- **`gtt`**: GTT (Good Till Triggered) orders and triggers
17
18## What's New in v1.0.3
19
20### Enhanced Historical Data API
21- **Structured Requests**: New `HistoricalDataRequest` with builder pattern
22- **Precise DateTime**: `NaiveDateTime` support for hour/minute/second precision
23- **Type Safety**: Compile-time validation of parameters
24
25### Dual Serde Support
26- **Flexible Intervals**: Accept both strings ("day") and integers (0) for `Interval`
27- **Consistent Output**: Always serialize as strings for API compatibility
28- **Backward Compatible**: Existing code continues to work
29
30### Organized Enum System
31- **Modular Structure**: Enums split into logical submodules
32- **Better Maintainability**: Easier navigation and development
33- **Full Compatibility**: All imports work through re-exports
34
35```rust
36use kiteconnect_async_wasm::models::prelude::*;
37
38# fn main() -> Result<(), Box<dyn std::error::Error>> {
39// Current: Create typed models from JSON responses
40let json_response = r#"{
41 "account_id": "ABCD123",
42 "tradingsymbol": "RELIANCE",
43 "exchange": "NSE",
44 "isin": "INE002A01018",
45 "product": "CNC",
46 "instrument_token": 738561,
47 "quantity": 100,
48 "t1_quantity": 0,
49 "realised_quantity": 100,
50 "authorised_quantity": 0,
51 "opening_quantity": 100,
52 "collateral_quantity": 0,
53 "collateral_type": null,
54 "collateral_update_quantity": 0,
55 "discrepancy": false,
56 "average_price": 2400.0,
57 "last_price": 2450.0,
58 "close_price": 2445.0,
59 "price_change": 5.0,
60 "pnl": 5000.0,
61 "day_change": 5.0,
62 "day_change_percentage": 0.2,
63 "used_quantity": 0
64}"#;
65let holding: Holding = serde_json::from_str(&json_response)?;
66
67// Future: Direct typed API methods (roadmap)
68// let holdings: Vec<Holding> = kite.holdings_typed().await?;
69# Ok(())
70# }
71```
72
73## Error Handling
74
75All models include comprehensive error types with `KiteError`:
76
77```rust
78use kiteconnect_async_wasm::models::KiteError;
79
80// Example error handling with models
81let error = KiteError::Api {
82 status: "400".to_string(),
83 message: "Invalid parameters".to_string(),
84 error_type: Some("BadRequest".to_string()),
85};
86
87match error {
88 KiteError::Authentication(msg) => { /* handle auth error */ },
89 KiteError::Api { status, message, .. } => { /* handle API error */ },
90 KiteError::Json(err) => { /* handle JSON parsing error */ },
91 _ => { /* handle other errors */ },
92}
93```
94*/
95
96// Core common types (always available)
97pub mod common;
98
99// Phase 2: Authentication models (completed)
100pub mod auth;
101
102// Phase 3: Orders models (completed)
103pub mod orders;
104
105// Phase 4: Portfolio models (completed)
106pub mod portfolio;
107
108// Phase 5: Market data models (completed)
109pub mod market_data;
110
111// Phase 6: Mutual funds models (completed)
112pub mod mutual_funds;
113
114// Phase 7: GTT models (completed)
115pub mod gtt;
116
117// Public API - re-export main types for convenience
118pub use common::*;
119
120/// Prelude module for convenient imports
121///
122/// Import commonly used types with a single `use` statement
123///
124/// ```rust
125/// use kiteconnect_async_wasm::models::prelude::*;
126/// ```
127pub mod prelude {
128
129 // Common types
130 pub use super::common::{
131 // Common enums
132 Exchange,
133 GttStatus,
134 InstrumentType,
135 Interval,
136 // Error types
137 KiteError,
138 // Response types
139 KiteResponse,
140 KiteResult,
141
142 OrderType,
143 Product,
144 RawResponse,
145 Status,
146
147 TransactionType,
148 Validity,
149 Variety,
150 };
151
152 // Authentication types
153 pub use super::auth::{
154 AccountStatus,
155
156 FundTransaction,
157 LoginUrlConfig,
158 LogoutResponse,
159
160 // Margin data
161 MarginData,
162 MarginFunds,
163 MarginUtilisation,
164 RequestToken,
165 SegmentMargin,
166 // Session management
167 SessionData,
168 SessionMeta,
169 TradingSegment,
170 UserMeta,
171 // User profiles
172 UserProfile,
173 UserType,
174 };
175
176 // Order types
177 pub use super::orders::{
178 BracketOrderBuilder,
179 BracketOrderParams,
180 BracketOrderResponse,
181 CoverOrderParams,
182 CoverOrderResponse,
183 // Order data
184 Order,
185 OrderBook,
186 OrderBuilder,
187 OrderCancellation,
188 OrderHistory,
189 OrderHistoryEntry,
190 OrderMeta,
191
192 // Order operations
193 OrderModification,
194 OrderModifyParams,
195
196 // Order parameters and builders
197 OrderParams,
198 OrderResponse,
199
200 OrderStatus,
201 // Order history and trades
202 Trade,
203 TradeBook,
204 TradeHistory,
205 };
206
207 // Portfolio types
208 pub use super::portfolio::{
209 BulkConversionRequest,
210 BulkConversionResponse,
211 ConversionRequest,
212 ConversionResponse,
213 ConversionResult,
214 // Conversions
215 ConversionType,
216 // Holdings
217 Holding,
218 HoldingsSummary,
219 PortfolioProfile,
220
221 // Positions
222 Position,
223 PositionConversionRequest,
224
225 PositionType,
226 PositionsSummary,
227 };
228
229 // Market data types
230 pub use super::market_data::{
231 Candle,
232 DepthItem,
233 DepthLevel,
234 HistoricalData,
235 // Historical data
236 HistoricalDataRequest,
237 HistoricalMetadata,
238 HistoricalQuote,
239 // Instruments
240 Instrument,
241 InstrumentLookup,
242
243 InstrumentSearch,
244 Level2Data,
245
246 // Market depth
247 MarketDepth,
248 MarketDepthFull,
249 MarketState,
250 MarketStatus,
251 // Quotes
252 Quote,
253 QuoteRequest,
254 LTP,
255 OHLC,
256 OHLCV,
257 };
258
259 // Mutual funds types
260 pub use super::mutual_funds::{
261 // MF holdings
262 MFHolding,
263 MFHoldings,
264 // MF instruments
265 MFInstrument,
266 MFInstrumentSearch,
267
268 // MF orders
269 MFOrder,
270 MFOrderParams,
271 MFOrderResponse,
272 MFOrderStatus,
273 MFOrders,
274
275 MFPerformance,
276 MFPortfolioSummary,
277
278 SIPFrequency,
279 SIPModifyParams,
280 SIPParams,
281 SIPResponse,
282 SIPStatus,
283 SIPStepUp,
284 SIPs,
285 // SIPs
286 SIP,
287 };
288
289 // GTT types
290 pub use super::gtt::{
291 BracketGTTBuilder,
292
293 // GTT builders
294 GTTBuilder,
295 GTTCondition,
296 GTTConditionBuilder,
297 GTTCreateParams,
298 GTTModifyParams,
299 GTTOrderBuilder,
300 GTTOrderParams,
301 GTTOrderResult,
302 GTTResponse,
303 // GTT templates
304 GTTTemplate,
305 GTTTriggerType,
306 GTTs,
307
308 StopLossGTTBuilder,
309 TargetGTTBuilder,
310 // GTT triggers
311 GTT,
312 };
313}