Yash
Yash

Reputation: 59

KiteConnect WEBSOCKET STREAMING ERROR : ReactorNotRestartable

I am trying to get ticks result from the kiteconnect API using KiteTicker. I have used the code given in the documentation

import logging
from kiteconnect import KiteTicker

logging.basicConfig(level=logging.DEBUG)

# Initialise
kws = KiteTicker("my_api", "my_access_token")

def on_ticks(ws, ticks):
    # Callback to receive ticks.
      print(ticks)

def on_connect(ws, response):
    # Callback on successful connect.
    # Subscribe to a list of instrument_tokens (RELIANCE and ACC here).
    ws.subscribe([738561, 5633])

    # Set RELIANCE to tick in `full` mode.
    ws.set_mode(ws.MODE_FULL, [738561])

def on_close(ws, code, reason):
    # On connection close stop the event loop.
    # Reconnection will not happen after executing `ws.stop()`
    ws.stop()

# Assign the callbacks.
kws.on_ticks = on_ticks
kws.on_connect = on_connect
kws.on_close = on_close

# Infinite loop on the main thread. Nothing after this will run.
# You have to use the pre-defined callbacks to manage subscriptions.
kws.connect()

It ran successfully for the first time but not it's showing below error:

2020-06-26 20:09:26+0530 [-] Starting factory <kiteconnect.ticker.KiteTickerClientFactory object at 0x000001DE88068A88>
DEBUG:kiteconnect.ticker:Start WebSocket connection.
Traceback (most recent call last):

  File "<ipython-input-52-9b59ab5163b2>", line 31, in <module>
    kws.connect()

  File "C:\Users\yp229\anaconda3\lib\site-packages\kiteconnect\ticker.py", line 532, in connect
    reactor.run(**opts)

  File "C:\Users\yp229\anaconda3\lib\site-packages\twisted\internet\base.py", line 1282, in run
    self.startRunning(installSignalHandlers=installSignalHandlers)

  File "C:\Users\yp229\anaconda3\lib\site-packages\twisted\internet\base.py", line 1262, in startRunning
    ReactorBase.startRunning(self)

  File "C:\Users\yp229\anaconda3\lib\site-packages\twisted\internet\base.py", line 765, in startRunning
    raise error.ReactorNotRestartable()

ReactorNotRestartable

I am not able to find the reasoning behind the same and also unable to get the log file :| . I was trying to achieve below output:

  1. List of kite ticks (I wanted to store it in the data frame but the printing it self giving the error)
  2. Applying certain condition on ticks result

Any help would be really useful.

Upvotes: 3

Views: 943

Answers (0)

Related Questions