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):