Websocket Packet parsing with Swift 5

I'm using URLSessionWebSocketTask API on iOS app.

After starting a web socket connection, I am subscribing to Nifty and Banknifty tokens, [256265, 260105]

As per the document, I should get 76 bytes (4 + 4 + 32 + 4 + 32) in response...
  1. The first 4 bytes containing number of packets
  2. The next 4 containing length of the first packet
  3. Then the packet data
  4. Then next 4 containing length of the 2nd packet
  5. Then the 2nd packet data.. (and so on)
But the data I'm getting is 62 bytes only.

The first 4 bytes contains '2', which is right
The next 4 bytes contains length of the nifty packet, which it says is 28. But it should be 32...

Also, when I'm parsing nifty packet, I'm rightly getting the instrument token in the first 4 bytes, but each consecutive int32 chunk is null.

Please help.

  • sujith
    A third party app can't show our data. You can email kiteconnect(at)zerodha.com with product details and check with compliance team.
    You may have to get live market data from an exchange registered data vendor.
  • akshansh_96_zerodha
    I am not a third party. I'm using zerodha tokens.. Not sure what you mean by that.
  • sujith
    Kite Connect API is provide for personal use only. It can't be used to display data on third party platforms. It is against the regulations. You can speak to the compliance team for more details.
  • akshansh_96_zerodha
    What do you mean by third party platform?
  • akshansh_96_zerodha
    I'm just building this app for myself. I paid for the APIs.. I'm trying to stream data using web socket. The data is incorrect, and I'm asking about that. There is no third party and no displaying of data anywhere where anyone except for me can see it..
  • sujith
    The data is fine. Only 2 bytes is number of packets. After that the next 2 bytes has length of first tick.
    You can know more here.
  • akshansh_96_zerodha
    Solved it with:

    UInt32(bigEndian: data.withUnsafeBytes { $0.pointee })
This discussion has been closed.