0
# Market Data & Quotes
1
2
Access real-time market quotes, historical data, OHLC candles, option chains, market status information, and expired instrument data.
3
4
## Capabilities
5
6
### Real-time Market Quotes
7
8
Get current market prices, depth, and comprehensive quote information.
9
10
```python { .api }
11
def ltp(symbol: str, api_version: str) -> GetMarketQuoteLastTradedPriceResponse:
12
"""
13
Get Last Traded Price for instruments.
14
15
Parameters:
16
- symbol: Comma-separated instrument tokens
17
- api_version: API version ('2.0')
18
19
Returns:
20
GetMarketQuoteLastTradedPriceResponse with LTP data
21
"""
22
23
def get_full_market_quote(symbol: str, api_version: str) -> GetFullMarketQuoteResponse:
24
"""
25
Get complete market quote with depth, OHLC, and other details.
26
27
Parameters:
28
- symbol: Comma-separated instrument tokens
29
- api_version: API version ('2.0')
30
31
Returns:
32
GetFullMarketQuoteResponse with comprehensive quote data
33
"""
34
35
def get_market_quote_ohlc(symbol: str, interval: str, api_version: str) -> GetMarketQuoteOHLCResponse:
36
"""
37
Get OHLC (Open, High, Low, Close) data for instruments.
38
39
Parameters:
40
- symbol: Comma-separated instrument tokens
41
- interval: Time interval ('1m', '3m', '5m', '15m', '30m', '1h', '1d')
42
- api_version: API version ('2.0')
43
44
Returns:
45
GetMarketQuoteOHLCResponse with OHLC data
46
"""
47
```
48
49
#### Usage Example
50
51
```python
52
from upstox_client.api import MarketQuoteApi
53
from upstox_client import Configuration, ApiClient
54
55
# Setup
56
config = Configuration()
57
config.access_token = 'your_access_token'
58
api_client = ApiClient(config)
59
quote_api = MarketQuoteApi(api_client)
60
61
# Get Last Traded Price
62
instruments = "NSE_EQ|INE002A01018,NSE_EQ|INE009A01021" # Reliance, Infosys
63
ltp_response = quote_api.ltp(instruments, api_version='2.0')
64
65
for symbol, data in ltp_response.data.items():
66
print(f"{symbol}: ₹{data.last_price}")
67
68
# Get full market quote with depth
69
full_quote = quote_api.get_full_market_quote(
70
"NSE_EQ|INE002A01018",
71
api_version='2.0'
72
)
73
74
quote_data = full_quote.data["NSE_EQ|INE002A01018"]
75
print(f"LTP: ₹{quote_data.last_price}")
76
print(f"Volume: {quote_data.volume}")
77
print(f"Change: {quote_data.net_change} ({quote_data.percent_change}%)")
78
79
# Market depth
80
depth = quote_data.depth
81
print("Buy Orders:")
82
for buy_order in depth.buy:
83
print(f" Price: ₹{buy_order.price}, Quantity: {buy_order.quantity}")
84
85
print("Sell Orders:")
86
for sell_order in depth.sell:
87
print(f" Price: ₹{sell_order.price}, Quantity: {sell_order.quantity}")
88
89
# Get OHLC data
90
ohlc_response = quote_api.get_market_quote_ohlc(
91
"NSE_EQ|INE002A01018",
92
interval='1d',
93
api_version='2.0'
94
)
95
96
ohlc_data = ohlc_response.data["NSE_EQ|INE002A01018"]
97
print(f"Open: ₹{ohlc_data.ohlc.open}")
98
print(f"High: ₹{ohlc_data.ohlc.high}")
99
print(f"Low: ₹{ohlc_data.ohlc.low}")
100
print(f"Close: ₹{ohlc_data.ohlc.close}")
101
```
102
103
### Enhanced Market Quotes (V3 API)
104
105
Improved market quote API with batch support and option Greeks.
106
107
```python { .api }
108
def get_ltp(instrument_key: str = None) -> GetMarketQuoteLastTradedPriceResponseV3:
109
"""
110
Get Last Traded Price for multiple instruments (V3).
111
112
Parameters:
113
- instrument_key: Comma-separated list of instrument keys (optional, up to 500)
114
115
Returns:
116
GetMarketQuoteLastTradedPriceResponseV3 with LTP data
117
"""
118
119
def get_market_quote_ohlc(interval: str, instrument_key: str = None) -> GetMarketQuoteOHLCResponseV3:
120
"""
121
Get OHLC data for instruments (V3).
122
123
Parameters:
124
- interval: Time interval for OHLC data (required)
125
- instrument_key: Comma-separated list of instrument keys (optional, up to 500)
126
127
Returns:
128
GetMarketQuoteOHLCResponseV3 with OHLC data
129
"""
130
131
def get_market_quote_option_greek(instrument_key: str = None) -> GetMarketQuoteOptionGreekResponseV3:
132
"""
133
Get option Greeks (Delta, Gamma, Theta, Vega) for option instruments.
134
135
Parameters:
136
- instrument_key: Comma-separated list of instrument keys (optional, up to 500)
137
138
Returns:
139
GetMarketQuoteOptionGreekResponseV3 with Greeks data
140
"""
141
```
142
143
### Historical Data
144
145
Retrieve historical OHLC candle data and intraday data.
146
147
```python { .api }
148
def get_historical_candle_data(instrument_key: str, interval: str, to_date: str, api_version: str) -> GetHistoricalCandleResponse:
149
"""
150
Get historical candle data for an instrument.
151
152
Parameters:
153
- instrument_key: Instrument identifier
154
- interval: Candle interval ('minute', 'day', 'week', 'month')
155
- to_date: End date in YYYY-MM-DD format
156
- api_version: API version ('2.0')
157
158
Returns:
159
GetHistoricalCandleResponse with historical candles
160
"""
161
162
def get_historical_candle_data1(instrument_key: str, interval: str, to_date: str, from_date: str, api_version: str) -> GetHistoricalCandleResponse:
163
"""
164
Get historical candle data for a date range.
165
166
Parameters:
167
- instrument_key: Instrument identifier
168
- interval: Candle interval
169
- to_date: End date in YYYY-MM-DD format
170
- from_date: Start date in YYYY-MM-DD format
171
- api_version: API version ('2.0')
172
173
Returns:
174
GetHistoricalCandleResponse with historical candles
175
"""
176
177
def get_intra_day_candle_data(instrument_key: str, interval: str, api_version: str) -> GetIntraDayCandleResponse:
178
"""
179
Get intraday candle data for current trading day.
180
181
Parameters:
182
- instrument_key: Instrument identifier
183
- interval: Candle interval ('1minute', '30minute')
184
- api_version: API version ('2.0')
185
186
Returns:
187
GetIntraDayCandleResponse with intraday candles
188
"""
189
```
190
191
#### Usage Example
192
193
```python
194
from upstox_client.api import HistoryApi
195
196
history_api = HistoryApi(api_client)
197
198
# Get historical daily candles
199
historical_data = history_api.get_historical_candle_data(
200
instrument_key="NSE_EQ|INE002A01018",
201
interval="day",
202
to_date="2024-09-06",
203
api_version='2.0'
204
)
205
206
print("Historical Daily Data:")
207
for candle in historical_data.data.candles:
208
timestamp, open_price, high, low, close, volume, oi = candle
209
print(f"Date: {timestamp}, OHLC: {open_price}/{high}/{low}/{close}, Volume: {volume}")
210
211
# Get historical data with date range
212
range_data = history_api.get_historical_candle_data1(
213
instrument_key="NSE_EQ|INE002A01018",
214
interval="day",
215
to_date="2024-09-06",
216
from_date="2024-08-01",
217
api_version='2.0'
218
)
219
220
# Get intraday data
221
intraday_data = history_api.get_intra_day_candle_data(
222
instrument_key="NSE_EQ|INE002A01018",
223
interval="30minute",
224
api_version='2.0'
225
)
226
227
print("Intraday 30-minute Data:")
228
for candle in intraday_data.data.candles:
229
timestamp, open_price, high, low, close, volume, oi = candle
230
print(f"Time: {timestamp}, OHLC: {open_price}/{high}/{low}/{close}")
231
```
232
233
### Enhanced Historical Data (V3 API)
234
235
Extended historical data API with flexible time units and intervals.
236
237
```python { .api }
238
def get_historical_candle_data(instrument_key: str, unit: str, interval: int, to_date: str) -> GetHistoricalCandleResponse:
239
"""
240
Get historical candle data with flexible time units (V3).
241
242
Parameters:
243
- instrument_key: Instrument identifier (required)
244
- unit: Time unit ('minute', 'day', 'week', 'month') (required)
245
- interval: Interval number (e.g., 1, 5, 15, 30) (required)
246
- to_date: End date in YYYY-MM-DD format (required)
247
248
Returns:
249
GetHistoricalCandleResponse with historical candles
250
"""
251
252
def get_historical_candle_data1(instrument_key: str, unit: str, interval: int, to_date: str, from_date: str) -> GetHistoricalCandleResponse:
253
"""
254
Get historical candle data with date range and flexible intervals (V3).
255
256
Parameters:
257
- instrument_key: Instrument identifier (required)
258
- unit: Time unit ('minute', 'day', 'week', 'month') (required)
259
- interval: Interval number (e.g., 1, 5, 15, 30) (required)
260
- to_date: End date in YYYY-MM-DD format (required)
261
- from_date: Start date in YYYY-MM-DD format (required)
262
263
Returns:
264
GetHistoricalCandleResponse with historical candles
265
"""
266
267
def get_intra_day_candle_data(instrument_key: str, unit: str, interval: int) -> GetIntraDayCandleResponse:
268
"""
269
Get intraday candle data with flexible intervals (V3).
270
271
Parameters:
272
- instrument_key: Instrument identifier (required)
273
- unit: Time unit ('minute') (required)
274
- interval: Interval in minutes (1, 5, 15, 30) (required)
275
276
Returns:
277
GetIntraDayCandleResponse with intraday candles
278
"""
279
```
280
281
### Options Data
282
283
Access option contracts, option chains, and option-specific market data.
284
285
```python { .api }
286
def get_option_contracts(instrument_key: str) -> GetOptionContractResponse:
287
"""
288
Get available option contracts for an underlying instrument.
289
290
Parameters:
291
- instrument_key: Underlying instrument identifier
292
293
Returns:
294
GetOptionContractResponse with option contracts
295
"""
296
297
def get_put_call_option_chain(instrument_key: str, expiry_date: str) -> GetOptionChainResponse:
298
"""
299
Get complete option chain with put and call options.
300
301
Parameters:
302
- instrument_key: Underlying instrument identifier
303
- expiry_date: Option expiry date in YYYY-MM-DD format
304
305
Returns:
306
GetOptionChainResponse with option chain data
307
"""
308
```
309
310
#### Usage Example
311
312
```python
313
from upstox_client.api import OptionsApi
314
315
options_api = OptionsApi(api_client)
316
317
# Get option contracts for Nifty
318
option_contracts = options_api.get_option_contracts("NSE_INDEX|Nifty 50")
319
320
print("Available Expiry Dates:")
321
for expiry in option_contracts.data:
322
print(f"Expiry: {expiry}")
323
324
# Get option chain for specific expiry
325
option_chain = options_api.get_put_call_option_chain(
326
instrument_key="NSE_INDEX|Nifty 50",
327
expiry_date="2024-09-26"
328
)
329
330
print("Option Chain:")
331
for strike_price, strike_data in option_chain.data.items():
332
call_data = strike_data.call_options
333
put_data = strike_data.put_options
334
335
print(f"Strike {strike_price}:")
336
if call_data:
337
print(f" Call LTP: ₹{call_data.last_price}, IV: {call_data.implied_volatility}")
338
if put_data:
339
print(f" Put LTP: ₹{put_data.last_price}, IV: {put_data.implied_volatility}")
340
```
341
342
### Market Status & Holidays
343
344
Get market timings, holidays, and exchange status information.
345
346
```python { .api }
347
def get_market_status(exchange: str) -> GetMarketStatusResponse:
348
"""
349
Get current market status for an exchange.
350
351
Parameters:
352
- exchange: Exchange name ('NSE', 'BSE', 'MCX')
353
354
Returns:
355
GetMarketStatusResponse with market status
356
"""
357
358
def get_exchange_timings(date: str) -> GetExchangeTimingResponse:
359
"""
360
Get exchange trading timings for a specific date.
361
362
Parameters:
363
- date: Date in YYYY-MM-DD format
364
365
Returns:
366
GetExchangeTimingResponse with trading hours
367
"""
368
369
def get_holidays() -> GetHolidayResponse:
370
"""
371
Get list of market holidays.
372
373
Returns:
374
GetHolidayResponse with holiday information
375
"""
376
377
def get_holiday(date: str) -> GetHolidayResponse:
378
"""
379
Check if a specific date is a market holiday.
380
381
Parameters:
382
- date: Date in YYYY-MM-DD format
383
384
Returns:
385
GetHolidayResponse with holiday status
386
"""
387
```
388
389
### Expired Instruments
390
391
Access expired futures and options contracts and their historical data.
392
393
```python { .api }
394
def get_expired_future_contracts(instrument_key: str, expiry_date: str) -> GetExpiredFuturesContractResponse:
395
"""
396
Get expired futures contracts.
397
398
Parameters:
399
- instrument_key: Underlying instrument identifier
400
- expiry_date: Expiry date in YYYY-MM-DD format
401
402
Returns:
403
GetExpiredFuturesContractResponse with expired contracts
404
"""
405
406
def get_expired_option_contracts(instrument_key: str, expiry_date: str) -> GetOptionContractResponse:
407
"""
408
Get expired option contracts.
409
410
Parameters:
411
- instrument_key: Underlying instrument identifier
412
- expiry_date: Expiry date in YYYY-MM-DD format
413
414
Returns:
415
GetOptionContractResponse with expired option contracts
416
"""
417
418
def get_expired_historical_candle_data(expired_instrument_key: str, interval: str, to_date: str, from_date: str) -> GetHistoricalCandleResponse:
419
"""
420
Get historical data for expired instruments.
421
422
Parameters:
423
- expired_instrument_key: Expired instrument identifier
424
- interval: Candle interval
425
- to_date: End date in YYYY-MM-DD format
426
- from_date: Start date in YYYY-MM-DD format
427
428
Returns:
429
GetHistoricalCandleResponse with historical data
430
"""
431
432
def get_expiries(instrument_key: str) -> GetExpiriesResponse:
433
"""
434
Get available expiry dates for an instrument.
435
436
Parameters:
437
- instrument_key: Instrument identifier
438
439
Returns:
440
GetExpiriesResponse with expiry dates
441
"""
442
```
443
444
## Request/Response Types
445
446
```python { .api }
447
class GetMarketQuoteLastTradedPriceResponse:
448
status: str
449
data: dict[str, MarketQuoteSymbolLtp]
450
451
class MarketQuoteSymbolLtp:
452
instrument_token: str
453
last_price: float
454
455
class GetFullMarketQuoteResponse:
456
status: str
457
data: dict[str, MarketQuoteSymbol]
458
459
class MarketQuoteSymbol:
460
instrument_token: str
461
exchange: str
462
tradingsymbol: str
463
last_price: float
464
previous_close: float
465
change: float
466
percent_change: float
467
volume: int
468
last_trade_time: str
469
oi: int # Open Interest
470
oi_day_high: int
471
oi_day_low: int
472
depth: Depth # Market depth
473
474
class Depth:
475
buy: list[DepthItem]
476
sell: list[DepthItem]
477
478
class DepthItem:
479
price: float
480
quantity: int
481
orders: int
482
483
class GetMarketQuoteOHLCResponse:
484
status: str
485
data: dict[str, MarketQuoteOHLC]
486
487
class MarketQuoteOHLC:
488
instrument_token: str
489
ohlc: Ohlc
490
491
class Ohlc:
492
open: float
493
high: float
494
low: float
495
close: float
496
497
class GetHistoricalCandleResponse:
498
status: str
499
data: HistoricalCandleData
500
501
class HistoricalCandleData:
502
candles: list[list] # Each candle: [timestamp, open, high, low, close, volume, oi]
503
504
class GetIntraDayCandleResponse:
505
status: str
506
data: IntraDayCandleData
507
508
class IntraDayCandleData:
509
candles: list[list] # Each candle: [timestamp, open, high, low, close, volume, oi]
510
511
class GetOptionChainResponse:
512
status: str
513
data: dict[str, PutCallOptionChainData]
514
515
class PutCallOptionChainData:
516
strike_price: float
517
call_options: OptionStrikeData
518
put_options: OptionStrikeData
519
520
class OptionStrikeData:
521
instrument_token: str
522
last_price: float
523
implied_volatility: float
524
delta: float
525
gamma: float
526
theta: float
527
vega: float
528
529
class GetMarketStatusResponse:
530
status: str
531
data: list[MarketStatusData]
532
533
class MarketStatusData:
534
exchange: str
535
status: str # 'open', 'close', 'break'
536
537
class GetExchangeTimingResponse:
538
status: str
539
data: list[ExchangeTimingData]
540
541
class ExchangeTimingData:
542
exchange: str
543
trading_start_time: str
544
trading_end_time: str
545
546
class GetHolidayResponse:
547
status: str
548
data: list[HolidayData]
549
550
class HolidayData:
551
date: str
552
description: str
553
holiday_type: str
554
```
555
556
## Common Instrument Token Formats
557
558
Instrument tokens identify specific tradeable instruments:
559
560
### Equity
561
- `"NSE_EQ|INE002A01018"` - Reliance Industries (NSE)
562
- `"BSE_EQ|INE002A01018"` - Reliance Industries (BSE)
563
564
### Indices
565
- `"NSE_INDEX|Nifty 50"` - Nifty 50 Index
566
- `"NSE_INDEX|Nifty Bank"` - Bank Nifty Index
567
568
### Futures
569
- `"NSE_FO|46942"` - Futures contract on NSE
570
- `"MCX_FO|249736"` - Commodity futures on MCX
571
572
### Options
573
- `"NSE_FO|46943"` - Options contract on NSE
574
575
### Currency
576
- `"NSE_CD|1"` - Currency derivatives
577
578
Use the instrument master files or search APIs to get exact instrument tokens for your trading needs.