Module models

Source
Expand description

§KiteConnect v1.0.0 Data Models

This module provides fully typed data models for all KiteConnect API operations. The models are organized into domain-specific submodules:

  • common: Shared types, enums, errors, and response wrappers
  • auth: Authentication, sessions, user profiles, and margins
  • orders: Order management, trades, and order-related types
  • portfolio: Holdings, positions, and portfolio conversions
  • market_data: Instruments, quotes, market depth, and historical data
  • mutual_funds: MF orders, instruments, SIPs, and holdings
  • gtt: GTT (Good Till Triggered) orders and triggers

§Migration from v0.x

v1.0.0 introduces fully typed models that will replace JsonValue returns. The typed models are currently available for data serialization/deserialization:

use kiteconnect_async_wasm::models::prelude::*;

// Current: Create typed models from JSON responses
let json_response = r#"{
    "account_id": "ABCD123",
    "tradingsymbol": "RELIANCE",
    "exchange": "NSE",
    "isin": "INE002A01018",
    "product": "CNC",
    "instrument_token": 738561,
    "quantity": 100,
    "t1_quantity": 0,
    "realised_quantity": 100,
    "authorised_quantity": 0,
    "opening_quantity": 100,
    "collateral_quantity": 0,
    "collateral_type": null,
    "collateral_update_quantity": 0,
    "discrepancy": false,
    "average_price": 2400.0,
    "last_price": 2450.0,
    "close_price": 2445.0,
    "price_change": 5.0,
    "pnl": 5000.0,
    "day_change": 5.0,
    "day_change_percentage": 0.2,
    "used_quantity": 0
}"#;
let holding: Holding = serde_json::from_str(&json_response)?;

// Future: Direct typed API methods (roadmap)
// let holdings: Vec<Holding> = kite.holdings_typed().await?;

§Error Handling

All models include comprehensive error types with KiteError:

use kiteconnect_async_wasm::models::KiteError;

// Example error handling with models
let error = KiteError::Api {
    status: "400".to_string(),
    message: "Invalid parameters".to_string(),
    error_type: Some("BadRequest".to_string()),
};

match error {
    KiteError::Authentication(msg) => { /* handle auth error */ },
    KiteError::Api { status, message, .. } => { /* handle API error */ },
    KiteError::Json(err) => { /* handle JSON parsing error */ },
    _ => { /* handle other errors */ },
}

Re-exports§

pub use common::*;

Modules§

auth
Authentication and user-related data models.
common
Common types and utilities shared across all KiteConnect models.
gtt
GTT (Good Till Triggered) module for KiteConnect API v1.0.0
market_data
Market Data module for KiteConnect API v1.0.0
mutual_funds
Mutual Funds module for KiteConnect API v1.0.0
orders
Orders module for KiteConnect API v1.0.0
portfolio
Portfolio module for KiteConnect API v1.0.0
prelude
Prelude module for convenient imports Import commonly used types with a single use statement