忽略持仓数量和资金

This commit is contained in:
zhiyong 2025-06-04 11:24:21 +08:00
parent 48db0b7f4c
commit efbeb35d07

View File

@ -224,14 +224,14 @@ class RealTraderManager:
} }
try: try:
# 对于限价单,检查资金和持仓是否足够 # 对于限价单,进行订单可行性检查(当前已禁用资金和持仓限制)
if order_type == ORDER_TYPE_LIMIT and not self._check_order_feasibility( if order_type == ORDER_TYPE_LIMIT and not self._check_order_feasibility(
code, direction, amount, price code, direction, amount, price
): ):
logger.warning( logger.warning(
f"资金或持仓不足,忽略订单: {direction} {code} {amount}{price}" f"订单可行性检查失败,忽略订单: {direction} {code} {amount}{price}"
) )
return {"success": False, "error": "资金或持仓不足"} return {"success": False, "error": "订单可行性检查失败"}
# 下单 # 下单
logger.info( logger.info(
@ -356,7 +356,7 @@ class RealTraderManager:
self._lock.release() self._lock.release()
def _check_order_feasibility(self, code, direction, amount, price): def _check_order_feasibility(self, code, direction, amount, price):
"""检查订单是否可行(资金或持仓是否足够 """检查订单是否可行(已禁用资金和持仓检查,允许负数
Args: Args:
code: 股票代码 code: 股票代码
@ -365,51 +365,12 @@ class RealTraderManager:
price: 交易价格 price: 交易价格
Returns: Returns:
bool: 订单是否可行 bool: 订单是否可行始终返回True已禁用限制检查
""" """
try: # 不再检查资金和持仓限制,允许持仓数量和资金为负数
if direction == ORDER_DIRECTION_BUY: # 这样可以支持更灵活的交易策略,如融资融券、做空等场景
# 检查资金是否足够 logger.debug(f"订单可行性检查已禁用: {direction} {code} {amount}{price}元 - 允许执行")
balance = self.trader.get_balance() return True
if not balance:
logger.error("获取账户余额失败")
return False
# 计算所需资金加上3%的手续费作为缓冲)
required_cash = price * amount * 1.03
available_cash = balance.get("cash", 0)
if required_cash > available_cash:
logger.warning(
f"资金不足: 需要 {required_cash:.2f}, 可用 {available_cash:.2f}"
)
return False
return True
elif direction == "sell":
# 检查持仓是否足够
position = self.trader.get_position(code)
if not position:
logger.warning(f"没有持仓: {code}")
return False
available_volume = position.get("can_use_volume", 0)
if amount > available_volume:
logger.warning(
f"可用持仓不足: 需要 {amount}, 可用 {available_volume}"
)
return False
return True
return False
except Exception as e:
logger.error(f"检查订单可行性时发生异常: {str(e)}")
return False
def clean_expired_orders(self): def clean_expired_orders(self):
"""清理过期的未完成订单""" """清理过期的未完成订单"""