From 81f61370fed36d64e116716a89031eea5e02d1a6 Mon Sep 17 00:00:00 2001 From: "2569718930@qq.com" <2569718930@qq.com> Date: Mon, 25 May 2026 07:35:19 +0800 Subject: [PATCH] =?UTF-8?q?=5Fbatch=5Fget=5Ftoken=5Fmarket=5Fdata=20?= =?UTF-8?q?=E6=89=B9=E9=87=8F=20WS=20=E9=A2=84=E7=83=AD=E8=AE=A2=E9=98=85?= =?UTF-8?q?=E9=81=BF=E5=85=8D=E5=85=A8=E5=86=B7=20REST=20=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/data_collection/polymarket_readonly.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/data_collection/polymarket_readonly.py b/src/data_collection/polymarket_readonly.py index 2deacbcc..cde85b01 100644 --- a/src/data_collection/polymarket_readonly.py +++ b/src/data_collection/polymarket_readonly.py @@ -2709,6 +2709,23 @@ class PolymarketReadOnlyLayer: if not missing: return results + # Pre-warm WS cache: subscribe all missing tokens at once, then + # wait briefly for the first quotes to arrive. Tokens that get + # WS data skip the REST fallback entirely. + self._ws_cache.subscribe(missing) + if self._ws_cache.enabled: + time.sleep(0.6) + for token_id in list(missing): + ws_data = self._ws_cache.get_market_data(token_id) + if ws_data: + with self._lock: + self._price_cache[token_id] = {"data": ws_data, "t": now} + results[token_id] = ws_data + missing.remove(token_id) + + if not missing: + return results + buy_map: Dict[str, float] = {} sell_map: Dict[str, float] = {} midpoint_map: Dict[str, float] = {}