Compare commits
No commits in common. "3e0fbec6da243d42721781cd2e085ea9c787d304" and "bb76f3c23974a02bed7de3990d04b0ff2529bc85" have entirely different histories.
3e0fbec6da
...
bb76f3c239
2
.gitignore
vendored
2
.gitignore
vendored
@ -157,5 +157,3 @@ 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():
|
def is_trading_time(self):
|
||||||
"""判断当前是否为交易时间
|
"""判断当前是否为交易时间
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
@ -152,7 +152,7 @@ class BaseTrader(ABC):
|
|||||||
now = dt.datetime.now()
|
now = dt.datetime.now()
|
||||||
|
|
||||||
# 先判断是否为交易日
|
# 先判断是否为交易日
|
||||||
if not BaseTrader.is_trading_date():
|
if not self.is_trading_date():
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# 判断是否在交易时间段内
|
# 判断是否在交易时间段内
|
||||||
@ -169,8 +169,7 @@ 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:
|
||||||
logger = get_logger("BaseTrader")
|
self.logger.error(f"判断交易时间发生错误: {str(e)}")
|
||||||
logger.error(f"判断交易时间发生错误: {str(e)}")
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -148,7 +148,9 @@ 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:
|
||||||
@ -186,4 +188,6 @@ class SimulationTrader(BaseTrader):
|
|||||||
}
|
}
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def is_trading_time(self):
|
||||||
|
return True
|
||||||
|
|
||||||
|
@ -293,7 +293,7 @@ def buy():
|
|||||||
}), 503
|
}), 503
|
||||||
|
|
||||||
# 检查是否在交易时间内
|
# 检查是否在交易时间内
|
||||||
if not BaseTrader.is_trading_time():
|
if not trader.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 BaseTrader.is_trading_time():
|
if not trader.is_trading_time():
|
||||||
logger.warning(
|
logger.warning(
|
||||||
f"交易失败 - 非交易时间不能交易 - 代码: {code}, 价格: {price}, 数量: {amount}"
|
f"交易失败 - 非交易时间不能交易 - 代码: {code}, 价格: {price}, 数量: {amount}"
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user