Navigation

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

    Not receiving LTP data

    General Discussion
    0
    2
    11
    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.
    • N
      Nitin_06 last edited by

      Getting below error while connecting the websocket 2.0

      on open
      Attempting to resubscribe/reconnect...
      In on pong function==> b'\x00'
      In on pong function==> b'\x00'
      In on pong function==> b'\x00'

      Please help me fix the issue

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

        Hi @Nitin_06,

        Apologies for the delayed response.

        Please try using the below code in market hours and let us know if you face the same issue.

        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()
        

        Please write to us at smartapi@angelbroking.com if you still face the issue.

        Thank you.

        Regards
        SmartAPI Team

        1 Reply Last reply Reply Quote 0
        • First post
          Last post