Inquiry Regarding Zero Volume Data in Historical Data API

Zen8_ith
I am currently using the Historical Data API to retrieve 1-minute volume data for DLF, and I am integrating this data into my trading strategy. However, I’ve encountered an issue where, at times, I receive zero volume values for certain intervals. Interestingly, when I access historical data for the same day through another method, the volume values are available as expected.

Could you kindly assist me in understanding why I am receiving zero volume data for some time intervals, despite having non-zero volume data available for the same day via other sources? I have attached a screenshot of the data for your reference.

  • JD11
    Receiving zero volume data for certain intervals when using the Kite Connect Historical Data API can be due to several reasons. Here are some potential causes and suggestions to resolve this issue:

    Potential Causes
    Market Activity:
    During certain intervals, there might be no trades executed for the specific instrument, resulting in zero volume data. This can happen during low liquidity periods.
    Data Synchronization: There might be a delay or synchronization issue between the data source and the API, causing temporary discrepancies in the volume data.

    Suggestions to Resolve the Issue
    Verify Data Source: Ensure that you are using the correct instrument token and exchange while fetching the historical data. Cross-check the instrument token with the Kite Instruments API.
    Check for API Updates: Verify if there are any updates or known issues with the Kite Connect API by checking the Kite Connect Forum or contacting Zerodha support.
    Retry Mechanism: Implement a retry mechanism in your code to fetch the data again if zero volume is encountered. This can help mitigate temporary data synchronization issues.

    def fetch_historical_data_with_retry(kite, instrument_token, from_date, to_date, interval, retries=3):
    for attempt in range(retries):
    data = kite.historical_data(instrument_token, from_date, to_date, interval)
    if all(candle[5] == 0 for candle in data['candles']):
    time.sleep(1) # Wait before retrying
    else:
    return data
    return data # Return the data even if retries are exhausted
    Alternative Data Sources:

    If the issue persists, consider using alternative data sources or APIs to cross-verify the volume data.

    Example Code
    Here's an example of how you might implement a retry mechanism to handle zero volume data:

    from kiteconnect import KiteConnect
    import time

    kite = KiteConnect(api_key="your_api_key")
    kite.set_access_token("your_access_token")

    def fetch_historical_data_with_retry(kite, instrument_token, from_date, to_date, interval, retries=3):
    for attempt in range(retries):
    data = kite.historical_data(instrument_token, from_date, to_date, interval)
    if all(candle[5] == 0 for candle in data['candles']):
    time.sleep(1) # Wait before retrying
    else:
    return data
    return data # Return the data even if retries are exhausted

    # Example usage
    instrument_token = 123456 # Replace with actual instrument token for DLF
    from_date = "2023-12-01"
    to_date = "2023-12-31"
    interval = "minute"

    data = fetch_historical_data_with_retry(kite, instrument_token, from_date, to_date, interval)
    print(data)

    By implementing these suggestions, you should be able to mitigate the issue of receiving zero volume data for certain intervals.
Sign In or Register to comment.