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

description

已经升级到最新版本了,用的腾讯云东京服务器

Administrator
avatar
加入于:
帖子: 4873
声望: 283

请选中后ctrl-C复制那条报错日志,然后粘贴到这里看下

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

用Python的交易员 wrote:

请选中后ctrl-C复制那条报错日志,然后粘贴到这里看下
私有频道触发异常,类型:<class 'IndexError'>,信息:list index out of range,就是这条主要的

Member
avatar
加入于:
帖子: 2643
声望: 157

请用run.py或者在cmd中用命令行python -m vnstation打开vnstation再复现一下操作看看底层报错。
这个报错是处理收到数据的时候的报错,需要看一下传过来的数据

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

xiaohe wrote:

请用run.py或者在cmd中用命令行python -m vnstation打开vnstation再复现一下操作看看底层报错。
这个报错是处理收到数据的时候的报错,需要看一下传过来的数据
IndexError: list index out of range
[2021-05-06T10:43:49.487827]: Unhandled WebSocket Error:<class 'IndexError'>
LastSentText:
{"op": "subscribe", "args": [{"channel": "orders", "instType": "ANY"}, {"channel": "account"}, {"channel": "positions", "instType": "ANY"}]}
LastReceivedText:
{"arg":{"channel":"account"},"data":[]}
Exception trace:
Traceback (most recent call last):
File "C:\vnstudio\lib\site-packages\vnpy\api\websocket\websocket_client.py", line 216, in _run
self.on_packet(data)
File "C:\vnstudio\lib\site-packages\vnpy_okex\okex_gateway.py", line 687, in on_packet
callback(packet)
File "C:\vnstudio\lib\site-packages\vnpy_okex\okex_gateway.py", line 745, in on_account
buf: dict = packet["data"][0]
IndexError: list index out of range
[2021-05-06T10:43:49.597202]: Unhandled WebSocket Error:<class 'IndexError'>
LastSentText:
{"op": "subscribe", "args": [{"channel": "orders", "instType": "ANY"}, {"channel": "account"}, {"channel": "positions", "instType": "ANY"}]}
LastReceivedText:
{"arg":{"channel":"account"},"data":[]}
Exception trace:
Traceback (most recent call last):
File "C:\vnstudio\lib\site-packages\vnpy\api\websocket\websocket_client.py", line 216, in _run
self.on_packet(data)
File "C:\vnstudio\lib\site-packages\vnpy_okex\okex_gateway.py", line 687, in on_packet
callback(packet)
File "C:\vnstudio\lib\site-packages\vnpy_okex\okex_gateway.py", line 745, in on_account
buf: dict = packet["data"][0]
IndexError: list index out of range
[2021-05-06T10:43:49.693365]: Unhandled WebSocket Error:<class 'IndexError'>
LastSentText:
{"op": "subscribe", "args": [{"channel": "orders", "instType": "ANY"}, {"channel": "account"}, {"channel": "positions", "instType": "ANY"}]}
LastReceivedText:
{"arg":{"channel":"account"},"data":[]}
Exception trace:
Traceback (most recent call last):
File "C:\vnstudio\lib\site-packages\vnpy\api\websocket\websocket_client.py", line 216, in _run
self.on_packet(data)
File "C:\vnstudio\lib\site-packages\vnpy_okex\okex_gateway.py", line 687, in on_packet
callback(packet)
File "C:\vnstudio\lib\site-packages\vnpy_okex\okex_gateway.py", line 745, in on_account
buf: dict = packet["data"][0]
IndexError: list index out of range

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

是这样的

Member
avatar
加入于:
帖子: 2643
声望: 157

可以在on_account函数下加一行试试看

if len(packet["data"]) == 0:
    return
Member
avatar
加入于:
帖子: 68
声望: 0

xiaohe wrote:

可以在on_account函数下加一行试试看
if len(packet["data"]) == 0: return请问是加在循环外还是循坏内,加在函数最下面吗,不好意思因为对这接口代码没有研究
def on_account(self, packet: dict) -> None:
"""资金更新推送"""
buf: dict = packet["data"][0]
for detail in buf["details"]:
account: AccountData = AccountData(
accountid=detail["ccy"],
balance=float(detail["eq"]),
gateway_name=self.gateway_name,
)
account.available = float(detail["availEq"])
account.frozen = account.balance - account.available
self.gateway.on_account(account)

Member
avatar
加入于:
帖子: 2643
声望: 157

description

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

石头2021 wrote:

xiaohe wrote:

可以在on_account函数下加一行试试看
if len(packet["data"]) == 0: return请问是加在循环外还是循坏内,加在函数最下面吗,不好意思因为对这接口代码没有研究
def on_account(self, packet: dict) -> None:
"""资金更新推送"""
buf: dict = packet["data"][0]
for detail in buf["details"]:
account: AccountData = AccountData(
accountid=detail["ccy"],
balance=float(detail["eq"]),
gateway_name=self.gateway_name,
)
account.available = float(detail["availEq"])
account.frozen = account.balance - account.available
self.gateway.on_account(account)

原来那个错误没有提示了,现在出现这个错误,
按ENTER行情查询的还是不行
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\vnstudio\lib\threading.py", line 917, in _bootstrap_inner
self.run()
File "C:\vnstudio\lib\threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "C:\vnstudio\lib\site-packages\vnpy\event\engine.py", line 60, in _run
self._process(event)
File "C:\vnstudio\lib\site-packages\vnpy\event\engine.py", line 73, in _process
[handler(event) for handler in self._handlers[event.type]]
File "C:\vnstudio\lib\site-packages\vnpy\event\engine.py", line 73, in <listcomp>
[handler(event) for handler in self._handlers[event.type]]
File "C:\vnstudio\lib\site-packages\vnpy\app\option_master\engine.py", line 206, in process_contract_event
portfolio.add_option(contract)
File "C:\vnstudio\lib\site-packages\vnpy\app\option_master\base.py", line 692, in add_option
option = OptionData(contract)
File "C:\vnstudio\lib\site-packages\vnpy\app\option_master\base.py", line 127, in init
contract.option_expiry
File "C:\vnstudio\lib\site-packages\vnpy\app\option_master\time.py", line 20, in calculate_days_to_expiry
while current_dt <= option_expiry:
TypeError: can't compare offset-naive and offset-aware datetimes

[2021-05-06T11:35:29.646131]: Unhandled WebSocket Error:<class 'websocket._exceptions.WebSocketProtocolException'>
LastSentText:
{"op": "subscribe", "args": [{"channel": "orders", "instType": "ANY"}, {"channel": "account"}, {"channel": "positions", "instType": "ANY"}]}
LastReceivedText:
{"arg":{"channel":"positions","instType":"ANY"},"data":[]}
Exception trace:
Traceback (most recent call last):
File "C:\vnstudio\lib\site-packages\vnpy\api\websocket\websocket_client.py", line 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_data
opcode, frame = self.recv_data_frame(control_frame)
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 395, in recv_data_frame
frame = self.recv_frame()
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 431, in recv_frame
return self.frame_buffer.recv_frame()
File "C:\vnstudio\lib\site-packages\websocket_abnf.py", line 394, in recv_frame
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.
[2021-05-06T11:35:29.669570]: Unhandled WebSocket Error:<class 'websocket._exceptions.WebSocketProtocolException'>
LastSentText:
{"op": "subscribe", "args": [{"channel": "instruments", "instType": "SPOT"}, {"channel": "instruments", "instType": "SWAP"}, {"channel": "instruments", "instType": "FUTURES"}, {"channel": "instruments", "instType": "OPTION"}]}
LastReceivedText:
{"arg":{"channel":"instruments", "instType":"OPTION"},"data":[{"alias":"","baseCcy":"","category":"1","ctMult":"0.1","ctType":"","ctVal":"1","ctValCcy":"BTC","expTime":"1614931200000","instId":"BTC-USD-210305-47000-P","instType":"OPTION","lever":"","listTime":"1614753056162","lotSz":"1","minSz":"1","optType":"P","quoteCcy":"","settleCcy":"BTC","state":"live","stk":"47000","tickSz":"0.0005","uly":"BTC-USD"}, {"alias":"","baseCcy":"","category":"1","ctMult":"0.1","ctType":"","ctVal":"1","ctValCcy":"BTC","expTime":"1620288000000","instId":"BTC-USD-210506-54000-C","instType":"OPTION","lever":"","listTime":"1620117033831","lotSz":"1","minSz":"1","optType":"C","quoteCcy":"","settleCcy":"BTC","state":"live","stk":"54000","tickSz":"0.0005","uly":"BTC-USD"}, {"alias":"","baseCcy":"","category":"1","ctMult":"0.1","ctType":"","ctVal":"1","ctValCcy":"BTC","expTime":"1632470400000","instId":"BTC-USD-210924-50000-C","instType":"OPTION","lever":"","listTime":"1615537852387","lotSz":"1","minSz":"1","o
Exception trace:
Traceback (most recent call last):
File "C:\vnstudio\lib\site-packages\vnpy\api\websocket\websocket_client.py", line 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_data
opcode, frame = self.recv_data_frame(control_frame)
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 395, in recv_data_frame
frame = self.recv_frame()
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 431, in recv_frame
return self.frame_buffer.recv_frame()
File "C:\vnstudio\lib\site-packages\websocket_abnf.py", line 394, in recv_frame
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.
[2021-05-06T11:36:30.021099]: Unhandled WebSocket Error:<class 'websocket._exceptions.WebSocketProtocolException'>
LastSentText:
{"op": "subscribe", "args": [{"channel": "orders", "instType": "ANY"}, {"channel": "account"}, {"channel": "positions", "instType": "ANY"}]}
LastReceivedText:
{"arg":{"channel":"positions","instType":"ANY"},"data":[]}
Exception trace:
Traceback (most recent call last):
File "C:\vnstudio\lib\site-packages\vnpy\api\websocket\websocket_client.py", line 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_data
opcode, frame = self.recv_data_frame(control_frame)
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 395, in recv_data_frame
frame = self.recv_frame()
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 431, in recv_frame
return self.frame_buffer.recv_frame()
File "C:\vnstudio\lib\site-packages\websocket_abnf.py", line 394, in recv_frame
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
加入于:
帖子: 2643
声望: 157

可以照着图上改改看

description

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

xiaohe wrote:

可以照着图上改改看

description

行情可以查询了,但是出现下面错误

Microsoft Windows [版本 10.0.14393]
(c) 2016 Microsoft Corporation。保留所有权利。

C:\Windows\system32>python -m vnstation
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-06T14:57:11.501062]: Unhandled WebSocket Error:<class 'websocket._exceptions.WebSocketProtocolException'>
LastSentText:
{"op": "subscribe", "args": [{"channel": "orders", "instType": "ANY"}, {"channel": "account"}, {"channel": "positions", "instType": "ANY"}]}
LastReceivedText:
{"arg":{"channel":"positions","instType":"ANY"},"data":[]}
Exception trace:
Traceback (most recent call last):
File "C:\vnstudio\lib\site-packages\vnpy\api\websocket\websocket_client.py", line 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_data
opcode, frame = self.recv_data_frame(control_frame)
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 395, in recv_data_frame
frame = self.recv_frame()
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 431, in recv_frame
return self.frame_buffer.recv_frame()
File "C:\vnstudio\lib\site-packages\websocket_abnf.py", line 394, in recv_frame
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.
[2021-05-06T14:57:11.532318]: Unhandled WebSocket Error:<class 'websocket._exceptions.WebSocketProtocolException'>
LastSentText:
{"op": "subscribe", "args": [{"channel": "instruments", "instType": "SPOT"}, {"channel": "instruments", "instType": "SWAP"}, {"channel": "instruments", "instType": "FUTURES"}, {"channel": "instruments", "instType": "OPTION"}]}
LastReceivedText:
{"arg":{"channel":"instruments", "instType":"OPTION"},"data":[{"alias":"","baseCcy":"","category":"1","ctMult":"0.1","ctType":"","ctVal":"1","ctValCcy":"BTC","expTime":"1614931200000","instId":"BTC-USD-210305-47000-P","instType":"OPTION","lever":"","listTime":"1614753056162","lotSz":"1","minSz":"1","optType":"P","quoteCcy":"","settleCcy":"BTC","state":"live","stk":"47000","tickSz":"0.0005","uly":"BTC-USD"}, {"alias":"","baseCcy":"","category":"1","ctMult":"0.1","ctType":"","ctVal":"1","ctValCcy":"BTC","expTime":"1620288000000","instId":"BTC-USD-210506-54000-C","instType":"OPTION","lever":"","listTime":"1620117033831","lotSz":"1","minSz":"1","optType":"C","quoteCcy":"","settleCcy":"BTC","state":"live","stk":"54000","tickSz":"0.0005","uly":"BTC-USD"}, {"alias":"","baseCcy":"","category":"1","ctMult":"0.1","ctType":"","ctVal":"1","ctValCcy":"BTC","expTime":"1632470400000","instId":"BTC-USD-210924-50000-C","instType":"OPTION","lever":"","listTime":"1615537852387","lotSz":"1","minSz":"1","o
Exception trace:
Traceback (most recent call last):
File "C:\vnstudio\lib\site-packages\vnpy\api\websocket\websocket_client.py", line 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_data
opcode, frame = self.recv_data_frame(control_frame)
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 395, in recv_data_frame
frame = self.recv_frame()
File "C:\vnstudio\lib\site-packages\websocket_core.py", line 431, in recv_frame
return self.frame_buffer.recv_frame()
File "C:\vnstudio\lib\site-packages\websocket_abnf.py", line 394, in recv_frame
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.
[
description

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

可能是连接问题,请问现在连接还是这样吗?

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

青青子荆 wrote:

可能是连接问题,请问现在连接还是这样吗?
嗯,还是这样的,余额和行情查询都是没问题,就一直跳出这两个异常然后断开再自动重连
description

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

OKEX连接成功后30s未订阅或订阅后30s内服务器未向用户推送数据,系统会自动断开连接。你报的这个错误可能是这个原因。

  1. 请问有没有对接口进行修改?
  2. 可以在对应的Websocket类下打印self.ping_interval看一下是20还是60。
  3. 可以从主界面的日志信息上看一下服务器时间和API服务器时间的偏差。
  4. 也可以观测一下Websocket类连接后的订阅情况。
Member
avatar
加入于:
帖子: 68
声望: 0

青青子荆 wrote:

OKEX连接成功后30s未订阅或订阅后30s内服务器未向用户推送数据,系统会自动断开连接。你报的这个错误可能是这个原因。

  1. 请问有没有对接口进行修改?
  2. 可以在对应的Websocket类下打印self.ping_interval看一下是20还是60。
  3. 可以从主界面的日志信息上看一下服务器时间和API服务器时间的偏差。
  4. 也可以观测一下Websocket类连接后的订阅情况。

按照帖子上面的内容修改过两行代码,然后self.ping_interval默认是20,然后Websocket_client文件下是默认是60,服务器时间偏差是0.03秒

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

请在对应的Websocket类打印一下实际的self.ping_interval看看是多少。
description

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

青青子荆 wrote:

请在对应的Websocket类打印一下实际的self.ping_interval看看是多少。
description
打印出来是60
description

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

这个数要小于30才可以。请贴一下你两个Websocket类下面的connect函数。

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

青青子荆 wrote:

这个数要小于30才可以。请贴一下你两个Websocket类下面的connect函数。
def connect(
self,
proxy_host: str,
proxy_port: int,
server: str
) -> None:
"""连接Websocket公共频道"""
if server == "REAL":
self.init(PUBLIC_WEBSOCKET_HOST, proxy_host, proxy_port)
else:
self.init(TEST_PUBLIC_WEBSOCKET_HOST, proxy_host, proxy_port)
print("ping_interval=",self.ping_interval)
self.start()

def connect(
self,
key: str,
secret: str,
passphrase: str,
proxy_host: str,
proxy_port: int,
server: str
) -> None:
"""连接Websocket私有频道"""
self.key = key
self.secret = secret.encode()
self.passphrase = passphrase

    self.connect_time = int(datetime.now().strftime("%y%m%d%H%M%S"))

    if server == "REAL":
        self.init(PRIVATE_WEBSOCKET_HOST, proxy_host, proxy_port)
    else:
        self.init(TEST_PRIVATE_WEBSOCKET_HOST, proxy_host, proxy_port)

    self.start()

是这样吗

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

沪公网安备 31011502017034号