Getting error 'SmartConnect' object has no attribute 'getQuote'


  • I am runnning below code
    def get_live_data(api, stock_symbol):
    scrip_token = get_scrip_token(stock_symbol)
    if scrip_token:
    try:
    live_data = api.getQuote(scrip_token) # Ensure this is the correct method name
    return live_data
    except Exception as e:
    logging.error(f"Error fetching stock data for {stock_symbol}: {str(e)}")
    return None

    I am getting below error,
    INFO:root:Processing BAJAJ-AUTO-EQ
    ERROR:root:Error fetching stock data for BAJAJ-AUTO-EQ: 'SmartConnect' object has no attribute 'getQuote'

    Can you please suggest corrections.


  • @Moderator_3 said in Getting error 'SmartConnect' object has no attribute 'getQuote':

    The correct method name is getMarketData(mode,exchangeTokens)

    Thanks for your Help, Now I am getting error message as per below.

    ERROR:root:Error fetching stock data for HDFCLIFE-EQ: Couldn't parse the JSON response received from the server: b''

    Below is the Modified code as per suggestion given by you.

    Function to get live data from Angel One API

    def get_live_data(stock_symbol):
    scrip_token = get_scrip_token(stock_symbol)
    if scrip_token:
    try:
    # Fetch market data using the correct method
    data = smart_connect.getMarketData(mode='LTP', exchangeTokens=[scrip_token])
    if data and 'data' in data and data['data']:
    return data['data'][0] # Assuming the API returns a list of data for the requested tokens
    else:
    logging.error(f"No data returned for {stock_symbol}")
    except Exception as e:
    logging.error(f"Error fetching stock data for {stock_symbol}: {str(e)}")
    else:
    logging.error(f"No scrip token found for {stock_symbol}")
    return None


  • @thatte-kailas

    The correct method name is getMarketData(mode,exchangeTokens)

    Regards,
    SmartAPI Team

1 out of 3