如果position data 文件不存在, 创建它

This commit is contained in:
zhiyong 2025-05-10 23:39:11 +08:00
parent ffb2952fce
commit 363cb17ea4

View File

@ -31,6 +31,12 @@ class PositionManager:
# 待处理订单信息 # 待处理订单信息
self.pending_orders = {} # {order_id -> LocalOrder} self.pending_orders = {} # {order_id -> LocalOrder}
self.data_path = os.path.join(Config.DATA_DIR, self.strategy_name + "_positions.json") 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() self.load_data()
def update_position(self, code, direction, amount): def update_position(self, code, direction, amount):