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

StopOrder(vt_symbol='pp2309.DCE', direction=<Direction.LONG: '多'>, offset=<Offset.CLOSE: '平'>, price=7429.0, volume=1.0, stop_orderid='STOP.1', strategy_name='5', datetime=datetime.datetime(2023, 8, 7, 11, 8, 2, 204781, tzinfo=zoneinfo.ZoneInfo(key='Asia/Shanghai')), lock=False, net=False, vt_orderids=[], status=<StopOrderStatus.WAITING: '等待中'>)

停止单格式如上所示,保存到json时报错如下所示,咨询一下有什么好的方法把停止单保存到字典,开盘后再发出来吗?

Traceback (most recent call last):
  File "C:\veighna_studio\lib\site-packages\vnpy_ctastrategy\engine.py", line 887, in stop_all_strategies
    self.stop_strategy(strategy_name)
  File "C:\veighna_studio\lib\site-packages\vnpy_ctastrategy\engine.py", line 738, in stop_strategy
    self.sync_strategy_data(strategy)
  File "C:\veighna_studio\lib\site-packages\vnpy_ctastrategy\engine.py", line 842, in sync_strategy_data
    save_json(self.data_filename, self.strategy_data)
  File "C:\Users\784050800_1623449582\Desktop\vnpy-3.7.0\vnpy\trader\utility.py", line 118, in save_json
    json.dump(
  File "C:\veighna_studio\lib\json\__init__.py", line 179, in dump
    for chunk in iterable:
  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\encoder.py", line 405, in _iterencode_dict
    yield from chunks
  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 325, in _iterencode_list
    yield from chunks
  File "C:\veighna_studio\lib\json\encoder.py", line 438, in _iterencode
    o = _default(o)
  File "C:\veighna_studio\lib\json\encoder.py", line 179, in default
   raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type StopOrder is not JSON serializable
Member
avatar
加入于:
帖子: 1484
声望: 105

StopOrder这种对象可以用pickle模块来序列化

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

沪公网安备 31011502017034号

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