alphatrade icon indicating copy to clipboard operation
alphatrade copied to clipboard

Error: __on_close_callback() takes from 1 to 2 positional arguments but 4 were give

Open alokgpee opened this issue 2 years ago • 2 comments

Getting below issue very frequently after some time of running program.

ERROR:websocket:error from callback <bound method AlphaTrade.__on_close_callback of <alphatrade.alphatrade.AlphaTrade object at 0x0000025FC445FF70>>: __on_close_callback() takes from 1 to 2 positional arguments but 4 were given

Generally happens on calling following function: sas.subscribe(optionType, LiveFeedType.COMPACT)

Trace logs are as follows: ERROR:websocket:error from callback <bound method AlphaTrade.__on_close_callback of <alphatrade.alphatrade.AlphaTrade object at 0x0000025FC445FF70>>: __on_close_callback() takes from 1 to 2 positional arguments but 4 were given

Traceback (most recent call last): File "d:\alokguptaxggn\python_sandbox\python_stories\python_stories\01-Development\algoTrade\63AlgoTrade-MIS-4-RSI-56.py", line 238, in putBuyPrice = getOptionPrice(sas, NIFTY_PUT) File "d:\alokguptaxggn\python_sandbox\python_stories\python_stories\01-Development\algoTrade\63AlgoTrade-MIS-4-RSI-56.py", line 20, in getOptionPrice sas.subscribe(optionType, LiveFeedType.COMPACT) File "C:\Users\alokg\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\alphatrade\alphatrade.py", line 857, in subscribe return self.__ws_send(data) File "C:\Users\alokg\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\alphatrade\alphatrade.py", line 460, in __ws_send self.__websocket.send(*args, **kwargs) ocal\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Pythonpy", line 203, in send if not self.sock or self.sock.send(data, opcode) == 0:
File "C:\Users\alokg\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\websocket_core.py", line 283, in send return self.send_frame(frame File "C:\Users\alokg\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\websocket_core.py", line 311, in send_frame
l = self._send(data)
File "C:\Users\alokg\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\websocket_core.py", line 525, in _send
return send(self.sock, data) File "C:\Users\alokg\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\websocket_socket.py", line 146, in send
raise WebSocketConnectionClosedException("socket is already closed.") websocket._exceptions.WebSocketConnectionClosedException: socket is already closed.

alokgpee avatar Mar 24 '22 06:03 alokgpee

Is it possible for your to share the code? using code formatting. I will check it out

algo2t avatar Apr 01 '22 21:04 algo2t

Is it possible for your to share the code? using code formatting. I will check it out

Hi @algo2t, I am also receiving this error quite often. It happens sporadically.

2022-08-23 12:52:01,310 - ERROR - algo_test.py:292 - Error in subscribing to main instrument : EOF occurred in violation of protocol (_ssl.c:2384)

This happens when I try to subscribe to Nifty feed. Probably it could be for any instrument and not just for Nifty.

try:
    x = sas.get_instrument_by_symbol('NSE', 'Nifty 50')
    sas.subscribe(x, LiveFeedType.COMPACT)
    subscribed = len(sas._AlphaTrade__subscribers)
    sleep(1)
except Exception as e:
    logging.error('Error in subscribing to main instrument : ' + str(e))

Does it has something to do with insufficient memory (RAM)? or anything else? Kindly help.

ronaldpaul avatar Aug 23 '22 05:08 ronaldpaul