Anyone could able to connect and recieve data from websocket through API and without upstox sdk?

Iam trying to connect to the websocket with given documentation i could able to connect with a 101 status in Postman, Flutter and Deno edge function and also getting pong when sending a ping but not recieving market feed or portfolio updates. i think the documentation to connect websocket is incomplete ,I feel there is some missing parameters which affects proper functioning of websocket, if API works with SDK and not with direct connection there is a lack of information in the API doc which SDK uses to connect and recieve messages from Upstox, Team please take appropriate action to rectify that,awaiting for a quick response from the Team.

@Vigneshwaran

Could you provide more details about how you are establishing the connection? Please share information on the APIs being called and the cURL object used.

Thanks!

@shanmu

iam making a http call to

https://api.upstox.com/v2/feed/market-data-feed/authorize

with headers

'Authorization': 'Bearer $accessToken',
`Accept`: 'application/json'

and getting the response

{
 "status": "success",
 "data": {
   "authorized_redirect_uri": "wss://url?requestId=someId&code=someCode",
   "authorizedRedirectUri": "wss://url?requestId=someId&code=someCode"
 }
}

iam using this wss url on my websocket client and getting connected with a 101 status after that could able to send the subscription message but server not sending any message back.

{
  "guid": "someguid",
  "method": "sub",
  "data": {
    "mode": "full",
    "instrumentKeys": ["NSE_INDEX|Nifty Bank"]
  }
}

if i send a ping iam getting a pong. Should I add any header while connecting to my websocket , can you please check this scenario in postman? iam getting the same response in Postman, Flutter, and Deno Edge Function using Hono.

@Vigneshwaran

Send the subscription messages in binary format. Use Binary->Base64 when testing via Postman.

Thanks!

1 Like

@shanmu
Thanks for such a valuble response. now i could able to get a response from the websocket. May i know which version of .proto file should be used ? and also which class to use from my generated MarketDataFeed.pb.dart file to decode since iam getting error when i use

LTPC.fromBuffer(data)

error is

I/flutter (19944): Received WebSocket message: [8, 1, 18, 52, 10, 19, 78, 83, 69, 95, 69, 81, 124, 73, 78, 69, 48, 48, 50, 65, 48, 49, 48, 49, 56, 18, 29, 10, 27, 9, 51, 51, 51, 51, 51, 16, 148, 64, 16, 219, 195, 181, 138, 183, 50, 24, 1, 33, 205, 204, 204, 204, 204, 52, 148, 64, 24, 145, 197, 181, 138, 183, 50]
I/flutter (19944): Error decoding WebSocket message: InvalidProtocolBufferException: Protocol message end-group tag did not match expected tag.
I/flutter (31355): Received WebSocket message: [18, 52, 10, 19, 78, 83, 69, 95, 69, 81, 124, 73, 78, 69, 48, 48, 50, 65, 48, 49, 48, 49, 56, 18, 29, 10, 27, 9, 154, 153, 153, 153, 153, 22, 148, 64, 16, 189, 228, 247, 139, 183, 50, 24, 2, 33, 205, 204, 204, 204, 204, 52, 148, 64, 18, 52, 10, 19, 78, 83, 69, 95, 69, 81, 124, 73, 78, 69, 48, 57, 50, 65, 48, 49, 48, 49, 57, 18, 29, 10, 27, 9, 205, 204, 204, 204, 204, 96, 145, 64, 16, 246, 143, 247, 139, 183, 50, 24, 2, 33, 154, 153, 153, 153, 153, 76, 145, 64, 24, 185, 230, 247, 139, 183, 50]
I/flutter (31355): Error decoding WebSocket message: InvalidProtocolBufferException: While parsing a protocol message, the input ended unexpectedly
I/flutter (31355): in the middle of a field. This could either mean that the input
I/flutter (31355): has been truncated or that an embedded message misreported its
I/flutter (31355): own length.

for ltpc mode, and also iam not getting response for Portfolio Feed , should i send a message after connecting successfully with status 101?

https://api.upstox.com/v2/feed/portfolio-stream-feed/authorize?update_types=order%2Cposition%2Cholding

@shanmu

Thanks for your kind help and your valuble time , now i could able to decode the response for MarketDataFeed with this code

FeedResponse? decodeFeedResponse(Uint8List buffer) {
      try {
        // Decode buffer to FeedResponse
        final feedResponse = FeedResponse.fromBuffer(buffer);
        return feedResponse;
      } catch (e) {
        print('Error decoding buffer to FeedResponse: $e');
        return null;
      }
    }

    void handleFeedResponse(Uint8List buffer) {
      final feedResponse = decodeFeedResponse(buffer);

      if (feedResponse != null) {
        print('Decoded FeedResponse: $feedResponse');

        // Access the current timestamp
        print('Current Timestamp: ${feedResponse.currentTs}');

        // Iterate over the feeds map
        feedResponse.feeds.forEach((key, feed) {
          print('Feed Key: $key');

          // Check if the feed has LTPC data
          if (feed.hasLtpc()) {
            final ltpc = feed.ltpc;
            print('LTP: ${ltpc.ltp}');
            print('Last Traded Time: ${ltpc.ltt}');
            print('Last Traded Quantity: ${ltpc.ltq}');
            print('Close Price: ${ltpc.cp}');
          } else {
            print('Feed does not contain LTPC data');
          }
        });
      } else {
        print('Failed to decode FeedResponse');
      }
    }

I need one more help iam not recieving streams for portfolio-stream-feed after sucessful connection with status 101 can you please help on that.

https://api.upstox.com/v2/feed/portfolio-stream-feed/authorize?update_types=order%2Cposition%2Cholding

Thanks