vn.py官网
开源量化社区
Member
avatar
加入于:
帖子: 9
声望: 0

公共频道触发异常,类型:<class 'websocket._exceptions.WebSocketProtocolException'>,信息:Invalid close opcode.

description
寻求帮助怎么排除这个错误?

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

有个类似的帖子说给统一账户里充点钱就可以了. 这个办法也没有起到效果.

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

具体bug输出如下

qt.network.ssl: QSslSocket: cannot resolve SSL_CTX_set_ciphersuites
qt.network.ssl: QSslSocket: cannot resolve SSL_set_psk_use_session_callback
qt.network.ssl: QSslSocket: cannot call unresolved function SSL_set_psk_use_session_callback
qt.network.ssl: QSslSocket: cannot call unresolved function SSL_set_psk_use_session_callback
qt.network.ssl: QSslSocket: cannot call unresolved function SSL_set_psk_use_session_callback
qt.network.ssl: QSslSocket: cannot call unresolved function SSL_set_psk_use_session_callback


[2021-05-18T16:13:03.970900]: Unhandled WebSocket Error:<class 'websocket._excep
tions.WebSocketProtocolException'>
LastSentText:
{"op": "subscribe", "args": [{"channel": "instruments", "instType": "SPOT"}, {"c
hannel": "instruments", "instType": "SWAP"}, {"channel": "instruments", "instTyp
e": "FUTURES"}, {"channel": "instruments", "instType": "OPTION"}]}
LastReceivedText:
{"arg":{"channel":"instruments", "instType":"OPTION"},"data":[{"alias":"","baseC
cy":"","category":"1","ctMult":"0.1","ctType":"","ctVal":"1","ctValCcy":"BTC","e
xpTime":"1614931200000","instId":"BTC-USD-210305-47000-P","instType":"OPTION","l
ever":"","listTime":"1614753056162","lotSz":"1","minSz":"1","optType":"P","quote
Ccy":"","settleCcy":"BTC","state":"live","stk":"47000","tickSz":"0.0005","uly":"
BTC-USD"}, {"alias":"","baseCcy":"","category":"1","ctMult":"0.1","ctType":"","c
tVal":"1","ctValCcy":"BTC","expTime":"1632470400000","instId":"BTC-USD-210924-50
000-C","instType":"OPTION","lever":"","listTime":"1615537852387","lotSz":"1","mi
nSz":"1","optType":"C","quoteCcy":"","settleCcy":"BTC","state":"live","stk":"500
00","tickSz":"0.0005","uly":"BTC-USD"}, {"alias":"","baseCcy":"","category":"1",
"ctMult":"1","ctType":"","ctVal":"1","ctValCcy":"ETH","expTime":"1624608000000",
"instId":"ETH-USD-210625-360-C","instType":"OPTION","lever":"","listTime":"16092
46800000","lotSz":"1","minSz":"1","optTy
Exception trace:
Traceback (most recent call last):
Member
avatar
加入于:
帖子: 9
声望: 0


[2021-05-18T16:13:03.970900]: Unhandled WebSocket Error:<class 'websocket._excep
tions.WebSocketProtocolException'>
LastSentText:
{"op": "subscribe", "args": [{"channel": "instruments", "instType": "SPOT"}, {"c
hannel": "instruments", "instType": "SWAP"}, {"channel": "instruments", "instTyp
e": "FUTURES"}, {"channel": "instruments", "instType": "OPTION"}]}
LastReceivedText:
{"arg":{"channel":"instruments", "instType":"OPTION"},"data":[{"alias":"","baseC
cy":"","category":"1","ctMult":"0.1","ctType":"","ctVal":"1","ctValCcy":"BTC","e
xpTime":"1614931200000","instId":"BTC-USD-210305-47000-P","instType":"OPTION","l
ever":"","listTime":"1614753056162","lotSz":"1","minSz":"1","optType":"P","quote
Ccy":"","settleCcy":"BTC","state":"live","stk":"47000","tickSz":"0.0005","uly":"
BTC-USD"}, {"alias":"","baseCcy":"","category":"1","ctMult":"0.1","ctType":"","c
tVal":"1","ctValCcy":"BTC","expTime":"1632470400000","instId":"BTC-USD-210924-50
000-C","instType":"OPTION","lever":"","listTime":"1615537852387","lotSz":"1","mi
nSz":"1","optType":"C","quoteCcy":"","settleCcy":"BTC","state":"live","stk":"500
00","tickSz":"0.0005","uly":"BTC-USD"}, {"alias":"","baseCcy":"","category":"1",
"ctMult":"1","ctType":"","ctVal":"1","ctValCcy":"ETH","expTime":"1624608000000",
"instId":"ETH-USD-210625-360-C","instType":"OPTION","lever":"","listTime":"16092
46800000","lotSz":"1","minSz":"1","optTy
Exception trace:
Traceback (most recent call last):
  File "C:\vnstudio\lib\site-packages\vnpy\api\websocket\websocket_client.py", l
ine 200, in _run
    text = ws.recv()
  File "C:\vnstudio\lib\site-packages\websocket\_core.py", line 353, in recv
    opcode, data = self.recv_data()
  File "C:\vnstudio\lib\site-packages\websocket\_core.py", line 376, in recv_dat
a
    opcode, frame = self.recv_data_frame(control_frame)
  File "C:\vnstudio\lib\site-packages\websocket\_core.py", line 395, in recv_dat
a_frame
    frame = self.recv_frame()
  File "C:\vnstudio\lib\site-packages\websocket\_core.py", line 431, in recv_fra
me
    return self.frame_buffer.recv_frame()
  File "C:\vnstudio\lib\site-packages\websocket\_abnf.py", line 394, in recv_fra
me
    frame.validate(self.skip_utf8_validation)
  File "C:\vnstudio\lib\site-packages\websocket\_abnf.py", line 187, in validate

    raise WebSocketProtocolException("Invalid close opcode.")
websocket._exceptions.WebSocketProtocolException: Invalid close opcode.
Member
avatar
加入于:
帖子: 470
声望: 24

可以使用pip uninstall vnpy_okex/ pip install vnpy_okex重新安装一下试试看。
如果还是不行请打印self.ping_interval看一下。

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

你好, 青青子荆
重新安装了 vnpy_okex , 问题仍然没有解决. 请问 self.ping_interval 加载哪个文件下比较合适?
vnpy 架构的学习在哪里能找到资料?

Member
avatar
加入于:
帖子: 470
声望: 24

description
请看一下这里是否是20。
vnpy架构学习可参考https://www.vnpy.com/docs/cn/index.html

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

想问一下,这个问题解决了吗?

Member
avatar
加入于:
帖子: 2708
声望: 158

请参考7楼,看一下你的connect函数

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

感谢@青青子荆和其他小伙伴的热心帮助, 我查到问题点是这里造成的
self._last_received_text = text[:1000]
text字符串中是行情内容,贴4中 LastReceivedText: 长度44400个字节的json字符串被截断。
应该怎么解决求助?

description

description

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

C:\vnstudio\Lib\site-packages\vnpy\api\websocket\websocket_client.py
190:def _run(self):

C:\vnpy\Lib\site-packages\vnpy\api\websocket\websocket_client.py
321: def _record_last_received_text(self, text: str):

Member
avatar
加入于:
帖子: 2708
声望: 158

如果是报错Invalid close opcode,请参考一下7楼看一下你的connect函数,方便的话请贴个图吧

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

超时是因为在处理行情数据时候截断了行情数据, 进入了try分支终止了链接导致的超时。 具体代码参见10楼的贴图

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

沪公网安备 31011502017034号