Files
polymarket-5min-15min-1hour…/btc-binary-VWAP-Momentum-bot/check_ws_proxy.py
T

66 lines
1.8 KiB
Python
Raw Normal View History

2026-07-26 22:56:35 +08:00
"""Quick diagnostics: proxy tunnel + RTDS / market WS connect test."""
import asyncio
import json
import os
import sys
from pathlib import Path
from dotenv import load_dotenv
load_dotenv(Path(__file__).parent / ".env")
from src.proxy_util import PROXY_URL, apply_proxy_env, ws_connect, ws_connect_kwargs
apply_proxy_env()
import websockets
print("=" * 70)
print("DIAGNOSTIC: WebSocket proxy tunnel")
print("=" * 70)
print(f" websockets : {getattr(websockets, '__version__', '?')}")
print(f" proxy : {PROXY_URL or '(none)'}")
print()
async def _probe(name: str, url: str, subscribe: dict | None = None) -> bool:
print(f"[{name}] {url}")
try:
async with ws_connect(url, **ws_connect_kwargs(), open_timeout=15) as ws:
print(f" connected")
if subscribe is not None:
await ws.send(json.dumps(subscribe))
msg = await asyncio.wait_for(ws.recv(), timeout=15)
print(f" first msg: {str(msg)[:120]!r}")
return True
except Exception as e:
print(f" FAIL {type(e).__name__}: {e}")
return False
async def main() -> int:
rtds_ok = await _probe(
"RTDS",
"wss://ws-live-data.polymarket.com",
{
"action": "subscribe",
"subscriptions": [
{"topic": "crypto_prices_chainlink", "type": "*", "filters": ""}
],
},
)
mkt_ok = await _probe(
"MARKET",
"wss://ws-subscriptions-clob.polymarket.com/ws/market",
)
print()
if rtds_ok and mkt_ok:
print("OK — both WebSockets work through proxy tunnel")
return 0
print("FAILED — check Clash HTTP port and .env HTTP_PROXY")
return 2
if __name__ == "__main__":
raise SystemExit(asyncio.run(main()))