"""Push orchestration helpers. Separates eligibility / cooldown decisions from payload rendering and transport. """ from app.db.recommendation_queries import log_push, should_push from app.integrations.feishu_push import push_altcoin_tp_sl_alert, push_recommendation_state_alert def push_mainline_state_update(symbol: str, rec_id: int, mainline_item: dict, title_prefix: str | None = None, entry_push_type: str = "entry", watch_push_type: str = "watch_pool") -> bool: if not mainline_item or mainline_item.get("execution_status") not in ("buy_now", "wait_pullback"): status = mainline_item.get("execution_status") if mainline_item else "missing" print(f"[push] skip {symbol}: mainline_status={status}") return False push_type = entry_push_type if mainline_item.get("execution_status") == "buy_now" else watch_push_type action = mainline_item.get("action_status", "") if not should_push(symbol, push_type, action): print(f"⏭ 跳过推送({symbol}): {push_type}/{action} 12h冷却中") return False ok, resp = push_recommendation_state_alert(mainline_item, title_prefix=title_prefix) if ok: log_push(symbol, push_type, action, rec_id=rec_id) return True print(f"[push] failed {symbol}: {resp}") return False def push_trade_action_update(symbol: str, rec_id: int, state_decision: dict, final_action: str, push_type: str = "entry") -> bool: if not state_decision.get("push_required"): return False if not should_push(symbol, push_type, final_action): print(f"⏭ 跳过推送({symbol}): {push_type}/{final_action} 12h冷却中") return False ok, resp = push_altcoin_tp_sl_alert( state_decision["push_symbol"], state_decision["push_current_price"], state_decision["push_entry_price"], state_decision["push_pnl_pct"], final_action, state_decision.get("push_signals", []), state_decision.get("stop_loss", 0), state_decision.get("tp1", 0), state_decision.get("tp2", 0), ) if ok: log_push(symbol, push_type, final_action, rec_id=rec_id) return True print(f"飞书推送失败({symbol}): {resp}") return False