Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Samples are grouped by API area. Each `.md` file contains one or more Python sni
| [**user/**](user/) | User profile, fund and margin details, IP management, kill switch. |
| [**orders/**](orders/) | Order lifecycle: place (single/multi, v2 & v3), modify, cancel, order book, order details, order history, trades, historical trades, exit all positions. |
| [**portfolio/**](portfolio/) | Positions, holdings, MTF positions, convert positions. |
| [**market-quote/**](market-quote/) | LTP, full market quotes, OHLC (v2 & v3), option Greeks. |
| [**market-quote/**](market-quote/) | LTP, full market quotes (v2 & v3), OHLC (v2 & v3), option Greeks. |
| [**historical-data/**](historical-data/) | Historical and intraday candle data (v2 & v3). |
| [**option-chain/**](option-chain/) | Option contracts, put-call option chain. |
| [**expired-instruments/**](expired-instruments/) | Expiries, expired future/option contracts, expired historical candle data. |
Expand Down
36 changes: 21 additions & 15 deletions examples/market-quote/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,33 @@ Links to all market-quote-related examples in the `code/` folder.
- 1.1 [Get full market quote](code/full-market-quotes.md#get-full-market-quote)
- 1.2 [Get full market quote for multiple instrument keys](code/full-market-quotes.md#get-full-market-quote-for-multiple-instrument-keys)

## 2. OHLC Quotes V3
## 2. Full Market Quotes V3

- 2.1 [Get ohlc (open, high, low, close) market quotes](code/ohlc-quotes-v3.md#get-ohlc-open-high-low-close-market-quotes)
- 2.2 [Get ohlc (open, high, low, close) market quotes for multiple instrument keys](code/ohlc-quotes-v3.md#get-ohlc-open-high-low-close-market-quotes-for-multiple-instrument-keys)
- 2.1 [Get full market quote](code/full-market-quotes-v3.md#get-full-market-quote)
- 2.2 [Get full market quote for multiple instrument keys](code/full-market-quotes-v3.md#get-full-market-quote-for-multiple-instrument-keys)
- 2.3 [Read fields from the full market quote response](code/full-market-quotes-v3.md#read-fields-from-the-full-market-quote-response)

## 3. LTP Quotes V3
## 3. OHLC Quotes V3

- 3.1 [Get ltp (last traded price) market quotes](code/ltp-quotes-v3.md#get-ltp-last-traded-price-market-quotes)
- 3.2 [Get ltp (last traded price) market quotes for multiple instruments keys](code/ltp-quotes-v3.md#get-ltp-last-traded-price-market-quotes-for-multiple-instruments-keys)
- 3.1 [Get ohlc (open, high, low, close) market quotes](code/ohlc-quotes-v3.md#get-ohlc-open-high-low-close-market-quotes)
- 3.2 [Get ohlc (open, high, low, close) market quotes for multiple instrument keys](code/ohlc-quotes-v3.md#get-ohlc-open-high-low-close-market-quotes-for-multiple-instrument-keys)

## 4. Option Greek
## 4. LTP Quotes V3

- 4.1 [Get Option Greek fields](code/option-greek.md#get-option-greek-fields)
- 4.2 [Get Option Greek fields for multiple instruments keys](code/option-greek.md#get-option-greek-fields-for-multiple-instruments-keys)
- 4.1 [Get ltp (last traded price) market quotes](code/ltp-quotes-v3.md#get-ltp-last-traded-price-market-quotes)
- 4.2 [Get ltp (last traded price) market quotes for multiple instruments keys](code/ltp-quotes-v3.md#get-ltp-last-traded-price-market-quotes-for-multiple-instruments-keys)

## 5. OHLC Quotes
## 5. Option Greek

- 5.1 [Get ohlc (open, high, low, close) market quotes](code/ohlc-quotes.md#get-ohlc-open-high-low-close-market-quotes)
- 5.2 [Get ohlc (open, high, low, close) market quotes for multiple instrument keys](code/ohlc-quotes.md#get-ohlc-open-high-low-close-market-quotes-for-multiple-instrument-keys)
- 5.1 [Get Option Greek fields](code/option-greek.md#get-option-greek-fields)
- 5.2 [Get Option Greek fields for multiple instruments keys](code/option-greek.md#get-option-greek-fields-for-multiple-instruments-keys)

## 6. LTP Quotes
## 6. OHLC Quotes

- 6.1 [Get ltp (last traded price) market quotes](code/ltp-quotes.md#get-ltp-last-traded-price-market-quotes)
- 6.2 [Get ltp (last traded price) market quotes for multiple instruments keys](code/ltp-quotes.md#get-ltp-last-traded-price-market-quotes-for-multiple-instruments-keys)
- 6.1 [Get ohlc (open, high, low, close) market quotes](code/ohlc-quotes.md#get-ohlc-open-high-low-close-market-quotes)
- 6.2 [Get ohlc (open, high, low, close) market quotes for multiple instrument keys](code/ohlc-quotes.md#get-ohlc-open-high-low-close-market-quotes-for-multiple-instrument-keys)

## 7. LTP Quotes

- 7.1 [Get ltp (last traded price) market quotes](code/ltp-quotes.md#get-ltp-last-traded-price-market-quotes)
- 7.2 [Get ltp (last traded price) market quotes for multiple instruments keys](code/ltp-quotes.md#get-ltp-last-traded-price-market-quotes-for-multiple-instruments-keys)
78 changes: 78 additions & 0 deletions examples/market-quote/code/full-market-quotes-v3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
## Get full market quote

```python
import upstox_client
from upstox_client.rest import ApiException

configuration = upstox_client.Configuration()
configuration.access_token = '{your_access_token}'

apiInstance = upstox_client.MarketQuoteV3Api(upstox_client.ApiClient(configuration))
try:
# For a single instrument
response = apiInstance.get_full_market_quote_v3(instrument_key="NSE_EQ|INE848E01016")
print(response)
except ApiException as e:
print("Exception when calling MarketQuoteV3Api->get_full_market_quote_v3: %s\n" % e)
```

## Get full market quote for multiple instrument keys

```python
import upstox_client
from upstox_client.rest import ApiException

configuration = upstox_client.Configuration()
configuration.access_token = '{your_access_token}'

apiInstance = upstox_client.MarketQuoteV3Api(upstox_client.ApiClient(configuration))
try:
# For multiple instruments (up to 500 in one call)
response = apiInstance.get_full_market_quote_v3(
instrument_key="NSE_EQ|INE848E01016,NSE_EQ|INE669E01016")
print(response)
except ApiException as e:
print("Exception when calling MarketQuoteV3Api->get_full_market_quote_v3: %s\n" % e)
```

## Read fields from the full market quote response

```python
import upstox_client
from upstox_client.rest import ApiException

configuration = upstox_client.Configuration()
configuration.access_token = '{your_access_token}'

apiInstance = upstox_client.MarketQuoteV3Api(upstox_client.ApiClient(configuration))
try:
response = apiInstance.get_full_market_quote_v3(instrument_key="NSE_EQ|INE848E01016")

# response.data is a dict keyed by "<exchange>:<trading_symbol>"
for key, quote in response.data.items():
print(key)
print(" symbol :", quote.symbol)
print(" instrument_token :", quote.instrument_token)
print(" last_price :", quote.last_price)
print(" volume :", quote.volume)
print(" average_price :", quote.average_price)
print(" net_change :", quote.net_change)
print(" prev_close_price :", quote.prev_close_price)
print(" lower_circuit_limit :", quote.lower_circuit_limit)
print(" upper_circuit_limit :", quote.upper_circuit_limit)
print(" year_high / year_low :", quote.year_high, "/", quote.year_low)
print(" oi / previous_oi :", quote.oi, "/", quote.previous_oi)
print(" cas_eligible :", quote.cas_eligible)

# Nested OHLC snapshot
print(" ohlc :", quote.ohlc.open, quote.ohlc.high,
quote.ohlc.low, quote.ohlc.close)

# Nested market depth (top 5 bids and asks)
for level in quote.depth.buy:
print(" bid:", level.price, level.quantity, level.orders)
for level in quote.depth.sell:
print(" ask:", level.price, level.quantity, level.orders)
except ApiException as e:
print("Exception when calling MarketQuoteV3Api->get_full_market_quote_v3: %s\n" % e)
```
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
long_description = (this_directory / "README.md").read_text()

NAME = "upstox-python-sdk"
VERSION = "2.29.0"
VERSION = "2.30.0"
# To install the library, run the following
#
# python setup.py install
Expand Down
140 changes: 140 additions & 0 deletions test/sdk_tests/test_market_quote_v3_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import upstox_client
import data_token
from upstox_client.rest import ApiException

configuration = upstox_client.Configuration()
configuration.access_token = data_token.access_token

api_instance = upstox_client.MarketQuoteV3Api(upstox_client.ApiClient(configuration))

# Full market quotes for a single instrument
try:
api_response = api_instance.get_full_market_quote_v3(instrument_key="NSE_EQ|INE669E01016")
if api_response.status != "success":
print("error in get_full_market_quote_v3 with a single instrument_key")
except ApiException as e:
print("Exception when calling MarketQuoteV3Api->get_full_market_quote_v3 single: %s\n" % e)

# Full market quotes for multiple instruments
try:
api_response = api_instance.get_full_market_quote_v3(
instrument_key="NSE_EQ|INE669E01016,NSE_INDEX|Nifty 50")
if api_response.status != "success":
print("error in get_full_market_quote_v3 with multiple instrument_keys")
except ApiException as e:
print("Exception when calling MarketQuoteV3Api->get_full_market_quote_v3 multiple: %s\n" % e)

# Full market quotes without any filter
try:
api_response = api_instance.get_full_market_quote_v3()
if api_response.status != "success":
print("error in get_full_market_quote_v3 without instrument_key")
except ApiException as e:
print("Exception when calling MarketQuoteV3Api->get_full_market_quote_v3 no filter: %s\n" % e)

# LTP quotes
try:
api_response = api_instance.get_ltp(instrument_key="NSE_EQ|INE669E01016")
if api_response.status != "success":
print("error in get_ltp")
except ApiException as e:
print("Exception when calling MarketQuoteV3Api->get_ltp: %s\n" % e)

# OHLC quotes
try:
api_response = api_instance.get_market_quote_ohlc("I1", instrument_key="NSE_EQ|INE669E01016")
if api_response.status != "success":
print("error in get_market_quote_ohlc")
except ApiException as e:
print("Exception when calling MarketQuoteV3Api->get_market_quote_ohlc: %s\n" % e)

# Option greeks
try:
api_response = api_instance.get_market_quote_option_greek(instrument_key="NSE_FO|38516")
if api_response.status != "success":
print("error in get_market_quote_option_greek")
except ApiException as e:
print("Exception when calling MarketQuoteV3Api->get_market_quote_option_greek: %s\n" % e)

# Model instantiation tests
ohlc = upstox_client.OhlcV3(
open=100.5,
high=110.25,
low=99.75,
close=105.0,
volume=125000,
ts=1788590331000
)
if ohlc.open != 100.5:
print("error: OhlcV3 open field not set correctly")
if ohlc.volume != 125000:
print("error: OhlcV3 volume field not set correctly")

buy_depth = upstox_client.Depth(quantity=50, price=104.95, orders=3)
sell_depth = upstox_client.Depth(quantity=75, price=105.05, orders=4)
depth = upstox_client.DepthMap(buy=[buy_depth], sell=[sell_depth])
if depth.buy[0].quantity != 50:
print("error: DepthMap buy field not set correctly")
if depth.sell[0].price != 105.05:
print("error: DepthMap sell field not set correctly")

symbol = upstox_client.MarketQuoteSymbolV3(
ohlc=ohlc,
depth=depth,
timestamp="2026-09-05T09:15:00+05:30",
instrument_token="NSE_EQ|INE669E01016",
symbol="IDEA",
last_price=105.0,
volume=125000,
average_price=104.5,
oi=8500.0,
net_change=4.5,
total_buy_quantity=12000.0,
total_sell_quantity=11500.0,
lower_circuit_limit=94.5,
upper_circuit_limit=115.5,
last_trade_time="2026-09-05T09:14:59+05:30",
oi_day_high=9100.0,
oi_day_low=8100.0,
prev_close_price=100.5,
year_high=140.0,
year_low=80.0,
previous_oi=8300.0,
indicative_equilibrium_price=105.25,
reference_price=100.5,
indicative_equilibrium_quantity=4500,
indicative_imbalance_quantity_total=1200,
indicative_imbalance_quantity_market=300,
cas_eligible=True
)
if symbol.symbol != "IDEA":
print("error: MarketQuoteSymbolV3 symbol field not set correctly")
if symbol.last_price != 105.0:
print("error: MarketQuoteSymbolV3 last_price field not set correctly")
if symbol.volume != 125000:
print("error: MarketQuoteSymbolV3 volume field not set correctly")
if symbol.cas_eligible is not True:
print("error: MarketQuoteSymbolV3 cas_eligible field not set correctly")
if symbol.indicative_equilibrium_quantity != 4500:
print("error: MarketQuoteSymbolV3 indicative_equilibrium_quantity field not set correctly")
if symbol.ohlc.close != 105.0:
print("error: MarketQuoteSymbolV3 nested ohlc field not set correctly")
if symbol.depth.buy[0].orders != 3:
print("error: MarketQuoteSymbolV3 nested depth field not set correctly")

full_quote_response = upstox_client.GetFullMarketQuoteResponseV3(
status="success",
data={"NSE_EQ:IDEA": symbol}
)
if full_quote_response.status != "success":
print("error: GetFullMarketQuoteResponseV3 status field not set correctly")
if full_quote_response.data["NSE_EQ:IDEA"].symbol != "IDEA":
print("error: GetFullMarketQuoteResponseV3 data field not set correctly")
if full_quote_response.to_dict()["data"]["NSE_EQ:IDEA"]["last_price"] != 105.0:
print("error: GetFullMarketQuoteResponseV3 to_dict did not serialise nested data")

try:
upstox_client.GetFullMarketQuoteResponseV3(status="not_a_valid_status")
print("error: GetFullMarketQuoteResponseV3 accepted an invalid status value")
except ValueError:
pass
2 changes: 2 additions & 0 deletions upstox_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
from upstox_client.models.get_expired_futures_contract_response import GetExpiredFuturesContractResponse
from upstox_client.models.get_expiries import GetExpiriesResponse
from upstox_client.models.get_full_market_quote_response import GetFullMarketQuoteResponse
from upstox_client.models.get_full_market_quote_response_v3 import GetFullMarketQuoteResponseV3
from upstox_client.models.get_gtt_order_response import GetGttOrderResponse
from upstox_client.models.get_historical_candle_response import GetHistoricalCandleResponse
from upstox_client.models.get_holdings_response import GetHoldingsResponse
Expand Down Expand Up @@ -180,6 +181,7 @@
from upstox_client.models.market_quote_symbol import MarketQuoteSymbol
from upstox_client.models.market_quote_symbol_ltp import MarketQuoteSymbolLtp
from upstox_client.models.market_quote_symbol_ltp_v3 import MarketQuoteSymbolLtpV3
from upstox_client.models.market_quote_symbol_v3 import MarketQuoteSymbolV3
from upstox_client.models.market_status_data import MarketStatusData
from upstox_client.models.modify_order_data import ModifyOrderData
from upstox_client.models.modify_order_request import ModifyOrderRequest
Expand Down
Loading
Loading