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        // Common enums
116        Exchange,
117        GttStatus,
118        InstrumentType,
119        Interval,
120        // Error types
121        KiteError,
122        // Response types
123        KiteResponse,
124        KiteResult,
125
126        OrderType,
127        Product,
128        RawResponse,
129        Status,
130
131        TransactionType,
132        Validity,
133        Variety,
134    };
135
136    // Authentication types
137    pub use super::auth::{
138        AccountStatus,
139
140        FundTransaction,
141        LoginUrlConfig,
142        LogoutResponse,
143
144        // Margin data
145        MarginData,
146        MarginFunds,
147        MarginUtilisation,
148        RequestToken,
149        SegmentMargin,
150        // Session management
151        SessionData,
152        SessionMeta,
153        TradingSegment,
154        UserMeta,
155        // User profiles
156        UserProfile,
157        UserType,
158    };
159
160    // Order types
161    pub use super::orders::{
162        BracketOrderBuilder,
163        BracketOrderParams,
164        BracketOrderResponse,
165        CoverOrderParams,
166        CoverOrderResponse,
167        // Order data
168        Order,
169        OrderBook,
170        OrderBuilder,
171        OrderCancellation,
172        OrderHistory,
173        OrderHistoryEntry,
174        OrderMeta,
175
176        // Order operations
177        OrderModification,
178        OrderModifyParams,
179
180        // Order parameters and builders
181        OrderParams,
182        OrderResponse,
183
184        OrderStatus,
185        // Order history and trades
186        Trade,
187        TradeBook,
188        TradeHistory,
189    };
190
191    // Portfolio types
192    pub use super::portfolio::{
193        BulkConversionRequest,
194        BulkConversionResponse,
195        ConversionRequest,
196        ConversionResponse,
197        ConversionResult,
198        // Conversions
199        ConversionType,
200        // Holdings
201        Holding,
202        HoldingsSummary,
203        PortfolioProfile,
204
205        // Positions
206        Position,
207        PositionConversionRequest,
208
209        PositionType,
210        PositionsSummary,
211    };
212
213    // Market data types
214    pub use super::market_data::{
215        Candle,
216        DepthItem,
217        DepthLevel,
218        HistoricalData,
219        // Historical data
220        HistoricalDataRequest,
221        HistoricalMetadata,
222        HistoricalQuote,
223        // Instruments
224        Instrument,
225        InstrumentLookup,
226
227        InstrumentSearch,
228        Level2Data,
229
230        // Market depth
231        MarketDepth,
232        MarketDepthFull,
233        MarketState,
234        MarketStatus,
235        // Quotes
236        Quote,
237        QuoteRequest,
238        LTP,
239        OHLC,
240        OHLCV,
241    };
242
243    // Mutual funds types
244    pub use super::mutual_funds::{
245        // MF holdings
246        MFHolding,
247        MFHoldings,
248        // MF instruments
249        MFInstrument,
250        MFInstrumentSearch,
251
252        // MF orders
253        MFOrder,
254        MFOrderParams,
255        MFOrderResponse,
256        MFOrderStatus,
257        MFOrders,
258
259        MFPerformance,
260        MFPortfolioSummary,
261
262        SIPFrequency,
263        SIPModifyParams,
264        SIPParams,
265        SIPResponse,
266        SIPStatus,
267        SIPStepUp,
268        SIPs,
269        // SIPs
270        SIP,
271    };
272
273    // GTT types
274    pub use super::gtt::{
275        BracketGTTBuilder,
276
277        // GTT builders
278        GTTBuilder,
279        GTTCondition,
280        GTTConditionBuilder,
281        GTTCreateParams,
282        GTTModifyParams,
283        GTTOrderBuilder,
284        GTTOrderParams,
285        GTTOrderResult,
286        GTTResponse,
287        // GTT templates
288        GTTTemplate,
289        GTTTriggerType,
290        GTTs,
291
292        StopLossGTTBuilder,
293        TargetGTTBuilder,
294        // GTT triggers
295        GTT,
296    };
297}