avanza
avanza copied to clipboard
While running in a subscription mode of a symbol sometimes exception happens
Task exception was never retrieved future: <Task finished name='Task-2' coro=<AvanzaSocket.__create_socket() done, defined at /home/anirban/.local/lib/python3.10/site-packages/avanza/avanza_socket.py:45> exception=ConnectionClosedError(None, Close(code=1011, reason='keepalive ping timeout'), None)> Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/websockets/legacy/protocol.py", line 945, in transfer_data message = await self.read_message() File "/usr/local/lib/python3.10/dist-packages/websockets/legacy/protocol.py", line 1015, in read_message frame = await self.read_data_frame(max_size=self.max_size) File "/usr/local/lib/python3.10/dist-packages/websockets/legacy/protocol.py", line 1090, in read_data_frame frame = await self.read_frame(max_size) File "/usr/local/lib/python3.10/dist-packages/websockets/legacy/protocol.py", line 1145, in read_frame frame = await Frame.read( File "/usr/local/lib/python3.10/dist-packages/websockets/legacy/framing.py", line 70, in read data = await reader(2) File "/usr/lib/python3.10/asyncio/streams.py", line 708, in readexactly await self._wait_for_data('readexactly') File "/usr/lib/python3.10/asyncio/streams.py", line 502, in _wait_for_data await self._waiter asyncio.exceptions.CancelledError
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "/home/anirban/.local/lib/python3.10/site-packages/avanza/avanza_socket.py", line 51, in __create_socket await self.__socket_message_handler() File "/home/anirban/.local/lib/python3.10/site-packages/avanza/avanza_socket.py", line 172, in __socket_message_handler async for message in self._socket: File "/usr/local/lib/python3.10/dist-packages/websockets/legacy/protocol.py", line 482, in aiter yield await self.recv() File "/usr/local/lib/python3.10/dist-packages/websockets/legacy/protocol.py", line 553, in recv await self.ensure_open() File "/usr/local/lib/python3.10/dist-packages/websockets/legacy/protocol.py", line 930, in ensure_open raise self.connection_closed_exc() websockets.exceptions.ConnectionClosedError: sent 1011 (unexpected error) keepalive ping timeout; no close frame received
This error keeps happening routinely, has any one else faced this?
Task exception was never retrieved
future: <Task finished name='Task-2' coro=<AvanzaSocket.__create_socket() done, defined at /home/anirban/.local/lib/python3.10/site-packages/avanza/avanza_socket.py:45> exception=ConnectionError(ProtocolError('Connection aborted.', RemoteDisconnected('Remote end closed connection without response')))>
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 699, in urlopen
httplib_response = self._make_request(
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 445, in _make_request
six.raise_from(e, None)
File "
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/requests/adapters.py", line 439, in send
resp = conn.urlopen(
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 755, in urlopen
retries = retries.increment(
File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 532, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/usr/lib/python3/dist-packages/six.py", line 718, in reraise
raise value.with_traceback(tb)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 699, in urlopen
httplib_response = self._make_request(
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 445, in _make_request
six.raise_from(e, None)
File "
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/anirban/.local/lib/python3.10/site-packages/avanza/avanza_socket.py", line 51, in __create_socket
await self.__socket_message_handler()
File "/home/anirban/.local/lib/python3.10/site-packages/avanza/avanza_socket.py", line 186, in __socket_message_handler
callback(message)
File "/home/anirban/Dropbox/Trading/Securities/Codes/MarketInteractin/Trading_with_instrnumber.py", line 175, in callback
result = avanza.get_deals_and_orders() #avanza.get_order(accountid, orderid)
File "/home/anirban/.local/lib/python3.10/site-packages/avanza/avanza.py", line 1459, in get_deals_and_orders
return self.__call(
File "/home/anirban/.local/lib/python3.10/site-packages/avanza/avanza.py", line 129, in __call
response = method_call(
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 555, in get
return self.request('GET', url, **kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python3/dist-packages/requests/adapters.py", line 498, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
^CTraceback (most recent call last):
File "/home/anirban/Dropbox/Trading/Securities/Codes/MarketInteractin/Trading_with_instrnumber.py", line 331, in
I am having problems with these types of exceptions too. I don't know how to catch them. My main thread is just looping on sleep() so it has nothing to catch and apart from that all I have is a call-back. Does anyone have any tips?
This is a problem with the API itself. I found a work-around for it, but it isn't pretty: https://github.com/Qluxzz/avanza/issues/86