fix: 只有实盘在非交易时间不可用
This commit is contained in:
parent
d1edce5c94
commit
90691e84cf
@ -285,27 +285,29 @@ def buy():
|
||||
if order_type == ORDER_TYPE_LIMIT and (price <= 0 or amount <= 0):
|
||||
raise ValueError("Price and amount must be positive")
|
||||
|
||||
# 检查交易系统是否可用
|
||||
trader = get_trader()
|
||||
if is_real_mode() and not trader.is_available():
|
||||
return jsonify({
|
||||
"success": False,
|
||||
"error": trader.connection_error_message or "交易系统连接失败,请稍后再试"
|
||||
}), 503
|
||||
|
||||
# 检查是否在交易时间内
|
||||
if not BaseTrader.is_trading_time():
|
||||
logger.warning(
|
||||
f"交易失败 - 非交易时间不能交易 - 代码: {code}, 价格: {price}, 数量: {amount}"
|
||||
)
|
||||
return (
|
||||
jsonify(
|
||||
{"success": False, "error": f"交易失败: 非交易时间不能实盘交易"}
|
||||
),
|
||||
400,
|
||||
)
|
||||
|
||||
if is_real_mode():
|
||||
# 检查是否在交易时间内
|
||||
if not BaseTrader.is_trading_time():
|
||||
logger.warning(
|
||||
f"交易失败 - 非交易时间不能交易 - 代码: {code}, 价格: {price}, 数量: {amount}"
|
||||
)
|
||||
return (
|
||||
jsonify(
|
||||
{"success": False, "error": f"交易失败: 非交易时间不能实盘交易"}
|
||||
),
|
||||
400,
|
||||
)
|
||||
|
||||
# 检查交易系统是否可用
|
||||
if is_real_mode() and not trader.is_available():
|
||||
return jsonify({
|
||||
"success": False,
|
||||
"error": trader.connection_error_message or "交易系统连接失败,请稍后再试"
|
||||
}), 503
|
||||
|
||||
# 开始买入
|
||||
logger.info(
|
||||
f"使用RealTraderManager执行买入: 代码={code}, 价格={price}, 数量={amount}, 策略={strategy_name}"
|
||||
)
|
||||
@ -354,27 +356,29 @@ def sell():
|
||||
if order_type == ORDER_TYPE_LIMIT and (price <= 0 or amount <= 0):
|
||||
raise ValueError("Price and amount must be positive")
|
||||
|
||||
# 检查交易系统是否可用
|
||||
trader = get_trader()
|
||||
if is_real_mode() and not trader.is_available():
|
||||
return jsonify({
|
||||
"success": False,
|
||||
"error": trader.connection_error_message or "交易系统连接失败,请稍后再试"
|
||||
}), 503
|
||||
|
||||
# 检查是否在交易时间内
|
||||
if not BaseTrader.is_trading_time():
|
||||
logger.warning(
|
||||
f"交易失败 - 非交易时间不能交易 - 代码: {code}, 价格: {price}, 数量: {amount}"
|
||||
)
|
||||
return (
|
||||
jsonify(
|
||||
{"success": False, "error": f"交易失败: 非交易时间不能实盘交易"}
|
||||
),
|
||||
400,
|
||||
)
|
||||
|
||||
if is_real_mode():
|
||||
# 检查是否在交易时间内
|
||||
if not BaseTrader.is_trading_time():
|
||||
logger.warning(
|
||||
f"交易失败 - 非交易时间不能交易 - 代码: {code}, 价格: {price}, 数量: {amount}"
|
||||
)
|
||||
return (
|
||||
jsonify(
|
||||
{"success": False, "error": f"交易失败: 非交易时间不能实盘交易"}
|
||||
),
|
||||
400,
|
||||
)
|
||||
|
||||
# 检查交易系统是否可用
|
||||
if not trader.is_available():
|
||||
return jsonify({
|
||||
"success": False,
|
||||
"error": trader.connection_error_message or "交易系统连接失败,请稍后再试"
|
||||
}), 503
|
||||
|
||||
# 开始卖出
|
||||
logger.info(
|
||||
f"使用RealTraderManager执行卖出: 代码={code}, 价格={price}, 数量={amount}, 策略={strategy_name}"
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user