feat: Add Polymarket wallet activity watcher and configure average price display thresholds.

This commit is contained in:
2569718930@qq.com
2026-03-10 13:23:35 +08:00
parent dd72e6a34b
commit f638850048
2 changed files with 35 additions and 3 deletions
+4
View File
@@ -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
@@ -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