@rajanprabu Can anyone please tell me what is wrong with this code__
token = "nse_cm|2885&nse_cm|3465&nse_cm|1660"
task = "mw" # "mw"|"sfi"|"dp"
ss = WebSocket(FEED_TOKEN, CLIENT_CODE)
trading_portfolio = {"nse_cm|2885": "RELIANCE", "nse_cm|3465": "TATAMOTORS", "nse_cm|1660": "ITC"}
def on_tick(ws, tick):
for single_company in tick:
inst_of_single_company = single_company['tk']
name = trading_portfolio[inst_of_single_company]
print(single_company, name)
I'm getting error like this____
Unhandled Error
Traceback (most recent call last):
File "C:\Python 3.9.2\lib\site-packages\twisted\python\log.py", line 101, in callWithLogger
return callWithContext({"system": lp}, func, *args, **kw)
File "C:\Python 3.9.2\lib\site-packages\twisted\python\log.py", line 85, in callWithContext
return context.call({ILogContext: newCtx}, func, *args, **kw)
File "C:\Python 3.9.2\lib\site-packages\twisted\python\context.py", line 118, in callWithContext
return self.currentContext().callWithContext(ctx, func, *args, **kw)
File "C:\Python 3.9.2\lib\site-packages\twisted\python\context.py", line 83, in callWithContext
return func(*args, **kw)
--- <exception caught here> ---
File "C:\Python 3.9.2\lib\site-packages\twisted\internet\selectreactor.py", line 149, in _doReadOrWrite
why = getattr(selectable, method)()
File "C:\Python 3.9.2\lib\site-packages\twisted\internet\tcp.py", line 246, in doRead
return self._dataReceived(data)
File "C:\Python 3.9.2\lib\site-packages\twisted\internet\tcp.py", line 251, in _dataReceived
rval = self.protocol.dataReceived(data)
File "C:\Python 3.9.2\lib\site-packages\twisted\protocols\tls.py", line 324, in dataReceived
self._flushReceiveBIO()
File "C:\Python 3.9.2\lib\site-packages\twisted\protocols\tls.py", line 290, in _flushReceiveBIO
ProtocolWrapper.dataReceived(self, bytes)
File "C:\Python 3.9.2\lib\site-packages\twisted\protocols\policies.py", line 107, in dataReceived
self.wrappedProtocol.dataReceived(data)
File "C:\Python 3.9.2\lib\site-packages\autobahn\twisted\websocket.py", line 290, in dataReceived
self._dataReceived(data)
File "C:\Python 3.9.2\lib\site-packages\autobahn\websocket\protocol.py", line 1207, in _dataReceived
self.consumeData()
File "C:\Python 3.9.2\lib\site-packages\autobahn\websocket\protocol.py", line 1219, in consumeData
while self.processData() and self.state != WebSocketProtocol.STATE_CLOSED:
File "C:\Python 3.9.2\lib\site-packages\autobahn\websocket\protocol.py", line 1579, in processData
fr = self.onFrameEnd()
File "C:\Python 3.9.2\lib\site-packages\autobahn\websocket\protocol.py", line 1704, in onFrameEnd
self._onMessageEnd()
File "C:\Python 3.9.2\lib\site-packages\autobahn\twisted\websocket.py", line 318, in _onMessageEnd
self.onMessageEnd()
File "C:\Python 3.9.2\lib\site-packages\autobahn\websocket\protocol.py", line 628, in onMessageEnd
self._onMessage(payload, self.message_is_binary)
File "C:\Python 3.9.2\lib\site-packages\autobahn\twisted\websocket.py", line 321, in _onMessage
self.onMessage(payload, isBinary)
File "C:\Python 3.9.2\lib\site-packages\smartapi\webSocket.py", line 41, in onMessage
self.factory.on_message(self, payload, is_binary)
File "C:\Python 3.9.2\lib\site-packages\smartapi\webSocket.py", line 337, in _on_message
self._parse_text_message(payload)
File "C:\Python 3.9.2\lib\site-packages\smartapi\webSocket.py", line 377, in _parse_text_message
self.on_ticks(self, data)
File "C:\Users\Nayan\PycharmProjects\Angel_Broking\main.py", line 31, in on_tick
inst_of_single_company = single_company['tk']
builtins.KeyError: 'tk'
Unhandled Error
Traceback (most recent call last):
File "C:\Python 3.9.2\lib\site-packages\smartapi\webSocket.py", line 233, in connect
reactor.run(**opts)
File "C:\Python 3.9.2\lib\site-packages\twisted\internet\base.py", line 1423, in run
self.mainLoop()
File "C:\Python 3.9.2\lib\site-packages\twisted\internet\base.py", line 1436, in mainLoop
reactorBaseSelf.doIteration(t)
File "C:\Python 3.9.2\lib\site-packages\twisted\internet\selectreactor.py", line 143, in doSelect
_logrun(selectable, _drdw, selectable, method)
--- <exception caught here> ---
File "C:\Python 3.9.2\lib\site-packages\twisted\python\log.py", line 101, in callWithLogger
return callWithContext({"system": lp}, func, *args, **kw)
File "C:\Python 3.9.2\lib\site-packages\twisted\python\log.py", line 85, in callWithContext
return context.call({ILogContext: newCtx}, func, *args, **kw)
File "C:\Python 3.9.2\lib\site-packages\twisted\python\context.py", line 118, in callWithContext
return self.currentContext().callWithContext(ctx, func, *args, **kw)
File "C:\Python 3.9.2\lib\site-packages\twisted\python\context.py", line 83, in callWithContext
return func(*args, **kw)
File "C:\Python 3.9.2\lib\site-packages\twisted\internet\selectreactor.py", line 154, in _doReadOrWrite
self._disconnectSelectable(selectable, why, method == "doRead")
File "C:\Python 3.9.2\lib\site-packages\twisted\internet\posixbase.py", line 306, in _disconnectSelectable
selectable.connectionLost(failure.Failure(why))
File "C:\Python 3.9.2\lib\site-packages\twisted\internet\tcp.py", line 506, in connectionLost
self._commonConnection.connectionLost(self, reason)
File "C:\Python 3.9.2\lib\site-packages\twisted\internet\tcp.py", line 324, in connectionLost
protocol.connectionLost(reason)
File "C:\Python 3.9.2\lib\site-packages\twisted\protocols\tls.py", line 389, in connectionLost
self._flushReceiveBIO()
File "C:\Python 3.9.2\lib\site-packages\twisted\protocols\tls.py", line 290, in _flushReceiveBIO
ProtocolWrapper.dataReceived(self, bytes)
File "C:\Python 3.9.2\lib\site-packages\twisted\protocols\policies.py", line 107, in dataReceived
self.wrappedProtocol.dataReceived(data)
File "C:\Python 3.9.2\lib\site-packages\autobahn\twisted\websocket.py", line 290, in dataReceived
self._dataReceived(data)
File "C:\Python 3.9.2\lib\site-packages\autobahn\websocket\protocol.py", line 1207, in _dataReceived
self.consumeData()
File "C:\Python 3.9.2\lib\site-packages\autobahn\websocket\protocol.py", line 1219, in consumeData
while self.processData() and self.state != WebSocketProtocol.STATE_CLOSED:
File "C:\Python 3.9.2\lib\site-packages\autobahn\websocket\protocol.py", line 1571, in processData
fr = self.onFrameData(payload)
File "C:\Python 3.9.2\lib\site-packages\autobahn\websocket\protocol.py", line 1666, in onFrameData
self._onMessageFrameData(payload)
File "C:\Python 3.9.2\lib\site-packages\autobahn\twisted\websocket.py", line 309, in _onMessageFrameData
self.onMessageFrameData(payload)
File "C:\Python 3.9.2\lib\site-packages\autobahn\websocket\protocol.py", line 602, in onMessageFrameData
self.frame_data.append(payload)
builtins.AttributeError: 'NoneType' object has no attribute 'append'