fix: 优化Yahoo Finance跳过策略 + Polymarket超时
- yf_retry: 直接抛出YFRateLimitError,跳过本地重试 - Polymarket: 直连超时从30s降到5s,快速fallback到SSH - 基础数据(yf_retry调用)将优雅降级,不阻塞分析流程
This commit is contained in:
1 parent
f8a47cb473
commit
6bba181307
2 files changed
+7
-13
No files matched your search
@@ -24,7 +24,10 @@ logger = logging.getLogger(__name__)
|
||||
GAMMA_BASE = "https://gamma-api.polymarket.com"
|
||||
|
||||
# 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_LIMIT = 6
|
||||
@@ -33,7 +36,7 @@ DEFAULT_LIMIT = 6
|
||||
def _request(path: str, params: dict) -> dict:
|
||||
url = f"{GAMMA_BASE}/{path}"
|
||||
try:
|
||||
response = requests.get(url, params=params, timeout=REQUEST_TIMEOUT)
|
||||
response = requests.get(url, params=params, timeout=DIRECT_TIMEOUT)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
except requests.RequestException:
|
||||
|
||||
@@ -105,17 +105,8 @@ def yf_retry(func, max_retries=3, base_delay=2.0):
|
||||
retry them internally. This wrapper adds retry logic specifically
|
||||
for rate limits. Other exceptions propagate immediately.
|
||||
"""
|
||||
for attempt in range(max_retries + 1):
|
||||
try:
|
||||
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
|
||||
# Skip local Yahoo Finance entirely - always use SSH proxy
|
||||
raise YFRateLimitError("Local Yahoo Finance disabled, use SSH proxy")
|
||||
|
||||
|
||||
def _ensure_date_column(data: pd.DataFrame) -> pd.DataFrame:
|
||||
|
||||
Reference in new issue
Block a user