Spaces:
Sleeping
Sleeping
Update utils.py
Browse files
utils.py
CHANGED
|
@@ -12,6 +12,7 @@ class StockDataFetcher:
|
|
| 12 |
self.base_url = "https://groww.in/v1/api/charting_service/v3/chart/exchange/NSE/segment/CASH/"
|
| 13 |
self.base_fno_url = "https://groww.in/v1/api/stocks_fo_data/v3/charting_service/chart/exchange/NSE/segment/FNO/"
|
| 14 |
self.latest_stock_price = "https://groww.in/v1/api/stocks_data/v1/tr_live_prices/exchange/NSE/segment/CASH/"
|
|
|
|
| 15 |
self.latest_option_price = "https://groww.in/v1/api/stocks_fo_data/v1/tr_live_prices/exchange/NSE/segment/FNO/"
|
| 16 |
self.option_chain = "https://groww.in/v1/api/option_chain_service/v1/option_chain/derivatives/"
|
| 17 |
self.search_url = "https://groww.in/v1/api/search/v1/entity"
|
|
@@ -63,12 +64,16 @@ class StockDataFetcher:
|
|
| 63 |
try:
|
| 64 |
if symbol[-2:].upper() == "PE" or symbol[-2:].upper() == "CE" or symbol[-3:].upper() == "FUT":
|
| 65 |
response = requests.get(self.latest_option_price + symbol.upper() + "/latest", headers=self.headers)
|
|
|
|
|
|
|
| 66 |
else:
|
| 67 |
response = requests.get(self.latest_stock_price + symbol.upper() + "/latest", headers=self.headers)
|
| 68 |
if response.status_code == 200:
|
| 69 |
data = response.json()
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
| 72 |
return latest_price
|
| 73 |
else:
|
| 74 |
print(f"Failed to fetch data. Status code: {response.status_code}")
|
|
|
|
| 12 |
self.base_url = "https://groww.in/v1/api/charting_service/v3/chart/exchange/NSE/segment/CASH/"
|
| 13 |
self.base_fno_url = "https://groww.in/v1/api/stocks_fo_data/v3/charting_service/chart/exchange/NSE/segment/FNO/"
|
| 14 |
self.latest_stock_price = "https://groww.in/v1/api/stocks_data/v1/tr_live_prices/exchange/NSE/segment/CASH/"
|
| 15 |
+
self.latest_index_price = "https://groww.in/v1/api/stocks_data/v1/tr_live_indices/exchange/NSE/segment/CASH/"
|
| 16 |
self.latest_option_price = "https://groww.in/v1/api/stocks_fo_data/v1/tr_live_prices/exchange/NSE/segment/FNO/"
|
| 17 |
self.option_chain = "https://groww.in/v1/api/option_chain_service/v1/option_chain/derivatives/"
|
| 18 |
self.search_url = "https://groww.in/v1/api/search/v1/entity"
|
|
|
|
| 64 |
try:
|
| 65 |
if symbol[-2:].upper() == "PE" or symbol[-2:].upper() == "CE" or symbol[-3:].upper() == "FUT":
|
| 66 |
response = requests.get(self.latest_option_price + symbol.upper() + "/latest", headers=self.headers)
|
| 67 |
+
elif symbol.upper() == "NIFTY" or symbol.upper() == "BANKNIFTY":
|
| 68 |
+
response = requests.get(self.latest_index_price + symbol.upper() + "/latest", headers=self.headers)
|
| 69 |
else:
|
| 70 |
response = requests.get(self.latest_stock_price + symbol.upper() + "/latest", headers=self.headers)
|
| 71 |
if response.status_code == 200:
|
| 72 |
data = response.json()
|
| 73 |
+
if 'ltp' in data:
|
| 74 |
+
latest_price = data['ltp']
|
| 75 |
+
else:
|
| 76 |
+
latest_price = data['value']
|
| 77 |
return latest_price
|
| 78 |
else:
|
| 79 |
print(f"Failed to fetch data. Status code: {response.status_code}")
|