Navigation

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

    Not able to get ticks from WebSocket using both Postman and .Net SDK

    Test
    0
    4
    17
    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.
    • D
      dlmandalia last edited by

      I have 2 queries. First is the generic issue i have been facing while connecting to websocket for live feeds. I have using the web socket url from the API docs. in Postman along with all required headers. And i am also able to connect to that socket but when i am sending the
      Json request as per the docs. i.e.

      {
      "correlationID": "abcde12345",
      "action": 1,
      "params": {
      "mode": 1,
      "tokenList": [
      {
      "exchangeType": 1,
      "tokens": [
      "10626",
      "5290"
      ]
      },
      {
      "exchangeType": 5,
      "tokens": [
      "234230",
      "234235",
      "234219"
      ]
      }
      ]
      }
      }

      I don't receive any ticks only receive binary data only 2 times that are almost blank. Kindly request you to please let me know where exactly i am wrong in the process of doing this.

      My 2nd issue is with the .Net SDK, this outdated SDK is using totally different approach of subscribing to tokens and different socket url. here also i am facing the same issue and also there is no documentation to it. Please help me with this also.

      Thanks!!

      M 1 Reply Last reply Reply Quote 0
      • M
        Moderator_2 @dlmandalia last edited by

        hi @dlmandalia

        Apologies for delayed response.
        Currently we are only supporting for Node JS, Java, Python SDKs. Websocket is working fine from our end, Kindly reverify the api with listed SDKs and let us know if the issue still occurs.

        Thanks & Regards,
        SmartAPI team

        1 Reply Last reply Reply Quote 0
        • D
          dlmandalia last edited by

          Okay then we will build our own SDK for that, all i want is to know how to subscribe to tokens. I am able to connect to websocket as per the urls and headers provided in API documents. Could you please share a sample/example of what exactly to be sent over a websocket to get subscribed to any token. Just a syntax with real data which i can copy and paste and send it to websocket and then start receiving the data over it that would be really appreciated. Thanks!

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

            Hello @dlmandalia,
            Here is an example of python code to be used for using Websocket Streaming 2.0:

            AUTH_TOKEN = "token"
            API_KEY = "key"
            CLIENT_CODE = "code"
            FEED_TOKEN = "feed_token"
            correlation_id = "abc123"
            action = 1
            mode = 3
            token_list = [{"exchangeType": "1", "tokens": ["438"]}, {"exchangeType": "1", "tokens": ["13528"]}, {"exchangeType": "1", "tokens": ["18365"]}, {"exchangeType": "1", "tokens": ["5701"]}, {"exchangeType": "1", "tokens": ["2142"]}, {"exchangeType": "1", "tokens": ["881"]}, {"exchangeType": "1", "tokens": ["29135"]}, {"exchangeType": "1", "tokens": ["21770"]}, {"exchangeType": "1", "tokens": ["11957"]}, {"exchangeType": "1", "tokens": ["3351"]}, {"exchangeType": "1", "tokens": ["11532"]}, {"exchangeType": "1", "tokens": ["1964"]}, {"exchangeType": "1", "tokens": ["3432"]}, {"exchangeType": "1", "tokens": ["21808"]}, {"exchangeType": "1", "tokens": ["404"]}, {"exchangeType": "1", "tokens": ["20374"]}, {"exchangeType": "1", "tokens": ["10738"]}, {"exchangeType": "1", "tokens": ["24948"]}, {"exchangeType": "1", "tokens": ["4306"]}, {"exchangeType": "1", "tokens": ["685"]}, {"exchangeType": "1", "tokens": ["1174"]}, {"exchangeType": "1", "tokens": ["2412"]}, {"exchangeType": "1", "tokens": ["10447"]}, {"exchangeType": "1", "tokens": ["14299"]}, {"exchangeType": "1", "tokens": ["17094"]},]
            
             
            #retry_strategy=0 for simple retry mechanism
            sws = SmartWebSocketV2(AUTH_TOKEN, API_KEY, CLIENT_CODE, FEED_TOKEN)
            
            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()
            

            Hope this helps to resolve your query.

            Regards
            SmartAPI Team

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