jugaad-py/jugaad-trader

Ticker is Unable to connect.

Opened this issue ยท 5 comments

Unable to connect to Ticker

Sample code being used.

Error
Connection error: 1006 - connection was closed uncleanly (WebSocket connection upgrade failed (400 - BadRequest))
Connection closed: 1006 - connection was closed uncleanly (WebSocket connection upgrade failed (400 - BadRequest))

Additional context
Add any other context about the problem here.

Hello @vijay-arwapally ,

I think you need to apply 2 changes.

image

replace with

import urllib.parse
image

In the python package of zerodha - KiteTicket class / file name ticker.py change word access_token to enctoken
image

replace with

image

Please note the second change will be replaced if you update kite package in future. so we might need to apply this again each time we upgrade kite package.

This worked for me, thanks

Resolved. Thanks

This is the hack with current code base:

jugaad-trader diff:

diff --git a/jugaad_trader/zerodha.py b/jugaad_trader/zerodha.py
index f39e44a..fbc44a7 100644
--- a/jugaad_trader/zerodha.py
+++ b/jugaad_trader/zerodha.py
@@ -13,6 +13,7 @@ import pickle
 import requests
 import click
 from six.moves.urllib.parse import urljoin
+import urllib.parse

 from kiteconnect import KiteConnect, KiteTicker
 import kiteconnect.exceptions as ex
@@ -50,7 +51,7 @@ class ZerodhaTicker(KiteTicker):

         uid = int(time.time()) * 1000
         self.socket_url = "{root}?api_key=kitefront&user_id={user_id}&enctoken={enc_token}&uid={uid}&user-agent=kite3-web&version=2.4.0".format(
-            root=self.ROOT_URI, user_id=user_id, enc_token=enc_token, uid=uid
+            root=self.ROOT_URI, user_id=user_id, enc_token=urllib.parse.quote_plus(enc_token), uid=uid
         )

The changes to pykiteconnect remains the same as above by @ssheikh098

Zerodha has changes the root for WebSocket.
root='wss://ws.kite.trade'

Please refer to this video for solution.
https://www.youtube.com/watch?v=_9C3FzqG-K8