kiteconnect_async_wasm/models/mod.rs
1/*!
2# KiteConnect v1.0.0 Data Models
3
4This module provides fully typed data models for all KiteConnect API operations.
5The models are organized into domain-specific submodules:
6
7- **`common`**: Shared types, enums, errors, and response wrappers
8- **`auth`**: Authentication, sessions, user profiles, and margins
9- **`orders`**: Order management, trades, and order-related types
10- **`portfolio`**: Holdings, positions, and portfolio conversions
11- **`market_data`**: Instruments, quotes, market depth, and historical data
12- **`mutual_funds`**: MF orders, instruments, SIPs, and holdings
13- **`gtt`**: GTT (Good Till Triggered) orders and triggers
14
15## Migration from v0.x
16
17v1.0.0 introduces fully typed models that will replace `JsonValue` returns.
18The typed models are currently available for data serialization/deserialization:
19
20```rust
21use kiteconnect_async_wasm::models::prelude::*;
22
23# fn main() -> Result<(), Box<dyn std::error::Error>> {
24// Current: Create typed models from JSON responses
25let json_response = r#"{
26 "account_id": "ABCD123",
27 "tradingsymbol": "RELIANCE",
28 "exchange": "NSE",
29 "isin": "INE002A01018",
30 "product": "CNC",
31 "instrument_token": 738561,
32 "quantity": 100,
33 "t1_quantity": 0,
34 "realised_quantity": 100,
35 "authorised_quantity": 0,
36 "opening_quantity": 100,
37 "collateral_quantity": 0,
38 "collateral_type": null,
39 "collateral_update_quantity": 0,
40 "discrepancy": false,
41 "average_price": 2400.0,
42 "last_price": 2450.0,
43 "close_price": 2445.0,
44 "price_change": 5.0,
45 "pnl": 5000.0,
46 "day_change": 5.0,
47 "day_change_percentage": 0.2,
48 "used_quantity": 0
49}"#;
50let holding: Holding = serde_json::from_str(&json_response)?;
51
52// Future: Direct typed API methods (roadmap)
53// let holdings: Vec<Holding> = kite.holdings_typed().await?;
54# Ok(())
55# }
56```
57
58## Error Handling
59
60All models include comprehensive error types with `KiteError`:
61
62```rust
63use kiteconnect_async_wasm::models::KiteError;
64
65// Example error handling with models
66let error = KiteError::Api {
67 status: "400".to_string(),
68 message: "Invalid parameters".to_string(),
69 error_type: Some("BadRequest".to_string()),
70};
71
72match error {
73 KiteError::Authentication(msg) => { /* handle auth error */ },
74 KiteError::Api { status, message, .. } => { /* handle API error */ },
75 KiteError::Json(err) => { /* handle JSON parsing error */ },
76 _ => { /* handle other errors */ },
77}
78```
79*/
80
81// Core common types (always available)
82pub mod common;
83
84// Phase 2: Authentication models (completed)
85pub mod auth;
86
87// Phase 3: Orders models (completed)
88pub mod orders;
89
90// Phase 4: Portfolio models (completed)
91pub mod portfolio;
92
93// Phase 5: Market data models (completed)
94pub mod market_data;
95
96// Phase 6: Mutual funds models (completed)
97pub mod mutual_funds;
98
99// Phase 7: GTT models (completed)
100pub mod gtt;
101
102// Public API - re-export main types for convenience
103pub use common::*;
104
105/// Prelude module for convenient imports
106pub mod prelude {
107 //! Import commonly used types with a single `use` statement
108 //!
109 //! ```rust
110 //! use kiteconnect_async_wasm::models::prelude::*;
111 //! ```
112
113 // Common types
114 pub use super::common::{
115 // Error types
116 KiteError, KiteResult,
117
118 // Response types
119 KiteResponse, RawResponse, Status,
120
121 // Common enums
122 Exchange, Product, Validity, TransactionType, OrderType,
123 Variety, InstrumentType, GttStatus, Interval,
124 };
125
126 // Authentication types
127 pub use super::auth::{
128 // Session management
129 SessionData, SessionMeta, LoginUrlConfig, RequestToken, LogoutResponse,
130
131 // User profiles
132 UserProfile, UserMeta, UserType, AccountStatus,
133
134 // Margin data
135 MarginData, SegmentMargin, MarginFunds, MarginUtilisation,
136 TradingSegment, FundTransaction,
137 };
138
139 // Order types
140 pub use super::orders::{
141 // Order data
142 Order, OrderStatus, OrderMeta,
143
144 // Order parameters and builders
145 OrderParams, OrderBuilder, BracketOrderParams, BracketOrderBuilder,
146 CoverOrderParams, OrderModifyParams,
147
148 // Order history and trades
149 Trade, OrderHistoryEntry, OrderHistory, TradeHistory,
150 OrderBook, TradeBook, OrderResponse,
151
152 // Order operations
153 OrderModification, OrderCancellation, BracketOrderResponse, CoverOrderResponse,
154 };
155
156 // Portfolio types
157 pub use super::portfolio::{
158 // Holdings
159 Holding, HoldingsSummary, PortfolioProfile,
160
161 // Positions
162 Position, PositionType, PositionsSummary, PositionConversionRequest,
163
164 // Conversions
165 ConversionType, ConversionRequest, ConversionResponse,
166 BulkConversionRequest, BulkConversionResponse, ConversionResult,
167 };
168
169 // Market data types
170 pub use super::market_data::{
171 // Instruments
172 Instrument, MarketStatus, MarketState, InstrumentSearch, InstrumentLookup,
173
174 // Quotes
175 Quote, OHLC, LTP, QuoteRequest, HistoricalQuote, OHLCV,
176
177 // Market depth
178 MarketDepth, DepthItem, MarketDepthFull, DepthLevel, Level2Data,
179
180 // Historical data
181 HistoricalDataRequest, Candle, HistoricalData, HistoricalMetadata,
182 };
183
184 // Mutual funds types
185 pub use super::mutual_funds::{
186 // MF instruments
187 MFInstrument, MFPerformance, MFInstrumentSearch,
188
189 // MF orders
190 MFOrder, MFOrderParams, MFOrderStatus, MFOrderResponse, MFOrders,
191
192 // MF holdings
193 MFHolding, MFHoldings, MFPortfolioSummary,
194
195 // SIPs
196 SIP, SIPParams, SIPStatus, SIPFrequency, SIPStepUp, SIPModifyParams,
197 SIPResponse, SIPs,
198 };
199
200 // GTT types
201 pub use super::gtt::{
202 // GTT triggers
203 GTT, GTTCondition, GTTOrderParams, GTTOrderResult, GTTTriggerType,
204 GTTCreateParams, GTTModifyParams, GTTResponse, GTTs,
205
206 // GTT builders
207 GTTBuilder, GTTOrderBuilder, GTTConditionBuilder,
208 StopLossGTTBuilder, TargetGTTBuilder, BracketGTTBuilder,
209
210 // GTT templates
211 GTTTemplate,
212 };
213}