fix: healthcheck now tests geo-gate (POST /order) not just GET /markets
Two critical bugs fixed: 1. Old script tested GET /markets (no geo-block) -> UK node passed but couldn't actually place orders. Now tests POST /order (geo-blocked): 401/400 = passed geo-gate, 403 = blocked. 2. Old script only excluded US nodes -> UK/France/Germany/etc could be selected. Now uses ALLOWLIST (only JP/HK/KR/TW) instead of blocklist. Logic unchanged: if current node can place orders -> exit 0 (don't switch). Only switches when current node fails geo-gate, and only tries JP/HK/KR/TW nodes. Moved to host/ in git repo so it syncs with git pull.
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
#!/bin/bash
|
||||
# mihomo 代理健康检查 - Polymarket 专用
|
||||
# 逻辑:当前节点能下单就不换;不能下单就在日本/香港节点之间切换
|
||||
# cron 每 5 分钟跑一次
|
||||
|
||||
API="http://127.0.0.1:9090"
|
||||
PROXY="http://127.0.0.1:7890"
|
||||
|
||||
# 测试当前节点能否通过 Polymarket geo-gate(下单检测,不是读取检测)
|
||||
# 用 POST /order 测,403=被block,401=通过(到认证层了)
|
||||
test_geo() {
|
||||
code=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 -x $PROXY \
|
||||
-X POST "https://clob.polymarket.com/order" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{}' 2>/dev/null)
|
||||
# 401 = 通过 geo-gate(到认证层了),403 = 被 block
|
||||
if [ "$code" = "401" ] || [ "$code" = "400" ]; then
|
||||
return 0 # 能下单
|
||||
fi
|
||||
return 1 # 不能下单
|
||||
}
|
||||
|
||||
# 1. 测当前节点能不能下单
|
||||
if test_geo; then
|
||||
exit 0 # 能下单,不换
|
||||
fi
|
||||
|
||||
# 2. 不能下单,在日本和香港节点之间找能用的
|
||||
# 只选日本/香港/韩国/台湾(Polymarket 允许的地区)
|
||||
nodes=$(curl -s "$API/proxies" | python3 -c "
|
||||
import sys, json
|
||||
d = json.load(sys.stdin)
|
||||
skip = {'DIRECT','REJECT','自动选择','故障转移','良心云','GLOBAL',
|
||||
'剩余流量','套餐到期'}
|
||||
# 只允许的地区关键词
|
||||
allowed = ['日本', 'JP', 'Japan', '香港', 'HK', 'Hong Kong',
|
||||
'韩国', 'KR', 'Korea', '台湾', 'TW', 'Taiwan']
|
||||
for name, info in d.get('proxies', {}).items():
|
||||
if name in skip:
|
||||
continue
|
||||
if info.get('type') in ('Selector','URLTest','Fallback','LoadBalance'):
|
||||
continue
|
||||
# 只选允许地区的节点
|
||||
if not any(k in name for k in allowed):
|
||||
continue
|
||||
print(name)
|
||||
")
|
||||
|
||||
# 3. 逐个试,找到能下单的就切
|
||||
for node in $nodes; do
|
||||
curl -s -X PUT "$API/proxies/GLOBAL" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"name\":\"$node\"}" > /dev/null
|
||||
sleep 2
|
||||
if test_geo; then
|
||||
logger "mihomo-healthcheck: switched to $node (previous node geo-blocked)"
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
|
||||
logger "mihomo-healthcheck: ALL JP/HK nodes failed - check mihomo or subscription"
|
||||
exit 1
|
||||
Reference in New Issue
Block a user