Problem with the websocket

After facing problem with the historical API from a week now.
Today I started facing problem with the websocket where I am receiving very few ticks.
After facing issue for the whole day on my application, I test it on the postman, and I didn’t get even a single tick until the market was closed at 3:30pm I got some data.
Please check the attached image from the postman websocket connection where I am connected to websocket and have send the request for bank nifty index at full mode.
Message I sent after successful connection:
{
“guid”: “13syxu852ztodyqncwt0”,
“method”: “sub”,
“data”: {
“mode”: “full”,
“instrumentKeys”: [“NSE_INDEX|Nifty Bank”]
}
}

@Ketan @Ushnota Please fix this asap I am not able to run my strategies because of this.

Hi @Kautilya, After the successful connection, the subscription data must be sent in binary format. Please refer to the sample WebSocket implementation in python here for guidance.

Thanks

@Anand_Sajankar As you can see from the image, I didn’t received any kind of data no binary data or in any other format.
I have been using the websockets in my application, and I know the data is send in binary format, but today there has been no data after subscription.
Kindly check why did this happen.

Thanks

@Anand_Sajankar facing the same issue today also, No getting any data from websocket.
I have susbcribed with the nifty 50 and bank nifty data, but not receiving any data at all.

Please fix this asap, I am not able to run my strategies.

Thanks

Hi @Kautilya Could you please share your websocket implementation for further investigation?

Hi @Anand_Sajankar I am not even getting data on the postman websocket connection.
I am using this to get the url
curl --location ‘https://api.upstox.com/v3/feed/market-data-feed/authorize
–header ‘Api-Version: 2.0’
–header ‘Accept: application/json’
–header ‘Authorization: XXX’ \

And then simpling connecting to the websocket with response url in the postman itself, but I am not receiving any data at all.

@Kautilya Are you sending binary data in the postman as well ? Try using below python script, it will work

@Anand_Sajankar
I am sending the data in binary only on postman but still no ticks are coming from the websocket.

I am connected successfully with the websocket and even after sending the message in binary format I am not getting any response back from the websocket.

This is my java implementation.
For me websocket is not working either in postman or in my java application.

@Anand_Sajankar Please help me resolve this asap

private WebSocketClient createWebSocketClient(URI serverUri) {
        return new WebSocketClient(serverUri) {
            @Override
            public void onOpen(ServerHandshake handshakeData) {
                log.info("Opened Websocket connection");
                // Send subscription request after opening the connection
                mapOfModeToInstruments.forEach((mode, instrumentKeys) -> {
                    sendSubscriptionRequest(this, instrumentKeys.stream().toList(), mode);
                });
            }
            @Override
            public void onMessage(String message) {

            }
            @Override
            public void onMessage(ByteBuffer bytes) {
                handleBinaryMessage(bytes);
            }
            @Override
            public void onClose(int code, String reason, boolean remote) {
                log.info("Connection closed by {} peer. Info: {}", (remote ? "remote" : "us"), reason);
            }
            @Override
            public void onError(Exception ex) {
                log.error("Error in connecting to message feed websocket", ex);
            }
        };
    }

private void handleBinaryMessage(ByteBuffer bytes) {
        log.info("Received message: {}", deserializeFeedResponse(bytes));
    }

private void sendSubscriptionRequest(WebSocketClient client, List<String> instrumentKeys, Mode mode) {
        JsonObject requestObject = constructSubscriptionRequest(instrumentKeys, mode);
        byte[] binaryData = requestObject.toString()
                .getBytes(StandardCharsets.UTF_8);

        log.info("Sending subscription request: {}", requestObject);
        client.send(binaryData);
    }

same think happen with me bro ,

Here, I am also facing the issue related to web socket. I am successfully connecting with web socket and also receiving market feed as well but not getting further feeds like live feed. Can you please suggest me proper solution for it.

Here is the my code snipt which I have implemented for web socket.

def run(cron_job = true, run_by = "scheduler")
      cron_data = CronData.create(start_at: Time.now, cron_title: "Sockets::UpstoxClient.start_socket_connection", run_by: run_by)

      begin
        EM.run {
          if EM.connection_count < 1
            WebsocketActivity.where(status: "open").update_all(stopped_at: DateTime.now, status: "stopped")
            web_socket_activity = WebsocketActivity.create!(title: "Sockets::UpstoxClient.run", status: "open", start_at: DateTime.now)
            token = "Bearer #{ENV['UPSTOX_ACCESS_TOKEN']}"
            redirect_url = get_redirect_url(token)

            ws = Faye::WebSocket::Client.new(redirect_url,
                   ['json'],
                   headers: {
                     'Authorization' => token,
                     'Accept' => '*/*'
                   }
                 )

            symbol_keys = ['NSE_INDEX|Nifty 50'] #CacheModule.get_all_upstox_instrument_keys
            puts "symbol_keys: #{symbol_keys}"
            ws.on :open do |event|
              puts "✅ Upstox WebSocket Connected"

              subscription_payload = {
                guid: SecureRandom.uuid,
                method: 'sub',
                data: {
                  mode: 'ltpc',
                  instrumentKeys: symbol_keys #['MCX_FO|220230']
                }
              }

              ws.send(subscription_payload.to_json)
            #   EM.add_periodic_timer(30) {
            #     puts "🫀 Heartbeat at #{Time.now}"
            #     # Upstox doesn’t require ping unless explicitly stated
            #   }
              puts "📩 Sent subscription"
            end

            ws.on :message do |event|
              begin
                puts "📡 Received binary data"
                # Decode using protobuf here
                raw = event.data
                binary_data = raw.is_a?(Array) ? raw.pack('C*') : raw
                decoded = Com::Upstox::Marketdatafeederv3udapi::Rpc::Proto::FeedResponse.decode(binary_data)
                puts "Decoded data #{decoded}"
                puts "📥 Raw binary size: #{binary_data.bytesize} bytes"
                puts "📦 Decoded type: #{decoded.type}"
                puts "📊 Instruments in feed: #{decoded.feeds.keys}"
              rescue JSON::ParserError => e
                puts "JSON Parse Error: #{e.message}"
                ActionCable.server.broadcast "messages", { error: "Error parsing message" }
              end
            end

            ws.on :close do |event|
              web_socket_activity.update!(status: "closed", stopped_at: DateTime.now)
              puts "❌ Upstox WebSocket Closed (#{event})"
              ws = nil
              EM.stop
              StockCompanies::UpstoxWebsocketClientStartWorker.perform_at(30.seconds.from_now)
            end

            ws.on :error do |e|
              puts "❌ WebSocket Error: #{e.message}"
            end
          end
        }

        cron_data.update(status: "success", end_at: Time.now)
      rescue => e
        cron_data.update(status: "error", error: e.message, end_at: Time.now)
        puts "⚠️ WebSocket Exception: #{e.message}"
      end
    end

    private

    def get_redirect_url(token)
      url = URI("https://api.upstox.com/v3/feed/market-data-feed/authorize")

      https = Net::HTTP.new(url.host, url.port)
      https.use_ssl = true

      request = Net::HTTP::Get.new(url)
      request["Authorization"] = token
      request["Accept"] = "application/json"
      response = https.request(request)
      JSON.parse(response.read_body)["data"]["authorized_redirect_uri"]
    end