From 75e6f58a56630ada063bf6b0ea268df9399f68cc Mon Sep 17 00:00:00 2001 From: "2569718930@qq.com" <2569718930@qq.com> Date: Mon, 25 May 2026 16:53:20 +0800 Subject: [PATCH] =?UTF-8?q?SQLite=20=E5=BC=80=E5=90=AF=20WAL=20=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=20+=20busy=5Ftimeout=20=E8=A7=A3=E5=86=B3=E5=B9=B6?= =?UTF-8?q?=E8=A1=8C=E6=89=AB=E6=8F=8F=E5=86=99=E5=85=A5=E9=94=81=E5=86=B2?= =?UTF-8?q?=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scratch_query_gamma.py | 36 ++++++++++++++++++++++ scratch_query_slugs.py | 23 ++++++++++++++ scratch_search_markets.py | 43 ++++++++++++++++++++++++++ scratch_test.py | 62 -------------------------------------- src/database/db_manager.py | 5 ++- 5 files changed, 106 insertions(+), 63 deletions(-) create mode 100644 scratch_query_gamma.py create mode 100644 scratch_query_slugs.py create mode 100644 scratch_search_markets.py delete mode 100644 scratch_test.py diff --git a/scratch_query_gamma.py b/scratch_query_gamma.py new file mode 100644 index 00000000..c0868d3f --- /dev/null +++ b/scratch_query_gamma.py @@ -0,0 +1,36 @@ +import httpx + +gamma_url = "https://gamma-api.polymarket.com" + +# 1. Search markets +print("Searching markets for 'temperature'...") +try: + resp = httpx.get(f"{gamma_url}/markets", params={"active": "true", "search": "temperature", "limit": 100}, timeout=10.0) + data = resp.json() + print(f"Found {len(data)} markets matching 'temperature':") + for m in data[:10]: + print(f" - {m.get('question')} | Slug: {m.get('slug')}") +except Exception as e: + print("Error:", e) + +# 2. Search events +print("\nSearching events for 'temperature'...") +try: + resp = httpx.get(f"{gamma_url}/events", params={"active": "true", "search": "temperature", "limit": 100}, timeout=10.0) + data = resp.json() + print(f"Found {len(data)} events matching 'temperature':") + for e in data[:10]: + print(f" - {e.get('title')} | Slug: {e.get('slug')}") +except Exception as e: + print("Error:", e) + +# 3. Search events for 'weather' +print("\nSearching events for 'weather'...") +try: + resp = httpx.get(f"{gamma_url}/events", params={"active": "true", "search": "weather", "limit": 100}, timeout=10.0) + data = resp.json() + print(f"Found {len(data)} events matching 'weather':") + for e in data[:10]: + print(f" - {e.get('title')} | Slug: {e.get('slug')}") +except Exception as e: + print("Error:", e) diff --git a/scratch_query_slugs.py b/scratch_query_slugs.py new file mode 100644 index 00000000..0679ef9b --- /dev/null +++ b/scratch_query_slugs.py @@ -0,0 +1,23 @@ +import httpx + +gamma_url = "https://gamma-api.polymarket.com" + +cities = ["hong-kong", "beijing", "tokyo", "seoul", "shanghai"] +date_str = "may-25-2026" + +for city in cities: + slug = f"highest-temperature-in-{city}-on-{date_str}" + try: + resp = httpx.get(f"{gamma_url}/events", params={"slug": slug}, timeout=10.0) + data = resp.json() + print(f"Slug: {slug} -> Status: {resp.status_code}") + if data and isinstance(data, list): + print(f" Found Event: {data[0].get('title')} | ID: {data[0].get('id')}") + markets = data[0].get("markets", []) + print(f" Markets: {len(markets)}") + for m in markets: + print(f" - Market: {m.get('question')} | Group: {m.get('group_id')}") + else: + print(" No event found.") + except Exception as e: + print(f" Error for {slug}: {e}") diff --git a/scratch_search_markets.py b/scratch_search_markets.py new file mode 100644 index 00000000..679dcd8a --- /dev/null +++ b/scratch_search_markets.py @@ -0,0 +1,43 @@ +import httpx + +gamma_url = "https://gamma-api.polymarket.com" +all_markets = [] +offset = 0 +limit = 100 + +while True: + params = { + "archived": "false", + "limit": limit, + "offset": offset, + "active": "true", + "closed": "false" + } + try: + resp = httpx.get(f"{gamma_url}/markets", params=params, timeout=10.0) + batch = resp.json() + except Exception as e: + print("Fetch error:", e) + break + if not isinstance(batch, list) and isinstance(batch, dict): + batch = batch.get("markets", []) + if not batch: + break + all_markets.extend(batch) + if len(batch) < limit: + break + offset += len(batch) + +print(f"Total active markets: {len(all_markets)}") + +cities = ["beijing", "tokyo", "seoul", "shanghai", "singapore", "manila", "jakarta", "taipei", "hong kong", "busan", "shenzhen"] + +for city in cities: + matched = [] + for m in all_markets: + q = m.get("question", "").lower() + if city in q: + matched.append(m) + print(f"City '{city}': matched {len(matched)} active markets") + for m in matched: + print(f" - {m.get('question')} (slug: {m.get('slug')})") diff --git a/scratch_test.py b/scratch_test.py deleted file mode 100644 index 69e3217b..00000000 --- a/scratch_test.py +++ /dev/null @@ -1,62 +0,0 @@ -import sys -import time -import httpx -from loguru import logger - -logger.remove() -logger.add(sys.stdout, format="[{time:HH:mm:ss}] {message}") - -print("1. Testing direct httpx request to Gamma API...") -t0 = time.time() -try: - resp = httpx.get("https://gamma-api.polymarket.com/markets", params={"active": "true", "closed": "false", "limit": 200}, timeout=10.0) - print(f"Gamma response status: {resp.status_code}") - print(f"Gamma response took: {time.time() - t0:.2f}s") - markets = resp.json() - print(f"Markets count: {len(markets)}") -except Exception as e: - print(f"Failed to fetch from Gamma API: {e}") - -print("\n2. Testing loading PolymarketReadOnlyLayer...") -try: - from src.data_collection.polymarket_readonly import PolymarketReadOnlyLayer - layer = PolymarketReadOnlyLayer() - print(f"Polymarket layer enabled: {layer.enabled}") - - t0 = time.time() - print("Loading active markets via layer...") - m = layer._load_markets(active_only=True) - print(f"Layer active markets count: {len(m)} (took {time.time() - t0:.2f}s)") - - t0 = time.time() - print("Loading broad markets via layer...") - m_broad = layer._load_markets(active_only=False) - print(f"Layer broad markets count: {len(m_broad)} (took {time.time() - t0:.2f}s)") -except Exception as e: - print(f"Layer test failed: {e}") - -print("\n3. Testing scan terminal payload for East Asia cities...") -try: - from web.scan_terminal_service import _build_scan_terminal_payload_uncached - filters = { - "scan_mode": "tradable", - "min_price": 0.05, - "max_price": 0.95, - "min_edge_pct": 2.0, - "min_liquidity": 1000.0, - "high_liquidity_only": False, - "market_type": "maxtemp", - "time_range": "today", - "limit": 28, - "trading_region": "east_asia" - } - t0 = time.time() - res = _build_scan_terminal_payload_uncached(filters, force_refresh=True) - print(f"Build scan terminal payload for east_asia took {time.time() - t0:.2f}s") - print(f"Result Status: {res.get('status')}") - print(f"Result Rows count: {len(res.get('rows', []))}") - for row in res.get('rows', []): - print(f"- City: {row.get('city')}, Question: {row.get('market_question')}, Midpoint: {row.get('midpoint')}, IsPrimary: {row.get('is_primary_signal')}") -except Exception as e: - import traceback - traceback.print_exc() diff --git a/src/database/db_manager.py b/src/database/db_manager.py index 57fd2e63..eac451fa 100644 --- a/src/database/db_manager.py +++ b/src/database/db_manager.py @@ -27,7 +27,10 @@ class DBManager: return raw def _get_connection(self): - return sqlite3.connect(self.db_path) + conn = sqlite3.connect(self.db_path, timeout=10) + conn.execute("PRAGMA journal_mode=WAL") + conn.execute("PRAGMA busy_timeout=5000") + return conn def _init_cache_key(self) -> str: return os.path.abspath(self.db_path)