Qluxzz / avanza

A Python library for the unofficial Avanza API
https://qluxzz.github.io/avanza/
MIT License
85 stars 40 forks source link

While running in a subscription mode of a symbol sometimes exception happens #78

Open anirbankrishna opened 1 year ago

anirbankrishna commented 1 year ago

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

anirbankrishna commented 1 year ago

This error keeps happening routinely, has any one else faced this?

anirbankrishna commented 1 year ago

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 "", line 3, in raise_from File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 440, in _make_request httplib_response = conn.getresponse() File "/usr/lib/python3.10/http/client.py", line 1374, in getresponse response.begin() File "/usr/lib/python3.10/http/client.py", line 318, in begin version, status, reason = self._read_status() File "/usr/lib/python3.10/http/client.py", line 287, in _read_status raise RemoteDisconnected("Remote end closed connection without" http.client.RemoteDisconnected: Remote end closed connection without response

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 "", line 3, in raise_from File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 440, in _make_request httplib_response = conn.getresponse() File "/usr/lib/python3.10/http/client.py", line 1374, in getresponse response.begin() File "/usr/lib/python3.10/http/client.py", line 318, in begin version, status, reason = self._read_status() File "/usr/lib/python3.10/http/client.py", line 287, in _read_status raise RemoteDisconnected("Remote end closed connection without" urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

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 main() File "/home/anirban/Dropbox/Trading/Securities/Codes/MarketInteractin/Trading_with_instrnumber.py", line 328, in main loop.run_forever() File "/usr/lib/python3.10/asyncio/base_events.py", line 600, in run_forever self._run_once() File "/usr/lib/python3.10/asyncio/base_events.py", line 1860, in _run_once event_list = self._selector.select(timeout) File "/usr/lib/python3.10/selectors.py", line 469, in select fd_event_list = self._selector.poll(timeout, max_ev)

00prometheus commented 1 year ago

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?

00prometheus commented 1 year ago

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