vn.py量化社区
By Traders, For Traders.
Member
avatar
加入于:
帖子: 44
声望: 3

事情经过如下,下午6点左右看社区有一个无法报单的帖子,为了演示正常,我在远程机登录并交易了一笔订单然后一直开着没管,刚才发现弹出了错误提示框,但主界面上行情依然在波动。

查看了出错的代码,应该是翻的不稳定导致的连接断开啥的,就是session请求出现了问题。然而,原始api代码中已经各种try了。所以才会使得主界面会在重连上后正常显示。
但是这个错误,已经被vnpy的错误引擎的拾取提示机制给拾取并弹出提醒导致(纯属猜测)。

错误代码如下:

Traceback (most recent call last):
  File "d:\anaconda3\lib\site-packages\urllib3\contrib\pyopenssl.py", line 485, in wrap_socket
    cnx.do_handshake()
  File "d:\anaconda3\lib\site-packages\OpenSSL\SSL.py", line 1934, in do_handshake
    self._raise_ssl_error(self._ssl, result)
  File "d:\anaconda3\lib\site-packages\OpenSSL\SSL.py", line 1663, in _raise_ssl_error
    raise SysCallError(errno, errorcode.get(errno))
OpenSSL.SSL.SysCallError: (10054, 'WSAECONNRESET')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "d:\anaconda3\lib\site-packages\urllib3\connectionpool.py", line 662, in urlopen
    self._prepare_proxy(conn)
  File "d:\anaconda3\lib\site-packages\urllib3\connectionpool.py", line 948, in _prepare_proxy
    conn.connect()
  File "d:\anaconda3\lib\site-packages\urllib3\connection.py", line 360, in connect
    ssl_context=context,
  File "d:\anaconda3\lib\site-packages\urllib3\util\ssl_.py", line 370, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "d:\anaconda3\lib\site-packages\urllib3\contrib\pyopenssl.py", line 491, in wrap_socket
    raise ssl.SSLError("bad handshake: %r" % e)
ssl.SSLError: ("bad handshake: SysCallError(10054, 'WSAECONNRESET')",)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "d:\anaconda3\lib\site-packages\requests\adapters.py", line 449, in send
    timeout=timeout
  File "d:\anaconda3\lib\site-packages\urllib3\connectionpool.py", line 720, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "d:\anaconda3\lib\site-packages\urllib3\util\retry.py", line 436, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='fapi.binance.com', port=443): Max retries exceeded with url: /fapi/v1/listenKey?listenKey=加密字串 (Caused by SSLError(SSLError("bad handshake: SysCallError(10054, 'WSAECONNRESET')")))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "d:\anaconda3\lib\site-packages\vnpy\api\rest\rest_client.py", line 262, in _process_request
    proxies=self.proxies,
  File "d:\anaconda3\lib\site-packages\requests\sessions.py", line 530, in request
    resp = self.send(prep, **send_kwargs)
  File "d:\anaconda3\lib\site-packages\requests\sessions.py", line 643, in send
    r = adapter.send(request, **kwargs)
  File "d:\anaconda3\lib\site-packages\requests\adapters.py", line 514, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='fapi.binance.com', port=443): Max retries exceeded with url: /fapi/v1/listenKey?listenKey=加密字串 (Caused by SSLError(SSLError("bad handshake: SysCallError(10054, 'WSAECONNRESET')")))
Administrator
avatar
加入于:
帖子: 4372
声望: 250

SSL签名错误,比较常见的原因是网络问题,不顾我们也发现Stackoverflow上有提到这可能是个OpenSSL的BUG,下个版本中会照着这个方案修复下

Administrator
avatar
加入于:
帖子: 4372
声望: 250

https://stackoverflow.com/questions/52501232/openssl-ssl-syscallerror-10054-wsaeconnreset-during-get-request-to-arcgis

参考资料地址,临时修复方法是修改vnpy/api/rest/rest_client.py。

在import requests这行下方加上:

requests.packages.urllib3.contrib.pyopenssl.extract_from_urllib3()
Member
avatar
加入于:
帖子: 44
声望: 3

very good!
非常酷和高效。

谢谢。

Member
avatar
加入于:
帖子: 44
声望: 3

再次测试,貌似并没有解决该问题。
同时,有时候会关闭报错窗口直接卡住然后崩溃。

ot connect to proxy.', ConnectionResetError(10054, '远程主机强迫关闭了一个现有的连接。', None, 10054, None)))
QWidget::repaint: Recursive repaint detected
QBackingStore::endPaint() called with active painter; did you forget to destroy it or call QPainter::end() on it?
Administrator
avatar
加入于:
帖子: 4372
声望: 250

ConnectionResetError这个确定是网络问题了,因为超时Socket连接被服务器那边关了,考虑换个网络环境吧。

Member
avatar
加入于:
帖子: 44
声望: 3

感谢陈总。现在我不纠结这个ConnectionResetError,
主要纠结的是,有时候出现ConnectionResetError时,关闭错误窗口引起的卡住然后崩溃的问题。

Administrator
avatar
加入于:
帖子: 4372
声望: 250

请在Github开个issue吧,我们后面来看下,这个卡住应该是报错频繁出现,导致的UI库问题

Member
avatar
加入于:
帖子: 27
声望: 0

确实在ConnectionResetError时,关闭错误窗口引起的卡住然后崩溃的问题,感觉最近还挺常见的

Member
加入于:
帖子: 4
声望: 0

我现在这里的币安没有办法,连接一天就掉线。

Member
加入于:
帖子: 4
声望: 0

用Python的交易员 wrote:

请在Github开个issue吧,我们后面来看下,这个卡住应该是报错频繁出现,导致的UI库问题
description
以下是日志信息:
2021-01-17 04:45:01,074 INFO: 委托失败,状态码:400,信息:{"code":-4003,"msg":"Quantity less than zero."}
2021-01-17 05:00:01,533 INFO: 委托失败,状态码:400,信息:{"code":-4003,"msg":"Quantity less than zero."}
2021-01-17 07:45:01,202 INFO: 委托失败,状态码:400,信息:{"code":-4003,"msg":"Quantity less than zero."}
2021-01-17 09:00:00,286 INFO: 委托失败,状态码:400,信息:{"code":-4003,"msg":"Quantity less than zero."}
这个我已经开了issue。请帮忙看一下呗

© 2015-2019 上海韦纳软件科技有限公司
备案服务号:沪ICP备18006526号-3