fix: 只有实盘在非交易时间不可用

This commit is contained in:
zhiyong 2025-05-13 00:31:00 +08:00
parent d1edce5c94
commit 90691e84cf

View File

@ -285,14 +285,9 @@ def buy():
if order_type == ORDER_TYPE_LIMIT and (price <= 0 or amount <= 0): if order_type == ORDER_TYPE_LIMIT and (price <= 0 or amount <= 0):
raise ValueError("Price and amount must be positive") raise ValueError("Price and amount must be positive")
# 检查交易系统是否可用
trader = get_trader() trader = get_trader()
if is_real_mode() and not trader.is_available():
return jsonify({
"success": False,
"error": trader.connection_error_message or "交易系统连接失败,请稍后再试"
}), 503
if is_real_mode():
# 检查是否在交易时间内 # 检查是否在交易时间内
if not BaseTrader.is_trading_time(): if not BaseTrader.is_trading_time():
logger.warning( logger.warning(
@ -305,7 +300,14 @@ def buy():
400, 400,
) )
if is_real_mode(): # 检查交易系统是否可用
if is_real_mode() and not trader.is_available():
return jsonify({
"success": False,
"error": trader.connection_error_message or "交易系统连接失败,请稍后再试"
}), 503
# 开始买入
logger.info( logger.info(
f"使用RealTraderManager执行买入: 代码={code}, 价格={price}, 数量={amount}, 策略={strategy_name}" f"使用RealTraderManager执行买入: 代码={code}, 价格={price}, 数量={amount}, 策略={strategy_name}"
) )
@ -354,14 +356,9 @@ def sell():
if order_type == ORDER_TYPE_LIMIT and (price <= 0 or amount <= 0): if order_type == ORDER_TYPE_LIMIT and (price <= 0 or amount <= 0):
raise ValueError("Price and amount must be positive") raise ValueError("Price and amount must be positive")
# 检查交易系统是否可用
trader = get_trader() trader = get_trader()
if is_real_mode() and not trader.is_available():
return jsonify({
"success": False,
"error": trader.connection_error_message or "交易系统连接失败,请稍后再试"
}), 503
if is_real_mode():
# 检查是否在交易时间内 # 检查是否在交易时间内
if not BaseTrader.is_trading_time(): if not BaseTrader.is_trading_time():
logger.warning( logger.warning(
@ -374,7 +371,14 @@ def sell():
400, 400,
) )
if is_real_mode(): # 检查交易系统是否可用
if not trader.is_available():
return jsonify({
"success": False,
"error": trader.connection_error_message or "交易系统连接失败,请稍后再试"
}), 503
# 开始卖出
logger.info( logger.info(
f"使用RealTraderManager执行卖出: 代码={code}, 价格={price}, 数量={amount}, 策略={strategy_name}" f"使用RealTraderManager执行卖出: 代码={code}, 价格={price}, 数量={amount}, 策略={strategy_name}"
) )