Compare commits
2 Commits
bb76f3c239
...
3e0fbec6da
Author | SHA1 | Date | |
---|---|---|---|
|
3e0fbec6da | ||
|
9c93af0c3a |
2
.gitignore
vendored
2
.gitignore
vendored
@ -157,3 +157,5 @@ cython_debug/
|
|||||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
#.idea/
|
||||||
|
|
||||||
|
Output/
|
@ -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,9 +148,7 @@ 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"):
|
||||||
"""查询指定股票代码的持仓信息
|
"""查询指定股票代码的持仓信息
|
||||||
Args:
|
Args:
|
||||||
@ -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