在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 = {}
后还是有同样的问题,不能理解,这是为什么呢?