javascript code for Websockets

pannet1
pannet1 edited August 2017 in PHP client
hi @sujith

here is the code as per kite connect PHP documentation for using websocket from client side (using javascript)
var ws = new WebSocket("wss://websocket.kite.trade/?api_key=mysecretkey&user_id=myid&public_token=my_public_token");
// Subscribe to quotes for INFY (408065) and TATAMOTORS (884737)
var message = {"a": "subscribe", "v": [408065, 884737]};
ws.send(JSON.stringify(message))
// Set TATAMOTORS (884737) to 'ltp' to only receive the LTP.
message = {"a": "mode", "v": ["ltp", [884737]]};
ws.send(JSON.stringify(message))
Technically I use PHP for getting the user_id and public_token after accesstoken is set. I am also able to successfully build my app based on the other parts of the API.

So, the above code should return the quote, right ? But I am not able to get any response. What am I doing wrong. Thanks.


Tagged:
  • pannet1
    i am bumping this again ..
  • sujith
    Hi @pannet1,
    Websockets data is returned as binary data. Check out parsing example here.
    As a first step, I would suggest setting a callback and check if you are getting data.
  • pannet1
    @sujith,

    i have already made a wrapper in PHP with Kite API. Now it looks like I need to scratch it and start developing a wrapper around Node and Kite API.

    i already have a Public API through my PHP App after subjecting it through lot of rerouting, controller and view. What I am expecting from you now is a simple include of the kite.js in the html header and a small tag that could process the kite js object.

    Is it possible or not ? If yes, please post the code.
  • tonystark
    Hi @pannet1,

    Here is an example you can use: Kite Ticker Pure JS Example
  • pannet1
    wow @ajinasokan,

    its so kind of you. i will check it out.

    thanks a lot.
This discussion has been closed.