chore: staged changes
This commit is contained in:
1 parent
1d732844e3
commit
e7e01516ba
4 files changed
+473
-43
No files matched your search
@@ -34,10 +34,11 @@ from data.fetcher import BinanceDataFetcher
|
||||
from data.trading_db import TradingDatabase
|
||||
from api.models import PredictionModel
|
||||
from models.inference import get_inference_manager
|
||||
from utils.send_msg import lark_notifier
|
||||
|
||||
load_dotenv()
|
||||
|
||||
|
||||
|
||||
def setup_logging(log_dir: str = "logs", log_level: int = logging.INFO) -> logging.Logger:
|
||||
"""
|
||||
配置日志系统
|
||||
@@ -298,57 +299,62 @@ class PolymarketBTCTrader:
|
||||
|
||||
def get_market_by_slug(self, slug: str) -> Optional[Dict]:
|
||||
"""通过slug获取市场信息"""
|
||||
try:
|
||||
response = self.http.get(
|
||||
f"{self.GAMMA_API}/events",
|
||||
params={'slug': slug}
|
||||
)
|
||||
response.raise_for_status()
|
||||
events = response.json()
|
||||
for attempt in range(3):
|
||||
try:
|
||||
response = self.http.get(
|
||||
f"{self.GAMMA_API}/events",
|
||||
params={'slug': slug}
|
||||
)
|
||||
response.raise_for_status()
|
||||
events = response.json()
|
||||
|
||||
if not events:
|
||||
return None
|
||||
if not events:
|
||||
return None
|
||||
|
||||
event = events[0]
|
||||
markets = event.get('markets', [])
|
||||
event = events[0]
|
||||
markets = event.get('markets', [])
|
||||
|
||||
if not markets:
|
||||
return None
|
||||
if not markets:
|
||||
return None
|
||||
|
||||
market = markets[0]
|
||||
market = markets[0]
|
||||
|
||||
# outcomePrices可能是JSON字符串或列表
|
||||
outcome_prices_raw = market.get('outcomePrices', ['0', '0'])
|
||||
if isinstance(outcome_prices_raw, str):
|
||||
import json as _json
|
||||
try:
|
||||
outcome_prices_raw = _json.loads(outcome_prices_raw)
|
||||
except:
|
||||
outcome_prices_raw = ['0', '0']
|
||||
outcome_prices_raw = market.get('outcomePrices', ['0', '0'])
|
||||
if isinstance(outcome_prices_raw, str):
|
||||
import json as _json
|
||||
try:
|
||||
outcome_prices_raw = _json.loads(outcome_prices_raw)
|
||||
except:
|
||||
outcome_prices_raw = ['0', '0']
|
||||
|
||||
# clobTokenIds也可能是JSON字符串
|
||||
clob_tokens_raw = market.get('clobTokenIds', [])
|
||||
if isinstance(clob_tokens_raw, str):
|
||||
import json as _json
|
||||
try:
|
||||
clob_tokens_raw = _json.loads(clob_tokens_raw)
|
||||
except:
|
||||
clob_tokens_raw = []
|
||||
clob_tokens_raw = market.get('clobTokenIds', [])
|
||||
if isinstance(clob_tokens_raw, str):
|
||||
import json as _json
|
||||
try:
|
||||
clob_tokens_raw = _json.loads(clob_tokens_raw)
|
||||
except:
|
||||
clob_tokens_raw = []
|
||||
|
||||
return {
|
||||
'title': event.get('title', ''),
|
||||
'slug': slug,
|
||||
'question': market.get('question', ''),
|
||||
'condition_id': market.get('conditionId', ''),
|
||||
'outcomes': market.get('outcomes', []),
|
||||
'outcome_prices': [float(p) for p in outcome_prices_raw],
|
||||
'tokens': clob_tokens_raw,
|
||||
'end_date': event.get('endDate', ''),
|
||||
'closed': market.get('closed', False),
|
||||
}
|
||||
except Exception as e:
|
||||
logger.error(f"获取市场失败: {e}")
|
||||
return None
|
||||
return {
|
||||
'title': event.get('title', ''),
|
||||
'slug': slug,
|
||||
'question': market.get('question', ''),
|
||||
'condition_id': market.get('conditionId', ''),
|
||||
'outcomes': market.get('outcomes', []),
|
||||
'outcome_prices': [float(p) for p in outcome_prices_raw],
|
||||
'tokens': clob_tokens_raw,
|
||||
'end_date': event.get('endDate', ''),
|
||||
'closed': market.get('closed', False),
|
||||
}
|
||||
except Exception as e:
|
||||
logger.warning(f"尝试 {attempt+1}/3 获取市场失败: {e}")
|
||||
if attempt < 2:
|
||||
time.sleep(5) # 等待5秒后重试
|
||||
|
||||
lark_notifier.send_alert(f"Slug: {slug}","连续3次请求或解析发生异常,已放弃重试")
|
||||
return None
|
||||
|
||||
def get_current_hourly_market(self) -> Optional[Dict]:
|
||||
"""获取BTC市场"""
|
||||
|
||||
Reference in new issue
Block a user