Web Socket not connecting.

gowthamrajanm
gowthamrajanm edited April 4 in General
HI, I am getting below error always today. This seem to be working till yesterday. Today I got this issue randomly & not sure why.

ticker.js:262 WebSocket connection to 'wss://ws.kite.trade/?api_key=XXXXXX&access_token=XXXXX&uid=XXXXX' failed:


Please help me on this.
  • rakeshr
    failed:
    Can you paste here the complete error stack trace?
  • gowthamrajanm
    I am not getting full stack trace. please find the error

    ticker.js:262 WebSocket connection to 'wss://ws.kite.trade/?api_key=oe8lq2vz8pbporok&access_token=5ax4GWxgXS9X08jVGabXMPJxNEWXjx2D&uid=1712226474592' failed:


  • rakeshr
    Looks like the above screenshot is from the browser console. Are you trying to run nodejs code using a front-end app?
    It won't compile successfully because of the CORS issue. This issue explains in detail.
  • gowthamrajanm
    gowthamrajanm edited April 4
    I am not running any node.js code. I am just using the ticker.js file. I saw the link which you have shared, I am running it from my local machine and it is for MY PERSONAL ZERODHA ACCOUNT. Accessing the api will need a application right, and it is using my own account which I have paid API for. Exactly what do we refer to "FOR PERSONAL USE ONLY"
    ?
  • gowthamrajanm
    gowthamrajanm edited April 4
    Without Using a FRONT-END APP, how we are suppose to use the API. Please suggest.
  • anuragroy11
    @gowthamrajanm Although you cannot call any of the APIs from your browser (they don't return CORS headers), you can connect to the websocket from your browser. What exactly is the error that you are getting?

    To use it in a client side rendered app, either setup your own proxy server which adds the CORS headers to every kite response, or use an API layer or use something like Next.js which has server support.
  • gowthamrajanm
    @anuragroy11 I have pasted below


    Initially I dont get this bug, but as the day progresses, KiteTicker.js stops responding and throws connection error.
    I havent customized anything, just included kiteticker.js and I am showing LTP in fullmode. This bug appears always.
  • gowthamrajanm
    any update to fix this BUG?
  • MAG
    I would suggest that you try connecting to websocket using backend command line code in the language of your choice - preferably python as its the easiest for anyone to pick up whether someone is adept at another programming language or absolutely new to programming.

    The websocket sample code in zerodha python client library is good enough that you can copy it as is and use it with very little modification.

    I don't think any adept programmer would try connecting to websocket using a browser as it adds a lot of abstraction and is difficult to debug. So if you insist on using brower to connect to websocket you may be on your own.

    Also if websocket is connecting initially and disconnecting after some time it could be an issue of internet connection flaking. This is the most common reason. In your case since you are using a browser, the browser may be adding its own session management and timeout logic.

    Like I said earlier browsers will add their own connection logic and abstraction layer making it unreliable and difficult to debug. Switch to backend CLI code.
  • gowthamrajanm
    When you have your code in backend, for every second LTP changes on LIVE FEED. So you need to call the backend code every second which may result in slowing down the system right? Is there a way to over come this atleast?
  • MAG
    Many of us here have entire algo setups with code running in the backend doing everything from getting ticks from websockets, computing candles, running strategies and trading/order placement. Some of us also have real time monitoring / reporting of trades and positions either on the backend terminal itself or using GUI front ends.

    So it is definitely possible. But out here this forum is a place for helping people resolve API related issues. It is impossible to teach someone how to code on a text forum like this.

    I would suggest you go to youtube and give a search for 'zerodha api' or 'zerodha kiteconnect'. You will find a number of videos explaining how things work, how to set up your environment and many of them show actual code and walk you through the code logic.
Sign In or Register to comment.