Navigation

    SmartAPI Forum
    • Register
    • Login
    • Search
    • Categories
    • Popular
    • Groups
    • FAQs
    • API Docs

    SmartConnect getOIData returning blank

    Python SDK
    0
    3
    16
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      S63128103 last edited by

      def historicaldata():
      try:
      historicParam={
      "exchange" : "NFO",
      "symboltoken" : "101931",
      "interval" : "THREE_MINUTE",
      "fromdate" : "2024-12-30 09:20",
      "todate" : "2024-12-30 09:21",
      }

          return smartApi.getOIData(historicParam)
      
      except Exception as e:
          print(e.message)
      

      historical_data = historicaldata()
      print(historical_data)

      i am trying to fetch historical oi data by passing above params to getOIData funciton but it just returns blank output.

      Output ->

      {
      "status": true,
      "message": "SUCCESS",
      "errorcode": "",
      "data": []
      }

      B 1 Reply Last reply Reply Quote 0
      • A
        admin last edited by

        @S63128103 it is returning blank because no trades have happened in the contract at the time of writing this response. You can check the same on the Angel One's chart.

        1 Reply Last reply Reply Quote 0
        • B
          bronez @S63128103 last edited by

          The issue likely lies with the parameters or the availability of the data you're requesting. Here's how you can debug and troubleshoot this problem:

          Possible Causes and Fixes
          Invalid or Insufficient Data for the Time Range:

          The time range "fromdate": "2024-12-30 09:20" to "todate": "2024-12-30 09:21" is only one minute. Check if the data exists for this exact time frame.
          Extend the time range to ensure data is available, for example:
          json
          Copy code
          "fromdate": "2024-12-30 09:20",
          "todate": "2024-12-30 09:30"
          Incorrect Interval:

          Ensure the "interval": "THREE_MINUTE" parameter is supported by the API for the specified data type (Open Interest). Try a commonly supported interval like "ONE_MINUTE" or "FIVE_MINUTE" to see if it resolves the issue.
          Invalid Symbol Token:

          Confirm that "symboltoken": "101931" corresponds to a valid and active symbol in the "exchange": "NFO". An invalid or inactive symbol will return no data.
          Verify this by querying metadata or using another API method to confirm the symbol’s validity.
          API Permissions or Limitations:

          Ensure your API credentials have permissions to access Open Interest (OI) data. Some API keys might have limited access.
          Check for API-specific documentation or limitations on fetching historical OI data.
          Improper Data Formatting:

          Double-check that fromdate and todate are formatted exactly as required by the API (e.g., "YYYY-MM-DD HH:MM:SS"). Small formatting errors may lead to no results.
          API-Side Issue:

          If all parameters seem correct, the issue might be on the API provider's side. Contact their support team or check their system status to ensure the endpoint is functioning correctly.
          Debugging Steps
          Log the Full API Request: Print the exact parameters being sent to getOIData to confirm everything is as expected.
          Expand the Data Range: Use a broader date range to verify if any data exists.
          Use a Known Valid Token: Test with a symbol token and interval combination you know works to ensure the API is functional.
          Test Different Data Types: If the API supports other types of data (e.g., historical price), test those to isolate the issue.
          Example Code with Extended Debugging
          python
          Copy code
          def historicaldata():
          try:
          historicParam = {
          "exchange": "NFO",
          "symboltoken": "101931",
          "interval": "FIVE_MINUTE",
          "fromdate": "2024-12-30 09:20",
          "todate": "2024-12-30 09:30",
          }
          print("Request Parameters:", historicParam) # Debugging
          return smartApi.getOIData(historicParam)
          except Exception as e:
          print("Error:", str(e)) # Catch full error details

          historical_data = historicaldata()
          print("Historical Data:", historical_data)
          If the issue persists despite these checks, you should reach out to the API provider with the exact request and response for further assistance.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post