fix: 静态方法is_trading_time
This commit is contained in:
parent
9c93af0c3a
commit
3e0fbec6da
@ -142,7 +142,7 @@ class BaseTrader(ABC):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_trading_time(self):
|
def is_trading_time():
|
||||||
"""判断当前是否为交易时间
|
"""判断当前是否为交易时间
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
@ -152,7 +152,7 @@ class BaseTrader(ABC):
|
|||||||
now = dt.datetime.now()
|
now = dt.datetime.now()
|
||||||
|
|
||||||
# 先判断是否为交易日
|
# 先判断是否为交易日
|
||||||
if not self.is_trading_date():
|
if not BaseTrader.is_trading_date():
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# 判断是否在交易时间段内
|
# 判断是否在交易时间段内
|
||||||
@ -169,7 +169,8 @@ class BaseTrader(ABC):
|
|||||||
return is_morning_session or is_afternoon_session
|
return is_morning_session or is_afternoon_session
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(f"判断交易时间发生错误: {str(e)}")
|
logger = get_logger("BaseTrader")
|
||||||
|
logger.error(f"判断交易时间发生错误: {str(e)}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -148,8 +148,6 @@ class SimulationTrader(BaseTrader):
|
|||||||
self.logger.info(message)
|
self.logger.info(message)
|
||||||
return {"message": "模拟交易:查询今日委托未实现", "success": True}
|
return {"message": "模拟交易:查询今日委托未实现", "success": True}
|
||||||
|
|
||||||
def is_trading_time(self):
|
|
||||||
return True
|
|
||||||
|
|
||||||
def get_position(self, stock_code, strategy_name="default_strategy"):
|
def get_position(self, stock_code, strategy_name="default_strategy"):
|
||||||
"""查询指定股票代码的持仓信息
|
"""查询指定股票代码的持仓信息
|
||||||
@ -188,6 +186,4 @@ class SimulationTrader(BaseTrader):
|
|||||||
}
|
}
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def is_trading_time(self):
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
@ -293,7 +293,7 @@ def buy():
|
|||||||
}), 503
|
}), 503
|
||||||
|
|
||||||
# 检查是否在交易时间内
|
# 检查是否在交易时间内
|
||||||
if not trader.is_trading_time():
|
if not BaseTrader.is_trading_time():
|
||||||
logger.warning(
|
logger.warning(
|
||||||
f"交易失败 - 非交易时间不能交易 - 代码: {code}, 价格: {price}, 数量: {amount}"
|
f"交易失败 - 非交易时间不能交易 - 代码: {code}, 价格: {price}, 数量: {amount}"
|
||||||
)
|
)
|
||||||
@ -361,7 +361,7 @@ def sell():
|
|||||||
}), 503
|
}), 503
|
||||||
|
|
||||||
# 检查是否在交易时间内
|
# 检查是否在交易时间内
|
||||||
if not trader.is_trading_time():
|
if not BaseTrader.is_trading_time():
|
||||||
logger.warning(
|
logger.warning(
|
||||||
f"交易失败 - 非交易时间不能交易 - 代码: {code}, 价格: {price}, 数量: {amount}"
|
f"交易失败 - 非交易时间不能交易 - 代码: {code}, 价格: {price}, 数量: {amount}"
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user