VeighNa量化社区
你的开源社区量化交易平台
Member
avatar
加入于:
帖子: 84
声望: 1

在onRspQryInstrument中加入save_json出现TypeError,
print("type:",type(symbol_contract_map))
save_json("contracts.json",symbol_contract_map)

Exception has occurred: TypeError (note: full exception trace is shown but execution is paused at: onRspQryInstrument)
Object of type ContractData is not JSON serializable
File "C:\veighna_studio\Lib\json\encoder.py", line 179, in default
raise TypeError(f'Object of type {o.class.name} '
File "C:\veighna_studio\Lib\json\encoder.py", line 438, in _iterencode
o = _default(o)
File "C:\veighna_studio\Lib\json\encoder.py", line 405, in _iterencode_dict
yield from chunks
File "C:\veighna_studio\Lib\json\encoder.py", line 431, in _iterencode
yield from _iterencode_dict(o, _current_indent_level)
File "C:\veighna_studio\Lib\json__init__.py", line 179, in dump
for chunk in iterable:
File "C:\veighna_studio\Lib\site-packages\vnpy\trader\utility.py", line 120, in save_json
json.dump(
File "C:\veighna_studio\Lib\site-packages\vnpy_ctp\gateway\ctp_gateway.py", line 636, in onRspQryInstrument (Current frame)
save_json("contracts.json",symbol_contract_map)

将symbol_contract_map定义改成
symbol_contract_map: dict = {}
后还是有同样的问题,不能理解,这是为什么呢?

Member
avatar
加入于:
帖子: 1638
声望: 119

symbol_contract_map中的value是ContracData对象,json无法直接序列化,换pickle存储即可

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

沪公网安备 31011502017034号

【用户协议】
【隐私政策】
【免责条款】