Navigation

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

    aniket

    @aniket

    0
    Reputation
    5
    Posts
    5
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    aniket Follow

    Best posts made by aniket

    This user hasn't posted anything yet.

    Latest posts made by aniket

    • Error Regarding JSONDecoderError

      Hello Team SmartAPI! For the past few days, I was trying to connect to the smartapi through my algo setup and it is giving me error. Here's the code for reference and Output. Can you please help me with this. I'm working on this after 2 months and I think API might got some changes, updates.

      CODE:

      Download master contract file and create token_df

      url = 'https://margincalculator.angelbroking.com/OpenAPI_File/files/OpenAPIScripMaster.json'
      d = requests.get(url).json()
      token_df = pd.DataFrame.from_dict(d)
      token_df['expiry'] = pd.to_datetime(token_df['expiry']).apply(lambda x: x.date())
      token_df = token_df.astype({'strike': float})

      def getTokenInfo(symbol, exch_seg='NSE', instrumenttype='OPTIDX', strike_price='', pe_ce='CE', expiry_day=None):
      df = token_df
      strike_price = strike_price * 100
      if exch_seg == 'NSE':
      eq_df = df[df['exch_seg'] == 'NSE']
      return eq_df[eq_df['name'] == symbol]
      elif exch_seg == 'NFO' and (instrumenttype in ['FUTSTK', 'FUTIDX']):
      return df[(df['exch_seg'] == 'NFO') & (df['instrumenttype'] == instrumenttype) & (df['name'] == symbol)].sort_values(by=['expiry'])
      elif exch_seg == 'NFO' and (instrumenttype in ['OPTSTK', 'OPTIDX']):
      filtered_df = df[(df['exch_seg'] == 'NFO') &
      (df['expiry'] == expiry_day) &
      (df['instrumenttype'] == instrumenttype) &
      (df['name'] == symbol) &
      (df['strike'] == strike_price) &
      (df['symbol'].str.endswith(pe_ce))].sort_values(by=['expiry'])
      #print(f"Filtered DF for {symbol} {expiry_day} {strike_price} {pe_ce}:\n", filtered_df)
      return filtered_df

      OUTPUT :

      [I 250303 14:06:26 smartConnect:121] in pool
      [I 250303 14:06:31 3702498481:21] Session created successfully.

      JSONDecodeError Traceback (most recent call last)
      File ~\AppData\Roaming\Python\Python310\site-packages\requests\models.py:971, in Response.json(self, **kwargs)
      970 try:
      --> 971 return complexjson.loads(self.text, **kwargs)
      972 except JSONDecodeError as e:
      973 # Catch JSON-related errors and raise as requests.JSONDecodeError
      974 # This aliases json.JSONDecodeError and simplejson.JSONDecodeError

      File D:\Anaconda\lib\json_init_.py:346, in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
      343 if (cls is None and object_hook is None and
      344 parse_int is None and parse_float is None and
      345 parse_constant is None and object_pairs_hook is None and not kw):
      --> 346 return _default_decoder.decode(s)
      347 if cls is None:

      File D:\Anaconda\lib\json\decoder.py:337, in JSONDecoder.decode(self, s, _w)
      333 """Return the Python representation of s (a str instance
      334 containing a JSON document).
      335
      336 """
      --> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
      338 end = _w(s, end).end()

      File D:\Anaconda\lib\json\decoder.py:353, in JSONDecoder.raw_decode(self, s, idx)
      352 try:
      --> 353 obj, end = self.scan_once(s, idx)
      354 except StopIteration as err:

      JSONDecodeError: Unterminated string starting at: line 1 column 409344 (char 409343)

      During handling of the above exception, another exception occurred:

      JSONDecodeError Traceback (most recent call last)
      Cell In[25], line 27
      25 # Download master contract file and create token_df
      26 url = 'https://margincalculator.angelbroking.com/OpenAPI_File/files/OpenAPIScripMaster.json'
      ---> 27 d = requests.get(url).json()
      28 token_df = pd.DataFrame.from_dict(d)
      29 token_df['expiry'] = pd.to_datetime(token_df['expiry']).apply(lambda x: x.date())

      File ~\AppData\Roaming\Python\Python310\site-packages\requests\models.py:975, in Response.json(self, **kwargs)
      971 return complexjson.loads(self.text, **kwargs)
      972 except JSONDecodeError as e:
      973 # Catch JSON-related errors and raise as requests.JSONDecodeError
      974 # This aliases json.JSONDecodeError and simplejson.JSONDecodeError
      --> 975 raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)

      JSONDecodeError: Unterminated string starting at: line 1 column 409344 (char 409343)

      posted in Python SDK
      A
      aniket
    • RE: Exit position using SmartAPI?

      @usrikanth hello there! Thank you for your help and code you provided. I've been looking for it since 8 months now and each time it failed. I'll try with this code you provided and tell you further. Thanks again.

      posted in Python SDK
      A
      aniket
    • RE: Exit position using SmartAPI?

      @Moderator_3 hello again! i have tried replacing order type from buy to sell but it is directly selling instead of exiting position. If you can provide little code snippet about exit position or selling it in right way, it would be helpful. Thanks again. Waiting for your response.

      posted in Python SDK
      A
      aniket
    • Exit position using SmartAPI?

      Hello Team SmartAPI! I've been working on this algo from last 5-6 months and I came across this issue regarding the exiting position/s in SmartAPI. Is there any way to exit the open position through code? I have gone through docs and they didn't mentioned it. Also I have checked some of previous discussions regarding this issues, so is there any update on that? Please let me know is there any way to do this. Thank you.

      posted in Python SDK
      A
      aniket
    • Option Chain Live Data

      Hello team smartapi! I want to fetch live option chain data of banknifty and other indices and i don't know how to do it with smart api. Can you please help me with this and also about placing an order through api in options. Thank you.

      posted in General Discussion
      A
      aniket