While i am trying to fetch upstocks live market with python script.Can anyhone suggest how to connect upstocks live market
@karthigeya_44296154 Kindly review the following documentation on WebSocket implementation
I tried using the sample data I am not able to connnect.I need live market data for analysis so how can i connect the upstocks with my local python script
@karthigeya_44296154 can you share the python code and the error message for further investigation ?
I connected upstocks using websocket and how do i fetch live data and i want to analysis using live data could you please suggest how to do that.Only for analysis purpose.
@karthigeya_44296154 You can access real-time market data sample code by referring to the links below:
@Anand_Sajankar
Thanks, But i downloaded complete.json file to get instrument key and try to get live data but i cant able to fetch the data
@karthigeya_44296154 Could you please provide more details about the request parameters? Are you encountering any errors?
Hello, i am also getting the same error. the instruments key come as invalid. can you please send a single instrument key for me to check the utility of the code?
import upstox_client
from upstox_client.api.market_quote_api import MarketQuoteApi
import pandas as pd
from datetime import datetime
import json
import time
Load access token
with open(“access_token.json”) as f:
token_data = json.load(f)
access_token = token_data[“access_token”]
Configure Upstox client
config = upstox_client.Configuration()
config.access_token = access_token
api_client = upstox_client.ApiClient(config)
quote_api = MarketQuoteApi(api_client)
Your instrument list (cut short for example)
instruments = [
{“name”: “ABB”, “instrument_key”: “NSE_EQ|INE117A01022”},
{“name”: “AEGISLOG”, “instrument_key”: “NSE_EQ|INE208C01025”},
{“name”: “ARE&M”, “instrument_key”: “NSE_EQ|INE885A01032”},
]
Fetch every 10 seconds
while True:
try:
# Build symbol list
symbol_keys = [stock[“instrument_key”] for stock in instruments]
# Fetch LTP
response = quote_api.ltp(symbol_keys, api_version='v2')
data = []
for stock in instruments:
key = stock["instrument_key"]
name = stock["name"]
ltp_data = response.data.get(key)
if ltp_data:
data.append({
"symbol": name,
"instrument_key": key,
"ltp": ltp_data.ltp,
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
})
# Save to CSV
df = pd.DataFrame(data)
df.to_csv("ltp_snapshot.csv", index=False)
print(f"✅ [{datetime.now()}] Snapshot saved with {len(df)} entries.")
print(df)
except Exception as e:
print("❌ Error fetching LTPs:", str(e))
# ⏱️ Wait 10 seconds
time.sleep(10)