Unable to fetch candle data


  • Fetch historical data for the latest 25 candles

    def fetch_historical_data(token, interval='ONE_MINUTE', limit=25):
    url = 'https://apiconnect.angelbroking.com/rest/secure/angelbroking/historical/v1/getCandleData'
    end_date = datetime.now(ist).strftime('%Y-%m-%d %H:%M:%S')
    start_date = (datetime.now(ist) - timedelta(minutes=limit * 1)).strftime('%Y-%m-%d %H:%M:%S')

    params = {
        'symbol': f'NFO:{token}',
        'interval': interval,
        'from_date': start_date,
        'to_date': end_date
    }
    headers = {'Authorization': appCreds['ao_appSecret']}
    print("i am here1----------------->")
    try:
        print("i am here2----------------->")
        response = requests.get(url, params=params, headers=headers)
        response.raise_for_status()  # Check if request was successful
        print("Response Status Code:", response.status_code)
        print("Response Content:", response.text)
        data = response.json()
        print("i am here3----------------->")
        return data
    except requests.RequestException as e:
        print(f"RequestException: {e}")
        print(f"Response Content: {response.text}")
        return None
    except ValueError as e:
        print(f"ValueError: {e}")
        print(f"Response Content: {response.text}")
        return None
    

    Getting the following error:
    i am here1----------------->
    i am here2----------------->
    Response Status Code: 200
    Response Content: <html><head><title>Request Rejected</title></head><body>The requested URL was rejected. Please consult with your administrator.<br><br>Your support ID is: 30350829149037984<br><br><a href='javascript:history.back();'>[Go Back]</a></body></html>
    RequestException: Expecting value: line 1 column 1 (char 0)
    Response Content: <html><head><title>Request Rejected</title></head><body>The requested URL was rejected. Please consult with your administrator.<br><br>Your support ID is: 30350829149037984<br><br><a href='javascript:history.back();'>[Go Back]</a></body></html>
    WebSocket Connection Open !!!

    Error encountered: Connection closed
    [W 240723 14:29:45 smartWebSocketV2:343] Connection closed due to max retry attempts reached.
    Error encountered: Connection closed
    [W 240723 14:29:45 smartWebSocketV2:343] Connection closed due to max retry attempts reached.
    Error encountered: Connection closed
    [W 240723 14:29:45 smartWebSocketV2:343] Connection closed due to max retry attempts reached.