From 363cb17ea437a502d1777c34108e260816c05a6f Mon Sep 17 00:00:00 2001 From: zhiyong Date: Sat, 10 May 2025 23:39:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A6=82=E6=9E=9Cposition=20data=20=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=8D=E5=AD=98=E5=9C=A8,=20=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E5=AE=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/position_manager.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/position_manager.py b/src/position_manager.py index 8a50601..9198b80 100644 --- a/src/position_manager.py +++ b/src/position_manager.py @@ -31,6 +31,12 @@ class PositionManager: # 待处理订单信息 self.pending_orders = {} # {order_id -> LocalOrder} self.data_path = os.path.join(Config.DATA_DIR, self.strategy_name + "_positions.json") + # 确保数据目录存在 + os.makedirs(os.path.dirname(self.data_path), exist_ok=True) + # 如果文件不存在,创建一个空文件 + if not os.path.exists(self.data_path): + with open(self.data_path, 'w') as f: + f.write('{}') self.load_data() def update_position(self, code, direction, amount):