Websocket: Market Data

I tried using websocket for market Data sttreaming.
I get connected and get a response

´¦éÜð2"Ž

aNSE_COM


NCD_FO


NSE_FO


BSE_EQ


BCD_FO


BSE_FO


NSE_EQ


MCX_FO

	MCX_INDEX

	NSE_INDEX

	BSE_INDEX

I sent the body as

{
  "guid": "0e955a7b-0598-4a55-a2f4-6164250e1102",
  "method": "sub",
  "data": {
    "instrumentKeys": ["NSE_INDEX|Nifty Bank"]
  }
}

But i dont get any response.

How to proceed on this. I used postman for testing

cc @Anand_Sajankar @Upstox

@SUMIT_43862558 Please make sure the WebSocket request message should be sent in binary format, not as a text/json message.

Refer to the sample websocket implementation here

I am able to connect the WS and it returns

Received market_info tick: %Com.Upstox.Marketdatafeederv3udapi.Rpc.Proto.MarketInfo{segmentStatus: %{"BCD_FO" => :NORMAL_CLOSE, "BSE_EQ" => :CLOSING_END, "BSE_FO" => :NORMAL_CLOSE, "BSE_INDEX" => :CLOSING_END, "MCX_FO" => :NORMAL_OPEN, "MCX_INDEX" => :NORMAL_OPEN, "NCD_FO" => :NORMAL_CLOSE, "NSE_COM" => :NORMAL_OPEN, "NSE_EQ" => :CLOSING_END, "NSE_FO" => :NORMAL_CLOSE, "NSE_INDEX" => :CLOSING_END}, __unknown_fields__: []}

Now after this i subscribe to

      {guid: "2bd60160-3037-48df-b9b5-9fdaae40d8dc", 
method: "sub", 
data: %{mode: "ltpc", instrumentKeys: ["MCX_FO|438425", "MCX_FO|426468"]}} 

Binary Representation sent is

<<10, 36, 50, 98, 100, 54, 48, 49, 54, 48, 45, 51, 48, 51, 55, 45, 52, 56, 100, 102, 45, 98, 57, 98, 53, 45, 57, 102, 100, 97, 97, 101, 52, 48, 100, 56, 100, 99, 18, 3, 115, 117, 98, 26, 36, 10, 4, 108, 116, 100, 99, 18, 13, 77, 67, 88, 95, 70, 79, 124, 52, 51, 56, 52, 50, 53, 18, 13, 77, 67, 88, 95, 70, 79, 124, 52, 50, 54, 52, 54, 56>>

which is converted to binary by FeedRequest.encode(msg) & than sent.
Says okay but not receiving any updates or further response.

@Anand_Sajankar

Is there a way i can debugg why i dont receive the response ?

Would like to understand if i get first ticker that means i am connected.
And for subcription body is binary after that i am not receivin nay events

Checking this, @SUMIT_43862558. Will get back to you with an update soon, thanks.

Thank you.

Incase you need below is the latest URL I used
“wss://wsfeeder-api.upstox.com/market-data-feeder/v3/upstox-developer-api/feeds?requestId=db809277-ac06-46b9-b2d6-d18b97d61a52&code=g4irK-1bfd1fd5-0bbc-4a54-97b0-51798fe5b592”

@SUMIT_43862558 Did you try as mentioned in the websocket_client.py ?

For eg.

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

        # Convert data to binary and send over WebSocket
        binary_data = json.dumps(data).encode('utf-8')
        await websocket.send(binary_data)

If still getting same issue, please do share your code. Thanks

Okay I see the issue. I was sending the Proto struct. But its required t send plain map / dict.
Thanks

I have one more question:

{"segment":"NSE_EQ","name":"TATA STEEL LIMITED","exchange":"NSE","isin":"INE081A01020","instrument_type":"EQ","instrument_key":"NSE_EQ|INE081A01020","lot_size":1,"freeze_quantity":100000.0,"exchange_token":"3499","tick_size":1.0,"trading_symbol":"TATASTEEL","short_name":"Tata Steel","qty_multiplier":1.0,"security_type":"NORMAL"}

I get above from the NSE.json and want to subscribe to the TATASTEEL for market data.
So i need to subscribe to “NSE_EQ|INE081A01020”.
I wanted to check if this identifier can change in future?
If yes, how do we know or when it usually change?

Cannot we subscribe using exchnage_token which is constant i believe?
@Anand_Sajankar