Announcing live WebSocket API

Kailash
The live WebSockets streaming API is now live. It is documented here -- https://kite.trade/docs/connect/v1/#streaming-websocket-api

We will publish client libraries for the API in the near future.
  • dineshkumarc
    Hi Kailash,

    I have integrated Kite API and successfully retrieve public_token. I have opened a socket connection using "Dark web scoket" extension of Google Chrome. When I'm subscribing for quotes using "{"a":"subscribe","v":[408065,884737]}" action, It's going to respond as follows:

    received: <94B of binary data>
    00 02 00 2c 00 06 3a 01 00 01 be 7c 00 00 00 01 |...,..:....|....|
    00 01 c0 a8 00 1e f6 da 00 00 00 00 00 00 07 b5 |................|
    00 01 bf bc 00 01 c3 8b 00 01 bc 9c 00 01 be 7c |...............||
    00 2c 00 0d 80 01 00 00 8a 61 00 00 00 32 00 00 |.,.......a...2..|
    88 e0 00 74 98 f2 00 00 00 92 00 00 00 00 00 00 |...t............|
    88 22 00 00 8b 06 00 00 86 d3 00 00 8a 61 |."...........a |

    Than I'm not going to receive any quotes, May you please help to resolve the issue?
  • Kailash
    Kailash edited March 2016
    @dineshkumarc That is the quote;it's binary data. Please read the documentation on how to parse it -- https://kite.trade/docs/connect/v1/#streaming-websocket-api
  • dineshkumarc
    @Kailash I have already read the https://kite.trade/docs/connect/v1/#streaming-websocket-api, But binary means 0 and 1, so why it's responding non binary format (i.e. including 1-8, a-f chars) as I shown in my previous comment.

    Also, when I' using using {"a": "mode", "v": ["ltp", [884737]} action, it's just responding '00', there's no response for given action.

    May you please clear about binary data? (I think it's in HEX format)
    How to parse binary data in JavaScript?
    Example for using "ltp" mode, because examples given in API documentation is not working.
  • Kailash
    @dineshkumarc The underlying data is indeed binary, just that it's being displayed by your system as hex. If you are using Javascript, please look up "arraybuffer". You may want to set ws.binaryType = "arraybuffer"

    We'll be releasing a Javascript client library shortly that handles all the underlying details for you.
  • instruritesh
    @Kailash is there any specific time interval at which data gets trasnferred to the websocket? Is it tick data? My question is what is the mechanism behind the data transfer in the websocket e.g. time based or per trade based etc?
  • Kailash
    @instruritesh The API streams messages tick(s) every 700ms to 1 sec. Each message can contain ticks for multiple instruments.

    It would be trade based. The exchange may send n number of ticks per instrument per second (usually 5-10 for very active instruments). The API streams the latest one of these ticks in the aforementioned interval.
  • Kailash
    https://kite.trade/#pricing -- WebSocket API is now bundled with the app with no additional charges.
  • kpskps
    @Kailash i tried the websocket api in python using websocket client, i got stuck at this point

    import websocket
    from settings import *
    import json

    ws = websocket.create_connection(WEBSOCKET_ROOT+"/?api_key="+API_KEY+"&user_id="+USER_ID+"&public_token="+PUBLIC_TOKEN,sslopt={"cert_reqs": websocket.ssl.CERT_NONE})
    message = {"a": "subscribe", "v": [884737]};
    ws.send(json.dumps(message))

    result = ws.recv()

    result's output is \x00\x01\x00,\x00\r\x80\x01\x00\x00\x97T\x00\x00\x002\x00\x00\x00\x00\x00\x00\x0fg\x00\x00#\x05\x00\x00`\x8e\x00\x00\x98X\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x97\xb8

    how do i use this ? this looks like hex but it has some characters like ',' in the middle. How can i get quotes from this.

    @others let me know in case you guys have a solution for the same.

  • Kailash
    @kpskps That is binary data (Python's just showing it as hex). You'll have to parse the binary data into the structures described in the document.

    That said, we're working on client libraries that you can just import and use. The Python and JS libraries should be out in the next few days.
  • dhavalp
    according to the doc, websocket server should return me binary data, but what i received is an array of numbers
    [0, 1, 0, 164, 0, 6, 58, 1, 0, 1, 213, 16, 0, 0, 0, 20, 0, 1, 217, 147, 0, 26, 18, 121, 0, 2, 18, 139, 0, 2, 130, 208, 0, 1, 223, 176, 0, 1, 223, 176, 0, 1, 211, 48, 0, 1, 220, 124, 0, 0, 0, 10, 0, 1, 213, 16, 0, 2, 0, 0, 0, 0, 0, 10, 0, 1, 213, 11, 0, 1, 0, 0, 0, 0, 0, 8, 0, 1, 213, 6, 0, 1, 0, 0, 0, 0, 0, 50, 0, 1, 212, 247, 0, 1, 0, 0, 0, 0, 0, 5, 0, 1, 212, 242, 0, 1, 0, 0, 0, 0, 0, 133, 0, 1, 213, 36, 0, 6, 0, 0, 0, 0, 0, 55, 0, 1, 213, 66, 0, 2, 0, 0, 0, 0, 0, 13, 0, 1, 213, 76, 0, 1, 0, 0, 0, 0, 0, 239, 0, 1, 213, 81, 0, 1, 0, 0, 0, 0, 0, 197, 0, 1, 213, 86, 0, 4, 0, 0]
  • Kailash
    Your system is just representing the binary data as an array of numbers.
  • dhavalp
    OK thanks. It was hex. I think you should give all probabilities and example in the doc for better understanding.
  • ishwarm
    ishwarm edited May 2016
    Hi Kailash,

    Can you provide a client library for the Websocket API for Android also? That will help a lot.

    Thanks,
    Ishwar.
  • Kailash
    Hi @ishwarm -- give us a week or so please. Our Android SDK is almost done.
  • ashwin_tay
    Hello has there been any update on this? Have u released a javascript API for this? I am getting binary data but I don't know how to convert it back to the required format
  • tonystark
    tonystark edited October 2017
    Hi @ashwin_tay,

    You can check out our official Node.js library. Or if you want a pure js implementation check out this gist.
Sign In or Register to comment.