Navigation

    SmartAPI Forum
    • Register
    • Login
    • Search
    • Categories
    • Popular
    • Groups
    • FAQs
    • API Docs
    1. Home
    2. Ekraj
    E
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    Ekraj

    @Ekraj

    0
    Reputation
    3
    Posts
    1
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    Ekraj Follow

    Best posts made by Ekraj

    This user hasn't posted anything yet.

    Latest posts made by Ekraj

    • RE: I'm getting error while fetching historical data.

      @admin Here is snip of my code "from SmartApi import SmartConnect
      import os
      import urllib
      import json
      import pandas as pd
      import datetime as dt
      from pyotp import TOTP

      key_path = r"C:\Users\Ekraj\OneDrive\SmartApi"
      os.chdir(key_path)

      key_secret = open("key.txt","r").read().split()

      obj=SmartConnect(api_key=key_secret[0])
      data = obj.generateSession(key_secret[2],key_secret[3],TOTP(key_secret[4]).now())

      instrument_url = "https://margincalculator.angelbroking.com/OpenAPI_File/files/OpenAPIScripMaster.json"
      response = urllib.request.urlopen(instrument_url)
      instrument_list = json.loads(response.read())

      def token_lookup(ticker, instrument_list, exchange="NSE"):
      for instrument in instrument_list:
      if instrument["name"] == ticker and instrument["exch_seg"] == exchange and instrument["symbol"].split('-')[-1] == "EQ":
      return instrument["token"]

      def symbol_lookup(token, instrument_list, exchange="NSE"):
      for instrument in instrument_list:
      if instrument["token"] == token and instrument["exch_seg"] == exchange and instrument["symbol"].split('-')[-1] == "EQ":
      return instrument["name"]

      def hist_data(ticker,duration,interval,instrument_list,exchange="NSE"):
      params = {
      "exchange": exchange,
      "symboltoken": token_lookup(ticker,instrument_list),
      "interval": interval,
      "fromdate": (dt.date.today() - dt.timedelta(duration)).strftime('%Y-%m-%d %H:%M'),
      "todate": dt.date.today().strftime('%Y-%m-%d %H:%M')
      }
      hist_data = obj.getCandleData(params)
      df_data = pd.DataFrame(hist_data["data"],
      columns = ["date","open","high","low","close","volume"])
      df_data.set_index("date",inplace=True)
      df_data.index = pd.to_datetime(df_data.index)
      df_data.index = df_data.index.tz_localize(None)
      return df_data

      hdfc_data = hist_data("HDFC", 120, "ONE_HOUR", instrument_list)

      Error

      Screenshot 2024-12-20 112112.png

      I need an solution plz tell if there any bug on my code or is there any issue with API

      posted in Bugs
      E
      Ekraj
    • RE: I'm getting error while fetching historical data.

      @admin I tried but still not working i'm getting same error.

      [E 241220 10:16:15 smartConnect:243] Error occurred while making a POST request to https://apiconnect.angelbroking.com/rest/secure/angelbroking/historical/v1/getCandleData. Error: Something Went Wrong, Please Try After Sometime. URL: https://apiconnect.angelbroking.com/rest/secure/angelbroking/historical/v1/getCandleData, Headers: {'Content-type': 'application/json', 'X-ClientLocalIP': '127.0.0.1', 'X-ClientPublicIP': '106.193.147.98', 'X-MACAddress': 'a4:42:3b:fe:86:9c', 'Accept': 'application/json', 'X-PrivateKey': 'xv5pzSlS', 'X-UserType': 'USER', 'X-SourceID': 'WEB'}, Request: {'exchange': 'NSE', 'interval': 'ONE_HOUR', 'fromdate': '2024-08-22 00:00', 'todate': '2024-12-20 00:00'}, Response: {'message': 'Something Went Wrong, Please Try After Sometime', 'errorcode': 'AB1004', 'status': False, 'data': None}

      posted in Bugs
      E
      Ekraj
    • I'm getting error while fetching historical data.

      [E 241216 10:28:43 smartConnect:243]

      posted in Bugs
      E
      Ekraj