☰
Login
Signup
Home
›
Python client
Howdy, Stranger!
It looks like you're new here. If you want to get involved, click one of these buttons!
Sign In
Register
Categories
Recent Discussions
Activity
Categories
13.9K
All Categories
0
Incidents
156
Node JS client
40
Go client
793
.Net API client
380
Kite Publisher
537
.Net / VBA / Excel (3rd party)
458
Algorithms and Strategies
999
Java client
1.1K
API clients
404
PHP client
4K
Python client
348
Mobile and Desktop apps
1.4K
Market data (WebSockets)
3.3K
General
In this Discussion
July 2018
zartimus
July 2018
ansumanm
July 2018
rakeshr
Error in ws_threaded.py
ansumanm
July 2018
in
Python client
Hi,
I am getting these error messages in ws_threaded.py file:-
2018-07-03 14:44:27+0530 [-] Stopping factory
2018-07-03 14:44:30+0530 [-] Starting factory
2018-07-03 14:44:34+0530 [KiteTickerClientProtocol (TLSMemoryBIOProtocol),client] will retry in 3 seconds
2018-07-03 14:44:34+0530 [-] Stopping factory
2018-07-03 14:44:37+0530 [-] Starting factory
2018-07-03 14:44:41+0530 [KiteTickerClientProtocol (TLSMemoryBIOProtocol),client] will retry in 2 seconds
2018-07-03 14:44:41+0530 [-] Stopping factory
2018-07-03 14:44:44+0530 [-] Starting factory
2018-07-03 14:44:48+0530 [KiteTickerClientProtocol (TLSMemoryBIOProtocol),client] will retry in 2 seconds
2018-07-03 14:44:48+0530 [-] Stopping factory
2018-07-03 14:44:51+0530 [-] Starting factory
2018-07-03 14:44:55+0530 [KiteTickerClientProtocol (TLSMemoryBIOProtocol),client] will retry in 3 seconds
2018-07-03 14:44:55+0530 [-] Stopping factory
2018-07-03 14:44:59+0530 [-] Starting factory
2018-07-03 14:45:02+0530 [KiteTickerClientProtocol (TLSMemoryBIOProtocol),client] will retry in 3 seconds
2018-07-03 14:45:02+0530 [-] Stopping factory
2018-07-03 14:45:06+0530 [-] Starting factory
Anyone facing these issues ?
Thanks,
Ansuman
rakeshr
July 2018
@ansumanm
Are you doing something in on_tick callback? Can you paste your ws_threaded.py code here.
ansumanm
July 2018
My on_tick callback code:-
# Callback for tick reception.
def on_ticks(ws, ticks):
global ws_ctx
tsb_dict = ws_ctx['tsb_dict']
tsp = round(time.time() * 1000)
tsb_dict = ws_ctx['tsb_dict']
if len(ticks) > 0:
#logging
.debug("Ticks: {}".format(ticks))
for inst in ticks:
inst['tsp'] = tsp#inst['timestamp']
inst['tradingsymbol'] = tsb_dict[inst['instrument_token']]
publisher.sock_send(tsb_dict[inst['instrument_token']],
json.dumps(inst, default=datetime_handler))
Please let me know if you need the full code.
ansumanm
July 2018
# Callback when current connection is closed.
def on_close(ws, code, reason):
logging.info("Connection closed: {code} - {reason}".format(code=code, reason=reason))
# Callback when connection closed with error.
def on_error(ws, code, reason):
logging.info("Connection error: {code} - {reason}".format(code=code, reason=reason))
Nothing much going on there..
rakeshr
July 2018
@ansumanm
, i'm asking where all you are calling on_close method?
ansumanm
July 2018
Hi Rakesh,
We are not calling on_close() anywhere.
We only register it.
(env3) [ansuman@kuber]~/env3_projects/Infinity/ticks_collection$
>grep on_close ws_threaded.py
def on_close(ws, code, reason):
kws.on_close = on_close
(env3) [ansuman@kuber]~/env3_projects/Infinity/ticks_collection$
>
I am observing this on two different VMs so I am ruling out any environment issues.
Thanks,
Ansuman
ansumanm
July 2018
My kiteconnect version:-
>pip3 show kiteconnect
Name: kiteconnect
Version: 3.7.0b1
Summary: The official Python client for the Kite Connect trading API
Home-page:
https://kite.trade
Author: Zerodha Technology Pvt ltd. (India)
Author-email:
[email protected]
License: MIT
Location: /home/ansuman/env3/lib/python3.6/site-packages
Requires: requests, six, autobahn, Twisted, pyOpenSSL, service-identity, enum34, python-dateutil
>
Is this the latest one?
ansumanm
July 2018
I updated the kiteconnect to latest. Will run and see If I am hitting the issue. BTW, Is there any example where I reset the connection on the fly?
>pip3 show kiteconnect
Name: kiteconnect
Version: 3.7.4
Summary: The official Python client for the Kite Connect trading API
Home-page:
https://kite.trade
Author: Zerodha Technology Pvt ltd. (India)
Author-email:
[email protected]
License: MIT
Location: /home/ansuman/env_infinity/lib/python3.6/site-packages/kiteconnect-3.7.4-py3.6.egg
Requires: requests, six, pyOpenSSL, enum34, python-dateutil, autobahn
>
zartimus
July 2018
@ansumanm
Can you paste the full code?
There should be some bug in the code. Can you enable debug flag and check for stacktraces ? Any exception occurring in the event loop will result in on_error which will in turn close the connection.
Sign In
or
Register
to comment.
Are you doing something in on_tick callback? Can you paste your ws_threaded.py code here.
# Callback for tick reception.
def on_ticks(ws, ticks):
global ws_ctx
tsb_dict = ws_ctx['tsb_dict']
tsp = round(time.time() * 1000)
tsb_dict = ws_ctx['tsb_dict']
if len(ticks) > 0:
#logging.debug("Ticks: {}".format(ticks))
for inst in ticks:
inst['tsp'] = tsp#inst['timestamp']
inst['tradingsymbol'] = tsb_dict[inst['instrument_token']]
publisher.sock_send(tsb_dict[inst['instrument_token']],
json.dumps(inst, default=datetime_handler))
Please let me know if you need the full code.
def on_close(ws, code, reason):
logging.info("Connection closed: {code} - {reason}".format(code=code, reason=reason))
# Callback when connection closed with error.
def on_error(ws, code, reason):
logging.info("Connection error: {code} - {reason}".format(code=code, reason=reason))
Nothing much going on there..
We are not calling on_close() anywhere.
We only register it.
(env3) [ansuman@kuber]~/env3_projects/Infinity/ticks_collection$
>grep on_close ws_threaded.py
def on_close(ws, code, reason):
kws.on_close = on_close
(env3) [ansuman@kuber]~/env3_projects/Infinity/ticks_collection$
>
I am observing this on two different VMs so I am ruling out any environment issues.
Thanks,
Ansuman
>pip3 show kiteconnect
Name: kiteconnect
Version: 3.7.0b1
Summary: The official Python client for the Kite Connect trading API
Home-page: https://kite.trade
Author: Zerodha Technology Pvt ltd. (India)
Author-email: [email protected]
License: MIT
Location: /home/ansuman/env3/lib/python3.6/site-packages
Requires: requests, six, autobahn, Twisted, pyOpenSSL, service-identity, enum34, python-dateutil
>
Is this the latest one?
>pip3 show kiteconnect
Name: kiteconnect
Version: 3.7.4
Summary: The official Python client for the Kite Connect trading API
Home-page: https://kite.trade
Author: Zerodha Technology Pvt ltd. (India)
Author-email: [email protected]
License: MIT
Location: /home/ansuman/env_infinity/lib/python3.6/site-packages/kiteconnect-3.7.4-py3.6.egg
Requires: requests, six, pyOpenSSL, enum34, python-dateutil, autobahn
>
There should be some bug in the code. Can you enable debug flag and check for stacktraces ? Any exception occurring in the event loop will result in on_error which will in turn close the connection.