Navigation

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

    Ekraj

    @Ekraj

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

    Ekraj Unfollow Follow

    Latest posts made by Ekraj

    • SmartWebSocketV2 reconnect only returns one ticker data after disconnect — all other tickers stop updating

      Hi all,

      I’m using SmartAPI’s SmartWebSocketV2 to stream multiple NSE tickers and generate live signals using Order Book Imbalance (OBI) and Volume Imbalance.

      Problem:

      Initially, the WebSocket streams all tickers correctly.

      After some time, I see repeated disconnects and reconnects:
      example :

      AXISBANK — Buy (Score: 0.606, Spread: 10.0, Mid: 106605.0)
      📈 DIVISLAB — Sell (Score: -0.9288, Spread: 50.0, Mid: 610025.0)
      📈 ADANIENT — Sell (Score: -0.923, Spread: 30.0, Mid: 227935.0)
      📈 LT — Sell (Score: -0.7807, Spread: 10.0, Mid: 369395.0)
      📈 HINDALCO — Hold (Score: -0.0862, Spread: 35.0, Mid: 70022.5)
      📈 ADANIPORTS — Buy (Score: 0.4086, Spread: 10.0, Mid: 131865.0)
      📈 JSWSTEEL — Hold (Score: -0.1565, Spread: 30.0, Mid: 105385.0)

      [W 250813 15:26:19 smartWebSocketV2:318] Attempting to resubscribe/reconnect (Attempt 1)...

      🔌 WebSocket Connected
      📈 BAJAJFINSV — Hold (Score: 0.054, Spread: 20.0, Mid: 191420.0)
      [W 250813 15:26:25 smartWebSocketV2:318]
      Attempting to
      resubscribe/reconnect (Attempt 2)...
      🔌 WebSocket Connected
      📈 BAJAJFINSV — Sell (Score: -0.4743, Spread: 20.0, Mid: 191420.0).

      current subscription logic:

      self.ws = SmartWebSocketV2(jwt_token, API_KEY, CLIENT_CODE, feed_token)
      self.ws.on_open = self.on_open
      self.ws.on_data = self.on_data
      self.ws.on_error = self.on_error

      def on_open(self, ws):
      print("✅ WebSocket connected")
      self.ws.subscribe("stream_1", 3, [{"exchangeType": 1, "tokens": tokens}])

      i tried everything but it dosent fixed.
      is there anything im missing or bug im not abel to catch.

      posted in General Discussion
      E
      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 Test
      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 Test
      E
      Ekraj
    • I'm getting error while fetching historical data.

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

      posted in Test
      E
      Ekraj