Module models

Source
Expand description

§KiteConnect v1.0.3 Data Models

This module provides comprehensive typed models for all KiteConnect API operations. The models are organized into domain-specific submodules and offer both legacy compatibility and enhanced v1.0.3 features.

§Model Organization

  • 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

§What’s New in v1.0.3

§Enhanced Historical Data API

  • Structured Requests: New HistoricalDataRequest with builder pattern
  • Precise DateTime: NaiveDateTime support for hour/minute/second precision
  • Type Safety: Compile-time validation of parameters

§Dual Serde Support

  • Flexible Intervals: Accept both strings (“day”) and integers (0) for Interval
  • Consistent Output: Always serialize as strings for API compatibility
  • Backward Compatible: Existing code continues to work

§Organized Enum System

  • Modular Structure: Enums split into logical submodules
  • Better Maintainability: Easier navigation and development
  • Full Compatibility: All imports work through re-exports
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