Runtime errors while running live strategy

hi @QN_Liza

when iam running my code I often get the following runtime errors:

wondered if these have ever been encountered before?
are there any upgrades of the rest api I need to upgrade to ?
#1
806 params = {‘models’: model}
807 self.handle_request(method=‘trading/subscribe’,
–> 808 params=params, protocol=‘post’)
809 if model == ‘Order’:
810 self.socket.on(‘Order’, self.on_order_update)

~\AppData\Local\Programs\Python\Python36-32\lib\site-packages\fxcmpy\fxcmpy.py in handle_request(self, method, params, protocol)
2426 self.logger.info(‘Connection status: %s’ % self.is_connected())
2427 self.logger.info(‘2. connection status: %s’ % self.connection_status)
-> 2428 self.logger.info(‘Socket state: %s’ % self.socket.connected)
2429 self.logger.info(‘Thread state: %s’ % self.socket_thread.is_alive())
2430 self.logger.info(‘Thread name: %s’ % self.socket_thread.name)

AttributeError: ‘NoneType’ object has no attribute ‘connected’

or sometimes we get

#2


ConnectionResetError Traceback (most recent call last)
~\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\packages\urllib3\connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
599 body=body, headers=headers,
–> 600 chunked=chunked)
601

~\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\packages\urllib3\connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
385 # otherwise it looks like a programming error was the cause.
–> 386 six.raise_from(e, None)
387 except (SocketTimeout, BaseSSLError, SocketError) as e:

~\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\packages\urllib3\packages\six.py in raise_from(value, from_value)

~\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\packages\urllib3\connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
381 try:
–> 382 httplib_response = conn.getresponse()
383 except Exception as e:

~\AppData\Local\Programs\Python\Python36-32\lib\http\client.py in getresponse(self)
1330 try:
-> 1331 response.begin()
1332 except ConnectionError:

~\AppData\Local\Programs\Python\Python36-32\lib\http\client.py in begin(self)
296 while True:
–> 297 version, status, reason = self._read_status()
298 if status != CONTINUE:

~\AppData\Local\Programs\Python\Python36-32\lib\http\client.py in _read_status(self)
257 def _read_status(self):
–> 258 line = str(self.fp.readline(_MAXLINE + 1), “iso-8859-1”)
259 if len(line) > _MAXLINE:

~\AppData\Local\Programs\Python\Python36-32\lib\socket.py in readinto(self, b)
585 try:
–> 586 return self._sock.recv_into(b)
587 except timeout:

~\AppData\Local\Programs\Python\Python36-32\lib\ssl.py in recv_into(self, buffer, nbytes, flags)
1008 self.class)
-> 1009 return self.read(nbytes, buffer)
1010 else:

~\AppData\Local\Programs\Python\Python36-32\lib\ssl.py in read(self, len, buffer)
870 try:
–> 871 return self._sslobj.read(len, buffer)
872 except SSLError as x:

~\AppData\Local\Programs\Python\Python36-32\lib\ssl.py in read(self, len, buffer)
630 if buffer is not None:
–> 631 v = self._sslobj.read(len, buffer)
632 else:

ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host

During handling of the above exception, another exception occurred:

ProtocolError Traceback (most recent call last)
~\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
422 retries=self.max_retries,
–> 423 timeout=timeout
424 )

~\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\packages\urllib3\connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
648 retries = retries.increment(method, url, error=e, _pool=self,
–> 649 _stacktrace=sys.exc_info()[2])
650 retries.sleep()

~\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\packages\urllib3\util\retry.py in increment(self, method, url, response, error, _pool, _stacktrace)
346 if read is False or not self._is_method_retryable(method):
–> 347 raise six.reraise(type(error), error, _stacktrace)
348 elif read is not None:

~\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\packages\urllib3\packages\six.py in reraise(tp, value, tb)
684 if value.traceback is not tb:
–> 685 raise value.with_traceback(tb)
686 raise value

~\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\packages\urllib3\connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
599 body=body, headers=headers,
–> 600 chunked=chunked)
601

~\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\packages\urllib3\connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
385 # otherwise it looks like a programming error was the cause.
–> 386 six.raise_from(e, None)
387 except (SocketTimeout, BaseSSLError, SocketError) as e:

~\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\packages\urllib3\packages\six.py in raise_from(value, from_value)

~\AppData\Local\Programs\Python\Python36-32\lib\site-packages\requests\packages\urllib3\connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
381 try:
–> 382 httplib_response = conn.getresponse()
383 except Exception as e:

~\AppData\Local\Programs\Python\Python36-32\lib\http\client.py in getresponse(self)
1330 try:
-> 1331 response.begin()
1332 except ConnectionError:

~\AppData\Local\Programs\Python\Python36-32\lib\http\client.py in begin(self)
296 while True:
–> 297 version, status, reason = self._read_status()
298 if status != CONTINUE:

~\AppData\Local\Programs\Python\Python36-32\lib\http\client.py in _read_status(self)
257 def _read_status(self):
–> 258 line = str(self.fp.readline(_MAXLINE + 1), “iso-8859-1”)
259 if len(line) > _MAXLINE:

~\AppData\Local\Programs\Python\Python36-32\lib\socket.py in readinto(self, b)
585 try:
–> 586 return self._sock.recv_into(b)
587 except timeout:

~\AppData\Local\Programs\Python\Python36-32\lib\ssl.py in recv_into(self, buffer, nbytes, flags)
1008 self.class)
-> 1009 return self.read(nbytes, buffer)
1010 else:

~\AppData\Local\Programs\Python\Python36-32\lib\ssl.py in read(self, len, buffer)
870 try:
–> 871 return self._sslobj.read(len, buffer)
872 except SSLError as x:

~\AppData\Local\Programs\Python\Python36-32\lib\ssl.py in read(self, len, buffer)
630 if buffer is not None:
–> 631 v = self._sslobj.read(len, buffer)
632 else:

ProtocolError: (‘Connection aborted.’, ConnectionResetError(10054, ‘An existing connection was forcibly closed by the remote host’, None, 10054, None))

During handling of the above exception, another exception occurred:

Hi @Femi.lewis, the first error looks like it’s from the part of your code which prints the connection status. I can’t see your code so I’m not sure what exactly the problem is.

The second error appears to be a connectivity issue. Are you connecting to the live server or the demo server?

Hi @QN_Liza it’s the demo server
Is the live server more stable ?
Femi

Also note it only crashes in both instances after about 4 hours
Femi

Ah okay, yes the demo server is less table than the live server as we naturally want to dedicate the most resources to the live server. But we regularly push updates to improve the demo server stability.
If you’re using fxcmpy, make sure you’re running the most up to date version by running pip install –U fxcmpy in your command prompt

1 Like

Thanks liza for the quick reply

Hi @QN_Liza
Regarding #1 the connection_reset error the erro code 10054 states the following:-

" this can be caused by the two sides of the connection disagreeing over whether the connection timed out or not during a keepalive. (Your code tries to reused the connection just as the server is closing it because it has been idle for too long.) You should basically just retry the operation over a new connection. (I’m surprised your library doesn’t do this automatically.)"

share|improve this answer