Filter market pushes by local trading window
This commit is contained in:
@@ -448,17 +448,34 @@ def _shortlist_focus_payloads(
|
|||||||
payloads: List[Dict[str, Any]],
|
payloads: List[Dict[str, Any]],
|
||||||
*,
|
*,
|
||||||
top_n: int,
|
top_n: int,
|
||||||
|
for_push: bool = False,
|
||||||
) -> List[Dict[str, Any]]:
|
) -> List[Dict[str, Any]]:
|
||||||
ranked = sorted(
|
ranked = sorted(
|
||||||
payloads,
|
payloads,
|
||||||
key=lambda item: _market_monitor_score(item),
|
key=lambda item: _market_monitor_score(item),
|
||||||
reverse=True,
|
reverse=True,
|
||||||
)
|
)
|
||||||
return [
|
shortlisted: List[Dict[str, Any]] = []
|
||||||
item for item in ranked
|
for item in ranked:
|
||||||
if bool((item.get("market_snapshot") or {}).get("available"))
|
if not bool((item.get("market_snapshot") or {}).get("available")):
|
||||||
and _market_price_cap_ok(item, require_actionable_quote=True)
|
continue
|
||||||
][:top_n]
|
if not _market_price_cap_ok(item, require_actionable_quote=True):
|
||||||
|
continue
|
||||||
|
if for_push:
|
||||||
|
peak_context = _local_peak_context(item)
|
||||||
|
local_min = _minute_of_day(peak_context.get("local_time"))
|
||||||
|
minutes_to_peak = peak_context.get("minutes_to_peak")
|
||||||
|
if local_min is not None and local_min < 9 * 60:
|
||||||
|
continue
|
||||||
|
if isinstance(minutes_to_peak, int | float):
|
||||||
|
if minutes_to_peak > 360:
|
||||||
|
continue
|
||||||
|
if minutes_to_peak < -90:
|
||||||
|
continue
|
||||||
|
shortlisted.append(item)
|
||||||
|
if len(shortlisted) >= top_n:
|
||||||
|
break
|
||||||
|
return shortlisted
|
||||||
|
|
||||||
|
|
||||||
def _build_focus_digest_message(
|
def _build_focus_digest_message(
|
||||||
@@ -471,7 +488,7 @@ def _build_focus_digest_message(
|
|||||||
digest_interval = _format_interval_brief(
|
digest_interval = _format_interval_brief(
|
||||||
_env_int("TELEGRAM_MARKET_FOCUS_DIGEST_INTERVAL_SEC", 1800),
|
_env_int("TELEGRAM_MARKET_FOCUS_DIGEST_INTERVAL_SEC", 1800),
|
||||||
)
|
)
|
||||||
shortlisted = _shortlist_focus_payloads(payloads, top_n=top_n)
|
shortlisted = _shortlist_focus_payloads(payloads, top_n=top_n, for_push=True)
|
||||||
if not shortlisted:
|
if not shortlisted:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user