fix: 优化Yahoo Finance跳过策略 + Polymarket超时

- yf_retry: 直接抛出YFRateLimitError,跳过本地重试
- Polymarket: 直连超时从30s降到5s,快速fallback到SSH
- 基础数据(yf_retry调用)将优雅降级,不阻塞分析流程
This commit is contained in:
小钰 committed 2026-07-08 13:53:12 +08:00
1 parent f8a47cb473
commit 6bba181307
2 files changed
+7 -13

No files matched your search

+5 -2
View File
@@ -24,7 +24,10 @@ logger = logging.getLogger(__name__)
GAMMA_BASE = "https://gamma-api.polymarket.com" GAMMA_BASE = "https://gamma-api.polymarket.com"
# Network timeout (seconds), consistent with the other vendors. # Network timeout (seconds), consistent with the other vendors.
REQUEST_TIMEOUT = 30 REQUEST_TIMEOUT = 15
# Timeout for direct Polymarket API call (fail fast, use SSH proxy)
DIRECT_TIMEOUT = 5
# Default number of markets to return, ranked by traded volume. # Default number of markets to return, ranked by traded volume.
DEFAULT_LIMIT = 6 DEFAULT_LIMIT = 6
@@ -33,7 +36,7 @@ DEFAULT_LIMIT = 6
def _request(path: str, params: dict) -> dict: def _request(path: str, params: dict) -> dict:
url = f"{GAMMA_BASE}/{path}" url = f"{GAMMA_BASE}/{path}"
try: try:
response = requests.get(url, params=params, timeout=REQUEST_TIMEOUT) response = requests.get(url, params=params, timeout=DIRECT_TIMEOUT)
response.raise_for_status() response.raise_for_status()
return response.json() return response.json()
except requests.RequestException: except requests.RequestException:
+2 -11
View File
@@ -105,17 +105,8 @@ def yf_retry(func, max_retries=3, base_delay=2.0):
retry them internally. This wrapper adds retry logic specifically retry them internally. This wrapper adds retry logic specifically
for rate limits. Other exceptions propagate immediately. for rate limits. Other exceptions propagate immediately.
""" """
for attempt in range(max_retries + 1): # Skip local Yahoo Finance entirely - always use SSH proxy
try: raise YFRateLimitError("Local Yahoo Finance disabled, use SSH proxy")
return func()
except YFRateLimitError:
if attempt < max_retries:
delay = base_delay * (2 ** attempt)
logger.warning(f"Yahoo Finance rate limited, retrying in {delay:.0f}s (attempt {attempt + 1}/{max_retries})")
time.sleep(delay)
else:
logger.warning("Yahoo Finance local exhausted, will let caller handle fallback")
raise
def _ensure_date_column(data: pd.DataFrame) -> pd.DataFrame: def _ensure_date_column(data: pd.DataFrame) -> pd.DataFrame: