fix: per_stock_reassess NoneType比较bug(x3)
This commit is contained in:
@@ -94,28 +94,30 @@ def main():
|
||||
price = entry.get("current_price") or entry.get("price") or 0
|
||||
|
||||
# Price diff debounce: skip reassessment if price changed < 1% since last update
|
||||
last_price = entry.get("last_reassessed_price", 0)
|
||||
last_price = entry.get("last_reassessed_price") or 0
|
||||
if last_price > 0 and price > 0:
|
||||
diff_pct = abs(price - last_price) / last_price * 100
|
||||
if diff_pct < 1.0:
|
||||
print(f" 价差仅{diff_pct:.2f}% (<1%),跳过重评(上次价={last_price},现价={price})")
|
||||
skipped += 1
|
||||
continue
|
||||
# 打印参数调试
|
||||
print(f" DEBUG: code={code} name={entry.get('name','')} price={price} cost={entry.get('cost')} shares={entry.get('shares')} action={entry.get('action','')[:30]} is_wl={entry.get('type','') in ('自选策略','watchlist')}", flush=True)
|
||||
result = reassess_strategy(
|
||||
code=code,
|
||||
name=entry.get("name", ""),
|
||||
price=price,
|
||||
cost=entry.get("cost", 0),
|
||||
shares=entry.get("shares", 0),
|
||||
price=price or 0,
|
||||
cost=entry.get("cost") or 0,
|
||||
shares=entry.get("shares") or 0,
|
||||
current_action=entry.get("action", ""),
|
||||
is_watchlist=entry.get("type", "") in ("自选策略", "watchlist"),
|
||||
)
|
||||
if result and result.get("action"):
|
||||
# 持仓股止损不下移(移动止损规则):已有仓位的止损只上不下
|
||||
is_held = entry.get("cost", 0) > 0 and entry.get("shares", 0) > 0 and \
|
||||
is_held = (entry.get("cost") or 0) > 0 and (entry.get("shares") or 0) > 0 and \
|
||||
entry.get("type", "") not in ("自选策略", "watchlist")
|
||||
old_stop = entry.get("stop_loss", 0)
|
||||
new_stop = result.get("stop_loss", 0)
|
||||
old_stop = entry.get("stop_loss") or 0
|
||||
new_stop = result.get("stop_loss") or 0
|
||||
if is_held and old_stop > 0 and new_stop > 0 and new_stop < old_stop:
|
||||
print(f" 移动止损保护: {new_stop}→保持{old_stop} (持仓止损不下移)")
|
||||
result["stop_loss"] = old_stop
|
||||
@@ -202,6 +204,8 @@ def main():
|
||||
ok += 1
|
||||
except Exception as e:
|
||||
print(f"[ERROR] {code}: {e}", file=sys.stderr)
|
||||
import traceback
|
||||
traceback.print_exc(file=sys.stderr)
|
||||
errors += 1
|
||||
|
||||
# 同步自选股更新回 watchlist_stocks 表(持仓策略已通过 write_holding_strategy 写入 DB)
|
||||
|
||||
Reference in New Issue
Block a user