Navigation

    SmartAPI Forum
    • Register
    • Login
    • Search
    • Categories
    • Popular
    • Groups
    • FAQs
    • API Docs

    Not getting ticks

    Python SDK
    0
    4
    28
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      Bhanu last edited by

      Hi @admin
      when i tried to use websocketv2
      i am getting tick and after that i am getting b'\x00'

      below is the output

      on open
      Ticks: {'subscription_mode': 3, 'exchange_type': 1, 'token': '26009', 'sequence_number': 15648232, 'exchange_timestamp': 1698230200000, 'last_traded_price': 4283200, 'subscription_mode_val': 'SNAP_QUOTE', 'last_traded_quantity': 0, 'average_traded_price': 0, 'volume_trade_for_the_day': 0, 'total_buy_quantity': 0.0, 'total_sell_quantity': 0.0, 'open_price_of_the_day': 0, 'high_price_of_the_day': 0, 'low_price_of_the_day': 0, 'closed_price': 4315120, 'last_traded_timestamp': 0, 'open_interest': 21203640, 'open_interest_change_percentage': 4633259491834387275, 'upper_circuit_limit': 0, 'lower_circuit_limit': 0, '52_week_high_price': 0, '52_week_low_price': 0, 'best_5_buy_data': [{'flag': 1, 'quantity': 0, 'price': 0, 'no of orders': 0}, {'flag': 1, 'quantity': 0, 'price': 0, 'no of orders': 0}, {'flag': 1, 'quantity': 0, 'price': 0, 'no of orders': 0}, {'flag': 1, 'quantity': 0, 'price': 0, 'no of orders': 0}, {'flag': 1, 'quantity': 0, 'price': 0, 'no of orders': 0}], 'best_5_sell_data': [{'flag': 0, 'quantity': 0, 'price': 0, 'no of orders': 0}, {'flag': 0, 'quantity': 0, 'price': 0, 'no of orders': 0}, {'flag': 0, 'quantity': 0, 'price': 0, 'no of orders': 0}, {'flag': 0, 'quantity': 0, 'price': 0, 'no of orders': 0}, {'flag': 0, 'quantity': 0, 'price': 0, 'no of orders': 0}]}
      Ticks: b'\x00'
      Ticks: b'\x00'
      Ticks: b'\x00'
      Ticks: b'\x00'
      Ticks: b'\x00'
      Ticks: b'\x00'
      Ticks: b'\x00'
      Ticks: b'\x00'
      Ticks: b'\x00'
      Ticks: b'\x00'
      Ticks: b'\x00'

      below is my code

      from SmartApi import SmartConnect
      from SmartApi.smartWebSocketV2 import SmartWebSocketV2
      feed_token = obj.getfeedToken()

      sws = SmartWebSocketV2(data["data"]["jwtToken"], key_secret[0], key_secret[2], feed_token)

      correlation_id = "stream_1" #any string value which will help identify the specific streaming in case of concurrent streaming
      action = 1 #1 subscribe, 0 unsubscribe
      mode = 3 #1 for LTP, 2 for Quote and 2 for SnapQuote

      token_list = [{"exchangeType": 1, "tokens": ["26009"]}]

      def on_data(wsapp, message):
      print("Ticks: {}".format(message))

      def on_open(wsapp):
      print("on open")
      sws.subscribe(correlation_id, mode, token_list)

      def on_error(wsapp, error):
      print(error)

      Assign the callbacks.

      sws.on_open = on_open
      sws.on_data = on_data
      sws.on_error = on_error

      sws.connect()

      can you please tell me what is the issue

      M A 2 Replies Last reply Reply Quote 0
      • A
        anontrader @Bhanu last edited by

        @admin @rajanprabu anyone?

        1 Reply Last reply Reply Quote 0
        • M
          Moderator_1 last edited by

          Hello @Bhanu ,

          Apologies for the delayed response.
          Thanks for raising this issue. I have raised this issue to tech team and will get back to you once I get a resolution from them. If you have any other issue, please share request and response on smartapi@angelbroking.com.

          Regards
          SmartAPI Team

          1 Reply Last reply Reply Quote 0
          • M
            Moderator_1 @Bhanu last edited by

            Hello @Bhanu
            Also the token code for Nifty and Bank Nifty has changed in the scrip master. Please use the new values.
            Please try using this code during market hours

            from SmartApi.smartWebSocketV2 import SmartWebSocketV2
            from logzero import logger
            
            AUTH_TOKEN = "auth_token"
            API_KEY = "api_key_here"
            CLIENT_CODE = "client_code"
            FEED_TOKEN = "feed_token"
            correlation_id = "abc123"// any string value
            action = 1
            mode = 3
            token_list = [
                {
                    "exchangeType": 1,
                    "tokens": ["26009"]
                }
            ]
            #retry_strategy=0 for simple retry mechanism
            sws = SmartWebSocketV2(AUTH_TOKEN, API_KEY, CLIENT_CODE, FEED_TOKEN)
            
            #retry_strategy=1 for exponential retry mechanism
            # sws = SmartWebSocketV2(AUTH_TOKEN, API_KEY, CLIENT_CODE, FEED_TOKEN,max_retry_attempt=3, retry_strategy=1, retry_delay=10,retry_multiplier=2, retry_duration=30)
            
            def on_data(wsapp, message):
                logger.info("Ticks: {}".format(message))
                # close_connection()
            
            def on_control_message(wsapp, message):
                logger.info(f"Control Message: {message}")
            
            def on_open(wsapp):
                logger.info("on open")
                some_error_condition = False
                if some_error_condition:
                    error_message = "Simulated error"
                    if hasattr(wsapp, 'on_error'):
                        wsapp.on_error("Custom Error Type", error_message)
                else:
                    sws.subscribe(correlation_id, mode, token_list)
                    # sws.unsubscribe(correlation_id, mode, token_list1)
            
            def on_error(wsapp, error):
                logger.error(error)
            
            def on_close(wsapp):
                logger.info("Close")
            
            def close_connection():
                sws.close_connection()
            
            
            # Assign the callbacks.
            sws.on_open = on_open
            sws.on_data = on_data
            sws.on_error = on_error
            sws.on_close = on_close
            sws.on_control_message = on_control_message
            
            sws.connect()
            
            1 Reply Last reply Reply Quote 0
            • First post
              Last post