fix bug
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
from datetime import datetime
|
||||
from functools import lru_cache
|
||||
import math
|
||||
|
||||
from libs import calc_buy_volume
|
||||
from sdk import OP_BUY
|
||||
@@ -13,44 +14,44 @@ import logging as log
|
||||
def open_signal(run: Runtime, ticks, open_signals) -> None:
|
||||
"""逐个验证开仓信号并提交买入委托。"""
|
||||
for item in open_signals:
|
||||
if item.last_close <= 0:
|
||||
log.info("[OpenSkip] %s 信号=%s,跳过:信号无效,last_close小于0", item.code, item.signal_key)
|
||||
continue
|
||||
|
||||
if item.code in run.account_cfg.excluded_codes:
|
||||
log.info("[OpenSkip] %s 信号=%s,跳过:已配置为排除股票", item.code, item.signal_key)
|
||||
continue
|
||||
|
||||
# 1. 验证信号配置允许开仓的时间区间。
|
||||
signal_config = run.global_cfg.signals.get(item.signal_key)
|
||||
if signal_config is None:
|
||||
log.info("[OpenSkip] %s 信号=%s,跳过:未找到信号配置",item.code,item.signal_key)
|
||||
continue
|
||||
|
||||
if not check_timezone(signal_config.timezone):
|
||||
log.info("[OpenSkip] %s 信号=%s,跳过:不在信号时间段(%s)",item.code,item.signal_key,signal_config.timezone)
|
||||
continue
|
||||
|
||||
# 2. 检查该证券是否已有买入委托锁,防止重复下单。
|
||||
if run.orders.busy(item.code, "BUY"):
|
||||
log.info("[OpenSkip] %s 信号=%s,跳过:买入委托处理中", item.code, item.signal_key)
|
||||
continue
|
||||
|
||||
# 3. 验证行情和最新价格是否有效。
|
||||
tick = ticks.get(item.code)
|
||||
price = tick.last_price if tick is not None else 0
|
||||
if price <= 0:
|
||||
log.info("[OpenSkip] %s 信号=%s,跳过:价格无效", item.code, item.signal_key)
|
||||
continue
|
||||
|
||||
# 5. 根据单笔买入金额计算整手开仓数量。
|
||||
volume = calc_buy_volume(price, run.account_cfg.buy_value)
|
||||
if volume <= 0:
|
||||
log.info("[OpenSkip] %s 信号=%s,跳过:数量无效", item.code, item.signal_key)
|
||||
continue
|
||||
|
||||
# 根据信号key做相关判断
|
||||
try:
|
||||
if not math.isfinite(item.last_close) or item.last_close <= 0:
|
||||
log.info("[OpenSkip] %s 信号=%s,跳过:信号无效,last_close不是有限正数", item.code, item.signal_key)
|
||||
continue
|
||||
|
||||
if item.code in run.account_cfg.excluded_codes:
|
||||
log.info("[OpenSkip] %s 信号=%s,跳过:已配置为排除股票", item.code, item.signal_key)
|
||||
continue
|
||||
|
||||
# 1. 验证信号配置允许开仓的时间区间。
|
||||
signal_config = run.global_cfg.signals.get(item.signal_key)
|
||||
if signal_config is None:
|
||||
log.info("[OpenSkip] %s 信号=%s,跳过:未找到信号配置",item.code,item.signal_key)
|
||||
continue
|
||||
|
||||
if not check_timezone(signal_config.timezone):
|
||||
log.info("[OpenSkip] %s 信号=%s,跳过:不在信号时间段(%s)",item.code,item.signal_key,signal_config.timezone)
|
||||
continue
|
||||
|
||||
# 2. 检查该证券是否已有买入委托锁,防止重复下单。
|
||||
if run.orders.busy(item.code, "BUY"):
|
||||
log.info("[OpenSkip] %s 信号=%s,跳过:买入委托处理中", item.code, item.signal_key)
|
||||
continue
|
||||
|
||||
# 3. 验证行情和最新价格是否有效。
|
||||
tick = ticks.get(item.code)
|
||||
price = tick.last_price if tick is not None else 0
|
||||
if not math.isfinite(price) or price <= 0:
|
||||
log.info("[OpenSkip] %s 信号=%s,跳过:价格无效", item.code, item.signal_key)
|
||||
continue
|
||||
|
||||
# 5. 根据单笔买入金额计算整手开仓数量。
|
||||
volume = calc_buy_volume(price, run.account_cfg.buy_value)
|
||||
if volume <= 0:
|
||||
log.info("[OpenSkip] %s 信号=%s,跳过:数量无效", item.code, item.signal_key)
|
||||
continue
|
||||
|
||||
# 根据信号key做相关判断
|
||||
# 早市信号,逢涨可买入
|
||||
if item.signal_key == "morning" and signal_config.gt_last_price_is_open:
|
||||
if price > item.last_close:
|
||||
@@ -68,9 +69,9 @@ def open_signal(run: Runtime, ticks, open_signals) -> None:
|
||||
do_open(run, item.code, volume, item.signal_key, price)
|
||||
|
||||
except RuntimeError as exc:
|
||||
log.exception("[OpenError] %s 信号=%s,买入=%d股失败:%s",item.code,item.signal_key,volume,exc)
|
||||
except Exception:
|
||||
log.exception("[OpenError] %s 信号=%s,买入=%d股异常",item.code,item.signal_key,volume)
|
||||
log.exception("[OpenRuntimeError] %s 信号=%s,失败:%s",item.code,item.signal_key,exc)
|
||||
except Exception as err:
|
||||
log.exception("[OpenExceptionError] %s 信号=%s,异常:%s",item.code,item.signal_key,err)
|
||||
continue
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user