Hi Team,
In current version, am able to subscribe to the symbol and its running in infinite loop, unable to retrieve the data from the subscription.
ex… code
feedJson={}
listOfTradingSymbol=[“MIDCPNIFTY08JAN24C10575”,“MIDCPNIFTY08JAN24C10500”,“MIDCPNIFTY08JAN24C10550”]
def subscribe_feed_data(data):
if (‘lp’ in data ) &(‘tk’ in data):
feedJson[data[‘tk’]] = {‘ltp’: float(data[‘lp’])}
print(feedJson)
thefirstock.websocket_connection( ‘AR6699’,
listOfTradingSymbol,
socket_connection=2,
activate_sub_feed=True,
callback_sub_feed= subscribe_feed_data
)
output:
{‘message’: ‘Connection Established’}
{‘41370’: {‘ltp’: 0.25}}
{‘41370’: {‘ltp’: 0.25}, ‘41335’: {‘ltp’: 1.65}}
{‘41370’: {‘ltp’: 0.25}, ‘41335’: {‘ltp’: 1.65}, ‘41345’: {‘ltp’: 0.35}}
and it runs in infinite loop. unable to come out of it and retrieve the value of it.
Tried the same code with Threads as well. Its throwing error.
Below are the code:
def websocket_firstock():
feedJson={}
listOfTradingSymbol=[“MIDCPNIFTY08JAN24C10575”,“MIDCPNIFTY08JAN24C10500”,“MIDCPNIFTY08JAN24C10550”]
def subscribe_feed_data(data):
if ('lp' in data ) &('tk' in data):
feedJson[data['tk']] = {'ltp': float(data['lp'])}
print(feedJson)
thefirstock.websocket_connection( 'AR6699',
listOfTradingSymbol,
socket_connection=2,
activate_sub_feed=True,
callback_sub_feed= subscribe_feed_data
)
t1=threading.Thread(target=websocket_firstock)
t1.start()
Output:
Exception in thread Thread-5 (websocket_firstock):
Traceback (most recent call last):
File “c:\Python311\Lib\threading.py”, line 1038, in _bootstrap_inner
self.run()
File “c:\Python311\Lib\threading.py”, line 975, in run
self._target(*self._args, **self._kwargs)
File “C:\Users\umadh\AppData\Local\Temp\ipykernel_77116\798819257.py”, line 12, in websocket_firstock
File “c:\Python311\Lib\site-packages\thefirstock\exchange_socket.py”, line 105, in websocket_connection
asyncio.get_event_loop().run_until_complete(
^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\umadh\AppData\Roaming\Python\Python311\site-packages\nest_asyncio.py”, line 45, in _get_event_loop
loop = events.get_event_loop_policy().get_event_loop()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “c:\Python311\Lib\asyncio\events.py”, line 677, in get_event_loop
raise RuntimeError(‘There is no current event loop in thread %r.’
RuntimeError: There is no current event loop in thread ‘Thread-5 (websocket_firstock)’.