jugaad-trader icon indicating copy to clipboard operation
jugaad-trader copied to clipboard

Ticker is Unable to connect.

Open vijay-arwapally opened this issue 2 years ago • 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.

vijay-arwapally avatar Jul 18 '22 10:07 vijay-arwapally

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.

ssheikh098 avatar Jul 31 '22 20:07 ssheikh098

This worked for me, thanks

PrajwalShenoy avatar Aug 16 '22 08:08 PrajwalShenoy

Resolved. Thanks

ashishanand7 avatar Sep 08 '22 23:09 ashishanand7

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

rushiagr avatar Oct 21 '23 08:10 rushiagr

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

suri2501 avatar Feb 04 '24 02:02 suri2501