kiteconnect_async_wasm/models/common/enums/exchange.rs
1/*!
2Stock exchanges supported by KiteConnect.
3
4This module provides the `Exchange` enum which represents all major Indian stock exchanges
5and international markets accessible through the KiteConnect API. Each exchange has specific
6characteristics such as trading hours, instrument types, and settlement processes.
7
8# Example
9
10```rust
11use kiteconnect_async_wasm::models::common::Exchange;
12
13// Check exchange types
14assert!(Exchange::NSE.is_equity());
15assert!(Exchange::NFO.is_derivative());
16assert!(Exchange::MCX.is_commodity());
17
18// Get all available exchanges
19let all_exchanges = Exchange::all();
20println!("Available exchanges: {}", all_exchanges.len());
21```
22*/
23
24use serde::{Deserialize, Serialize};
25
26/// Stock exchanges supported by KiteConnect
27///
28/// This enum represents all major Indian stock exchanges and international markets
29/// that can be accessed through the KiteConnect API. Each exchange has specific
30/// trading rules, timings, and supported instrument types.
31///
32/// # Exchange Categories
33///
34/// - **Equity**: NSE, BSE, NSEIX - Cash market trading in stocks
35/// - **Derivatives**: NFO, BFO - Futures and options trading
36/// - **Commodity**: MCX, CDS, NCO - Commodity futures and options
37/// - **Global**: GLOBAL - International markets and instruments
38///
39/// # Trading Hours
40///
41/// Most Indian exchanges operate from 9:15 AM to 3:30 PM IST on trading days,
42/// with pre-market and post-market sessions available on some exchanges.
43///
44/// # Example
45///
46/// ```rust
47/// use kiteconnect_async_wasm::models::common::Exchange;
48///
49/// let exchange = Exchange::NSE;
50/// println!("Exchange: {}", exchange); // Prints: "NSE"
51///
52/// if exchange.is_equity() {
53/// println!("This is an equity exchange");
54/// }
55/// ```
56#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
57pub enum Exchange {
58 /// National Stock Exchange of India (NSE)
59 ///
60 /// Primary equity exchange in India by volume. Supports:
61 /// - Equity cash market
62 /// - ETFs and mutual funds
63 /// - Government securities
64 #[serde(rename = "NSE")]
65 NSE,
66
67 /// Bombay Stock Exchange (BSE)
68 ///
69 /// Asia's oldest stock exchange. Supports:
70 /// - Equity cash market
71 /// - SME platform
72 /// - Government securities
73 #[serde(rename = "BSE")]
74 BSE,
75
76 /// NSE Futures & Options (NFO)
77 ///
78 /// Derivatives segment of NSE. Supports:
79 /// - Index futures and options
80 /// - Stock futures and options
81 /// - Currency derivatives
82 #[serde(rename = "NFO")]
83 NFO,
84
85 /// Currency Derivatives Segment (CDS)
86 ///
87 /// Currency trading segment. Supports:
88 /// - Currency futures
89 /// - Currency options
90 /// - Cross-currency pairs
91 #[serde(rename = "CDS")]
92 CDS,
93
94 /// BSE Futures & Options (BFO)
95 ///
96 /// Derivatives segment of BSE. Supports:
97 /// - Index derivatives
98 /// - Stock derivatives
99 /// - Weekly options
100 #[serde(rename = "BFO")]
101 BFO,
102
103 /// Multi Commodity Exchange (MCX)
104 ///
105 /// India's largest commodity exchange. Supports:
106 /// - Precious metals (gold, silver)
107 /// - Base metals (copper, aluminum)
108 /// - Energy commodities (crude oil, natural gas)
109 /// - Agricultural commodities
110 #[serde(rename = "MCX")]
111 MCX,
112
113 /// Global/International markets
114 ///
115 /// Access to international instruments and markets.
116 /// Availability depends on broker permissions.
117 #[serde(rename = "GLOBAL")]
118 GLOBAL,
119
120 /// National Commodity & Derivatives Exchange (NCDEX)
121 ///
122 /// Agricultural commodity exchange. Supports:
123 /// - Agricultural futures
124 /// - Agricultural options
125 /// - Weather derivatives
126 #[serde(rename = "NCO")]
127 NCO,
128
129 /// NSE Indices Exchange (NSEIX)
130 ///
131 /// Index-based trading platform. Supports:
132 /// - Index trading
133 /// - Specialized index products
134 #[serde(rename = "NSEIX")]
135 NSEIX,
136}
137
138impl Exchange {
139 /// Get all supported exchanges
140 pub fn all() -> Vec<Self> {
141 vec![
142 Exchange::NSE,
143 Exchange::BSE,
144 Exchange::NFO,
145 Exchange::CDS,
146 Exchange::BFO,
147 Exchange::MCX,
148 Exchange::GLOBAL,
149 Exchange::NCO,
150 Exchange::NSEIX,
151 ]
152 }
153
154 /// Check if exchange supports equity trading
155 pub fn is_equity(self) -> bool {
156 matches!(self, Exchange::NSE | Exchange::BSE | Exchange::NSEIX)
157 }
158
159 /// Check if exchange supports derivatives trading
160 pub fn is_derivative(self) -> bool {
161 matches!(self, Exchange::NFO | Exchange::BFO)
162 }
163
164 /// Check if exchange supports commodity trading
165 pub fn is_commodity(self) -> bool {
166 matches!(self, Exchange::MCX | Exchange::CDS | Exchange::NCO)
167 }
168
169 /// Check if exchange is international/global
170 pub fn is_global(self) -> bool {
171 matches!(self, Exchange::GLOBAL)
172 }
173}
174
175impl std::fmt::Display for Exchange {
176 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
177 match self {
178 Exchange::NSE => write!(f, "NSE"),
179 Exchange::BSE => write!(f, "BSE"),
180 Exchange::NFO => write!(f, "NFO"),
181 Exchange::CDS => write!(f, "CDS"),
182 Exchange::BFO => write!(f, "BFO"),
183 Exchange::MCX => write!(f, "MCX"),
184 Exchange::GLOBAL => write!(f, "GLOBAL"),
185 Exchange::NCO => write!(f, "NCO"),
186 Exchange::NSEIX => write!(f, "NSEIX"),
187 }
188 }
189}