fix 更新策略持仓
This commit is contained in:
parent
742a7a28df
commit
738bae5a4d
@ -162,12 +162,12 @@ def update_strategy_position(strategy_name, code, direction, amount):
|
||||
'total_amount': 0,
|
||||
'closeable_amount': 0
|
||||
}
|
||||
|
||||
# 直接使用交易实例返回的持仓数据更新策略持仓
|
||||
|
||||
# 直接使用实际持仓数据更新策略持仓
|
||||
strategy_positions[strategy_name][code]['total_amount'] = actual_total
|
||||
strategy_positions[strategy_name][code]['closeable_amount'] = actual_can_use
|
||||
|
||||
logger.info(f"更新策略持仓 - 策略: {strategy_name}, 代码: {code}, 总量: {strategy_positions[strategy_name][code]['total_amount']}, 可用: {strategy_positions[strategy_name][code]['closeable_amount']}")
|
||||
logger.info(f"更新策略持仓 - 策略: {strategy_name}, 代码: {code}, 方向: {direction}, 数量: {amount}, 总量: {strategy_positions[strategy_name][code]['total_amount']}, 可用: {strategy_positions[strategy_name][code]['closeable_amount']}")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"获取实际持仓失败: {str(e)}")
|
||||
@ -351,6 +351,9 @@ def should_use_simulation():
|
||||
def buy():
|
||||
"""Buy an item with given parameters."""
|
||||
logger.info("Received buy request")
|
||||
# 每次操作前更新未完成委托状态
|
||||
update_pending_orders()
|
||||
|
||||
# Get data from request body
|
||||
data = request.get_json()
|
||||
code = data.get("code")
|
||||
@ -453,6 +456,9 @@ def buy():
|
||||
def sell():
|
||||
"""Sell an item with given parameters."""
|
||||
logger.info("Received sell request")
|
||||
# 每次操作前更新未完成委托状态
|
||||
update_pending_orders()
|
||||
|
||||
# Get data from request body
|
||||
data = request.get_json()
|
||||
code = data.get("code")
|
||||
@ -591,15 +597,15 @@ def get_balance():
|
||||
def get_positions():
|
||||
"""Get the positions of the account."""
|
||||
logger.info("Received positions request")
|
||||
# 每次查询前更新未完成委托状态
|
||||
update_pending_orders()
|
||||
|
||||
try:
|
||||
# 获取查询参数中的策略名称
|
||||
strategy_name = request.args.get("strategy_name", "")
|
||||
|
||||
# 如果指定了策略名称,返回该策略的持仓
|
||||
if strategy_name:
|
||||
# 更新未完成委托状态
|
||||
update_pending_orders()
|
||||
|
||||
# 获取真实账户持仓,用于计算可交易量
|
||||
current_trader = get_trader()
|
||||
# get_trader 已经确保交易实例是登录状态的,无需再次检查
|
||||
|
Loading…
x
Reference in New Issue
Block a user