From f638850048179da2ad74e5f2a7b3c1155b8d108f Mon Sep 17 00:00:00 2001 From: "2569718930@qq.com" <2569718930@qq.com> Date: Tue, 10 Mar 2026 13:23:35 +0800 Subject: [PATCH] feat: Add Polymarket wallet activity watcher and configure average price display thresholds. --- .env.example | 4 +++ .../polymarket_wallet_activity_watcher.py | 34 +++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index 472f61bd..53d3e7ca 100644 --- a/.env.example +++ b/.env.example @@ -64,3 +64,7 @@ POLYMARKET_WALLET_ACTIVITY_MIN_SIZE_DELTA=0.001 POLYMARKET_WALLET_ACTIVITY_MAX_CHANGES_PER_MSG=5 POLYMARKET_WALLET_ACTIVITY_NOTIFY_CLOSED=true POLYMARKET_WALLET_ACTIVITY_BOOTSTRAP_ALERT=false +POLYMARKET_WALLET_ACTIVITY_AVG_PRICE_SHOW_MIN=0.01 +POLYMARKET_WALLET_ACTIVITY_AVG_PRICE_SHOW_MAX=0.99 + + diff --git a/src/onchain/polymarket_wallet_activity_watcher.py b/src/onchain/polymarket_wallet_activity_watcher.py index 175cbdc9..2d16f469 100644 --- a/src/onchain/polymarket_wallet_activity_watcher.py +++ b/src/onchain/polymarket_wallet_activity_watcher.py @@ -3,6 +3,7 @@ import os import threading import time from datetime import datetime, timezone +from zoneinfo import ZoneInfo from typing import Any, Dict, List, Optional, Tuple import requests @@ -242,6 +243,21 @@ def _fmt_price(value: float) -> str: return f"{value:.3f}" +def _should_show_avg_price(avg_price: float) -> bool: + # Extreme prices near 0/1 are usually not informative for activity alerts. + min_show = max( + 0.0, + min(1.0, _env_float("POLYMARKET_WALLET_ACTIVITY_AVG_PRICE_SHOW_MIN", 0.01)), + ) + max_show = max( + 0.0, + min(1.0, _env_float("POLYMARKET_WALLET_ACTIVITY_AVG_PRICE_SHOW_MAX", 0.99)), + ) + if min_show > max_show: + min_show, max_show = max_show, min_show + return min_show <= avg_price <= max_show + + def _format_change_block( change_type: str, wallet: str, @@ -278,7 +294,9 @@ def _format_change_block( else: lines.append(f"Size: {_safe_float(pos.get('size')):.3f}") - lines.append(f"Avg Price: {_fmt_price(_safe_float(pos.get('avg_price')))}") + avg_price = _safe_float(pos.get("avg_price")) + if _should_show_avg_price(avg_price): + lines.append(f"Avg Price: {_fmt_price(avg_price)}") lines.append(f"Position Value: {_fmt_usd(_safe_float(pos.get('position_value')))}") pnl = _safe_float(pos.get("cash_pnl")) @@ -293,12 +311,16 @@ def _build_message( changes: List[Tuple[str, Dict[str, Any]]], max_changes: int, ) -> str: - now_utc = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S UTC") + now_bj = ( + datetime.now(timezone.utc) + .astimezone(ZoneInfo("Asia/Shanghai")) + .strftime("%Y-%m-%d %H:%M:%S") + ) shown = changes[:max_changes] lines = [f"🚨 Wallet Activity ({len(changes)} changes):", ""] for idx, (change_type, pos) in enumerate(shown): - lines.append(_format_change_block(change_type, wallet, pos, now_utc)) + lines.append(_format_change_block(change_type, wallet, pos, f"{now_bj} 北京时间")) if idx != len(shown) - 1: lines.append("") @@ -411,3 +433,9 @@ def start_polymarket_wallet_activity_loop(bot: Any) -> Optional[threading.Thread return thread + + + + + +