🏗️ 项目重构:模块化清理完成
This commit is contained in:
196
modules/documentation-suite/docs/rapidapi/api_inventory.md
Normal file
196
modules/documentation-suite/docs/rapidapi/api_inventory.md
Normal file
@@ -0,0 +1,196 @@
|
||||
# RapidAPI 订阅清单
|
||||
|
||||
## 📋 概览
|
||||
|
||||
基于Doppler配置和实际测试,记录当前RapidAPI订阅的API服务及其可用性。
|
||||
|
||||
**API密钥**: `[REDACTED - 从Doppler获取RAPIDAPI_KEY]`
|
||||
**总订阅数**: 17个API服务
|
||||
**最后更新**: 2025-08-02
|
||||
|
||||
## ✅ 已验证可用的API (4个)
|
||||
|
||||
### 1. Alpha Vantage (`alpha-vantage.p.rapidapi.com`) ⚡
|
||||
- **状态**: ✅ 可用 (响应时间: 1.26s)
|
||||
- **用途**: 股票基本面数据、财报数据
|
||||
- **测试结果**: 成功获取AAPL全球报价数据
|
||||
- **数据字段**: Global Quote
|
||||
- **端点**:
|
||||
- `/query?function=GLOBAL_QUOTE&symbol={symbol}` - 实时报价
|
||||
- `/query?function=OVERVIEW&symbol={symbol}` - 公司概览
|
||||
- `/query?function=EARNINGS&symbol={symbol}` - 财报数据
|
||||
|
||||
### 2. Webull (`webull.p.rapidapi.com`) ⚡
|
||||
- **状态**: ✅ 可用 (响应时间: 1.56s)
|
||||
- **用途**: 股票搜索、报价
|
||||
- **测试结果**: 成功获取AAPL搜索数据
|
||||
- **数据字段**: stocks, busiModel
|
||||
- **端点**:
|
||||
- `/stock/search?keyword={symbol}` - 股票搜索
|
||||
- `/market/get-active-gainers` - 活跃涨幅股
|
||||
|
||||
### 3. Yahoo Finance 15 (`yahoo-finance15.p.rapidapi.com`)
|
||||
- **状态**: ✅ 可用 (响应时间: 2.07s)
|
||||
- **用途**: 实时股价、市场数据
|
||||
- **测试结果**: 成功获取AAPL报价数据
|
||||
- **数据字段**: meta, body
|
||||
- **端点**:
|
||||
- `/api/yahoo/qu/quote/{symbol}` - 股票报价
|
||||
- `/api/yahoo/co/collections/day_gainers` - 涨幅榜
|
||||
- `/api/yahoo/co/collections/day_losers` - 跌幅榜
|
||||
|
||||
### 4. Seeking Alpha (`seeking-alpha.p.rapidapi.com`)
|
||||
- **状态**: ✅ 可用 (响应时间: 3.32s)
|
||||
- **用途**: 股票分析、新闻
|
||||
- **测试结果**: 成功获取AAPL分析数据
|
||||
- **数据字段**: data
|
||||
- **端点**:
|
||||
- `/symbols/get-profile?symbols={symbol}` - 股票档案
|
||||
- `/news/list?category=market-news` - 市场新闻
|
||||
|
||||
## ❌ 未订阅或失败的API (13个)
|
||||
|
||||
### 权限问题 (403 Forbidden)
|
||||
以下API显示"You are not subscribed to this API",表示未订阅:
|
||||
|
||||
- **yahoo_finance_api_data** (`yahoo-finance-api1.p.rapidapi.com`)
|
||||
- **yahoo_finance_basic** (`yahoo-finance127.p.rapidapi.com`)
|
||||
- **morning_star** (`morningstar1.p.rapidapi.com`)
|
||||
- **investing_com** (`investing-cryptocurrency-markets.p.rapidapi.com`)
|
||||
- **finance_api** (`real-time-finance-data.p.rapidapi.com`)
|
||||
|
||||
### API不存在 (404 Not Found)
|
||||
以下API显示"API doesn't exists",可能已下线:
|
||||
|
||||
- **yahoo_finance_realtime** (`yahoo-finance-low-latency.p.rapidapi.com`)
|
||||
- **tradingview** (`tradingview-ta.p.rapidapi.com`)
|
||||
- **sec_filings** (`sec-filings.p.rapidapi.com`)
|
||||
|
||||
### 端点错误 (404 Endpoint Not Found)
|
||||
以下API存在但端点路径不正确:
|
||||
|
||||
- **yh_finance** (`yh-finance-complete.p.rapidapi.com`)
|
||||
- **ms_finance** (`ms-finance.p.rapidapi.com`)
|
||||
- **exchangerate_api** (`exchangerate-api.p.rapidapi.com`)
|
||||
- **crypto_news** (`cryptocurrency-news2.p.rapidapi.com`)
|
||||
|
||||
### 无响应数据 (204 No Content)
|
||||
- **yh_finance_complete** (`yh-finance.p.rapidapi.com`) - 返回空响应
|
||||
|
||||
## 🔄 需要进一步测试的API
|
||||
|
||||
### 8. YH Finance Complete (`yh-finance.p.rapidapi.com`)
|
||||
- **状态**: 🟡 待测试
|
||||
- **用途**: 完整的Yahoo Finance数据
|
||||
|
||||
### 9. Yahoo Finance API Data (`yahoo-finance-api1.p.rapidapi.com`)
|
||||
- **状态**: 🟡 待测试
|
||||
- **用途**: Yahoo Finance API数据
|
||||
|
||||
### 10. Yahoo Finance Low Latency (`yahoo-finance-low-latency.p.rapidapi.com`)
|
||||
- **状态**: 🟡 待测试
|
||||
- **用途**: 低延迟实时数据
|
||||
|
||||
### 11. YH Finance Complete (`yh-finance-complete.p.rapidapi.com`)
|
||||
- **状态**: 🟡 待测试
|
||||
- **用途**: 完整金融数据
|
||||
|
||||
### 12. Yahoo Finance 127 (`yahoo-finance127.p.rapidapi.com`)
|
||||
- **状态**: 🟡 待测试
|
||||
- **用途**: Yahoo Finance基础数据
|
||||
|
||||
### 13. Real Time Finance Data (`real-time-finance-data.p.rapidapi.com`)
|
||||
- **状态**: 🟡 待测试
|
||||
- **用途**: 实时金融数据
|
||||
|
||||
### 14. MS Finance (`ms-finance.p.rapidapi.com`)
|
||||
- **状态**: 🟡 待测试
|
||||
- **用途**: 微软金融数据
|
||||
|
||||
### 15. SEC Filings (`sec-filings.p.rapidapi.com`)
|
||||
- **状态**: 🟡 待测试
|
||||
- **用途**: SEC文件数据
|
||||
|
||||
### 16. ExchangeRate API (`exchangerate-api.p.rapidapi.com`)
|
||||
- **状态**: 🟡 待测试
|
||||
- **用途**: 汇率数据
|
||||
|
||||
### 17. Cryptocurrency News 2 (`cryptocurrency-news2.p.rapidapi.com`)
|
||||
- **状态**: 🟡 待测试
|
||||
- **用途**: 加密货币新闻
|
||||
|
||||
## 📊 使用统计
|
||||
|
||||
### 成功率分析
|
||||
- **可用API**: 4/17 (23.5%)
|
||||
- **未订阅API**: 5/17 (29.4%)
|
||||
- **API不存在**: 3/17 (17.6%)
|
||||
- **端点错误**: 4/17 (23.5%)
|
||||
- **其他问题**: 1/17 (5.9%)
|
||||
|
||||
### 八仙论道中的API使用情况
|
||||
- **吕洞宾**: Alpha Vantage ✅
|
||||
- **何仙姑**: Yahoo Finance 15 ✅
|
||||
- **张果老**: Seeking Alpha ✅
|
||||
- **韩湘子**: 多个API失败 ❌
|
||||
- **汉钟离**: 多个API失败 ❌
|
||||
- **蓝采和**: Webull ✅
|
||||
- **曹国舅**: Seeking Alpha ✅
|
||||
- **铁拐李**: 多个API失败 ❌
|
||||
|
||||
## 🔧 优化建议
|
||||
|
||||
### 1. 端点配置优化
|
||||
- 需要为每个API配置正确的端点路径
|
||||
- 研究各API的具体参数要求
|
||||
- 添加更多数据类型的端点映射
|
||||
|
||||
### 2. 故障转移策略
|
||||
- 优先使用已验证可用的API
|
||||
- 将Yahoo Finance系列API作为主要数据源
|
||||
- Alpha Vantage作为基本面数据的首选
|
||||
|
||||
### 3. API测试计划
|
||||
- 逐个测试待测试的API
|
||||
- 记录每个API的具体用法和限制
|
||||
- 建立API健康检查机制
|
||||
|
||||
## 📝 测试记录
|
||||
|
||||
### 2025-08-02 全面测试记录
|
||||
```
|
||||
✅ alpha_vantage: 1.26s - 成功获取AAPL全球报价
|
||||
✅ webull: 1.56s - 成功获取AAPL搜索数据
|
||||
✅ yahoo_finance_1: 2.07s - 成功获取AAPL报价数据
|
||||
✅ seeking_alpha: 3.32s - 成功获取AAPL分析数据
|
||||
|
||||
❌ yahoo_finance_api_data: 403 - 未订阅
|
||||
❌ yahoo_finance_basic: 403 - 未订阅
|
||||
❌ morning_star: 403 - 未订阅
|
||||
❌ investing_com: 403 - 未订阅
|
||||
❌ finance_api: 403 - 未订阅
|
||||
|
||||
❌ yahoo_finance_realtime: 404 - API不存在
|
||||
❌ tradingview: 404 - API不存在
|
||||
❌ sec_filings: 404 - API不存在
|
||||
|
||||
❌ yh_finance: 404 - 端点不存在
|
||||
❌ ms_finance: 404 - 端点不存在
|
||||
❌ exchangerate_api: 404 - 端点不存在
|
||||
❌ crypto_news: 404 - 端点不存在
|
||||
|
||||
❌ yh_finance_complete: 204 - 无响应数据
|
||||
```
|
||||
|
||||
## 🚀 下一步行动
|
||||
|
||||
1. **完善端点配置**: 为所有API添加正确的端点映射
|
||||
2. **批量测试**: 使用自动化脚本测试所有待测试API
|
||||
3. **文档更新**: 根据测试结果更新此文档
|
||||
4. **性能优化**: 基于可用性调整八仙论道的API分配策略
|
||||
|
||||
---
|
||||
|
||||
**维护者**: Ben
|
||||
**联系方式**: 通过Doppler配置管理API密钥
|
||||
**更新频率**: 每次API测试后更新
|
||||
@@ -0,0 +1,341 @@
|
||||
# 🏛️ 稷下学宫八仙论道负载分担策略
|
||||
|
||||
## 📋 概述
|
||||
|
||||
基于现有的RapidAPI订阅和雅虎财经数据接口,设计一套智能负载分担策略,让八仙论道系统中的不同角色调用不同的API端点获取相同类型的数据,实现API负载均衡和系统稳定性。
|
||||
|
||||
## 🎯 核心理念
|
||||
|
||||
**"同样的数据,不同的路径"** - 通过多API轮换获取相同类型的市场数据,避免单一API过载,确保系统稳定运行。
|
||||
|
||||
## 📊 可用API资源清单
|
||||
|
||||
### ✅ 已验证可用的API (4个)
|
||||
|
||||
```python
|
||||
AVAILABLE_APIS = {
|
||||
'alpha_vantage': {
|
||||
'host': 'alpha-vantage.p.rapidapi.com',
|
||||
'response_time': 1.26,
|
||||
'rate_limit': '500/min, 500k/month',
|
||||
'specialty': ['stock_quote', 'company_overview', 'earnings']
|
||||
},
|
||||
'yahoo_finance_15': {
|
||||
'host': 'yahoo-finance15.p.rapidapi.com',
|
||||
'response_time': 2.07,
|
||||
'rate_limit': '500/min, 500k/month',
|
||||
'specialty': ['stock_quote', 'market_movers', 'news']
|
||||
},
|
||||
'webull': {
|
||||
'host': 'webull.p.rapidapi.com',
|
||||
'response_time': 1.56,
|
||||
'rate_limit': '500/min, 500k/month',
|
||||
'specialty': ['stock_search', 'market_gainers']
|
||||
},
|
||||
'seeking_alpha': {
|
||||
'host': 'seeking-alpha.p.rapidapi.com',
|
||||
'response_time': 3.32,
|
||||
'rate_limit': '500/min, 500k/month',
|
||||
'specialty': ['company_profile', 'market_analysis']
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 🎭 八仙负载分担配置
|
||||
|
||||
### 数据类型映射策略
|
||||
|
||||
```python
|
||||
DATA_TYPE_API_MAPPING = {
|
||||
# 股票报价数据 - 3个API可提供
|
||||
'stock_quote': {
|
||||
'吕洞宾': 'alpha_vantage', # 主力剑仙用最快的API
|
||||
'何仙姑': 'yahoo_finance_15', # 风控专家用稳定的API
|
||||
'张果老': 'webull', # 技术分析师用搜索强的API
|
||||
'韩湘子': 'alpha_vantage', # 基本面研究用专业API
|
||||
'汉钟离': 'yahoo_finance_15', # 量化专家用市场数据API
|
||||
'蓝采和': 'webull', # 情绪分析师用活跃数据API
|
||||
'曹国舅': 'seeking_alpha', # 宏观分析师用分析API
|
||||
'铁拐李': 'alpha_vantage' # 逆向投资用基础数据API
|
||||
},
|
||||
|
||||
# 公司概览数据 - 2个API可提供
|
||||
'company_overview': {
|
||||
'吕洞宾': 'alpha_vantage', # 技术分析需要完整数据
|
||||
'何仙姑': 'seeking_alpha', # 风控需要分析师观点
|
||||
'张果老': 'alpha_vantage', # 技术分析偏好数据API
|
||||
'韩湘子': 'seeking_alpha', # 基本面研究需要深度分析
|
||||
'汉钟离': 'alpha_vantage', # 量化需要结构化数据
|
||||
'蓝采和': 'seeking_alpha', # 情绪分析需要市场观点
|
||||
'曹国舅': 'seeking_alpha', # 宏观分析需要专业观点
|
||||
'铁拐李': 'alpha_vantage' # 逆向投资需要基础数据
|
||||
},
|
||||
|
||||
# 市场动态数据 - 2个API可提供
|
||||
'market_movers': {
|
||||
'吕洞宾': 'yahoo_finance_15', # 剑仙关注市场热点
|
||||
'何仙姑': 'webull', # 风控关注活跃股票
|
||||
'张果老': 'yahoo_finance_15', # 技术分析关注涨跌榜
|
||||
'韩湘子': 'webull', # 基本面研究关注搜索热度
|
||||
'汉钟离': 'yahoo_finance_15', # 量化关注市场数据
|
||||
'蓝采和': 'webull', # 情绪分析关注活跃度
|
||||
'曹国舅': 'yahoo_finance_15', # 宏观关注整体趋势
|
||||
'铁拐李': 'webull' # 逆向投资关注异常股票
|
||||
},
|
||||
|
||||
# 新闻和分析数据 - 2个API可提供
|
||||
'market_news': {
|
||||
'吕洞宾': 'yahoo_finance_15', # 剑仙需要快速资讯
|
||||
'何仙姑': 'seeking_alpha', # 风控需要深度分析
|
||||
'张果老': 'yahoo_finance_15', # 技术分析关注市场新闻
|
||||
'韩湘子': 'seeking_alpha', # 基本面需要分析师观点
|
||||
'汉钟离': 'yahoo_finance_15', # 量化关注数据驱动新闻
|
||||
'蓝采和': 'seeking_alpha', # 情绪分析需要市场情绪
|
||||
'曹国舅': 'seeking_alpha', # 宏观需要政策分析
|
||||
'铁拐李': 'yahoo_finance_15' # 逆向投资关注反向指标
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 🔄 智能轮换策略
|
||||
|
||||
### 1. 时间窗口轮换
|
||||
|
||||
```python
|
||||
TIME_BASED_ROTATION = {
|
||||
# 交易时段 (9:30-16:00 EST) - 优先使用快速API
|
||||
'trading_hours': {
|
||||
'primary_apis': ['alpha_vantage', 'webull'],
|
||||
'backup_apis': ['yahoo_finance_15', 'seeking_alpha']
|
||||
},
|
||||
|
||||
# 非交易时段 - 可以使用较慢但更详细的API
|
||||
'after_hours': {
|
||||
'primary_apis': ['seeking_alpha', 'yahoo_finance_15'],
|
||||
'backup_apis': ['alpha_vantage', 'webull']
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 2. 负载感知轮换
|
||||
|
||||
```python
|
||||
LOAD_AWARE_ROTATION = {
|
||||
# 当某个API接近限制时,自动切换到其他API
|
||||
'rate_limit_thresholds': {
|
||||
'alpha_vantage': 450, # 90% of 500/min
|
||||
'yahoo_finance_15': 450,
|
||||
'webull': 450,
|
||||
'seeking_alpha': 450
|
||||
},
|
||||
|
||||
# 故障转移优先级
|
||||
'failover_priority': {
|
||||
'alpha_vantage': ['webull', 'yahoo_finance_15'],
|
||||
'yahoo_finance_15': ['webull', 'alpha_vantage'],
|
||||
'webull': ['alpha_vantage', 'yahoo_finance_15'],
|
||||
'seeking_alpha': ['yahoo_finance_15', 'alpha_vantage']
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 🏗️ 实现架构
|
||||
|
||||
### 核心组件
|
||||
|
||||
```python
|
||||
class JixiaLoadBalancer:
|
||||
"""稷下学宫负载均衡器"""
|
||||
|
||||
def __init__(self):
|
||||
self.api_pool = APIPool(AVAILABLE_APIS)
|
||||
self.immortal_mapping = DATA_TYPE_API_MAPPING
|
||||
self.rate_limiter = RateLimiter()
|
||||
self.health_checker = APIHealthChecker()
|
||||
|
||||
def get_data_for_immortal(self, immortal_name: str, data_type: str, symbol: str):
|
||||
"""为特定仙人获取数据"""
|
||||
# 1. 获取该仙人的首选API
|
||||
preferred_api = self.immortal_mapping[data_type][immortal_name]
|
||||
|
||||
# 2. 检查API健康状态和速率限制
|
||||
if self.is_api_available(preferred_api):
|
||||
return self.call_api(preferred_api, data_type, symbol)
|
||||
|
||||
# 3. 故障转移到备用API
|
||||
backup_apis = LOAD_AWARE_ROTATION['failover_priority'][preferred_api]
|
||||
for backup_api in backup_apis:
|
||||
if self.is_api_available(backup_api):
|
||||
return self.call_api(backup_api, data_type, symbol)
|
||||
|
||||
# 4. 如果所有API都不可用,返回缓存数据
|
||||
return self.get_cached_data(data_type, symbol)
|
||||
|
||||
def is_api_available(self, api_name: str) -> bool:
|
||||
"""检查API是否可用"""
|
||||
# 检查健康状态
|
||||
if not self.health_checker.is_healthy(api_name):
|
||||
return False
|
||||
|
||||
# 检查速率限制
|
||||
if self.rate_limiter.is_rate_limited(api_name):
|
||||
return False
|
||||
|
||||
return True
|
||||
```
|
||||
|
||||
### 数据统一化处理
|
||||
|
||||
```python
|
||||
class DataNormalizer:
|
||||
"""数据标准化处理器"""
|
||||
|
||||
def normalize_stock_quote(self, raw_data: dict, api_source: str) -> dict:
|
||||
"""将不同API的股票报价数据标准化"""
|
||||
if api_source == 'alpha_vantage':
|
||||
return self._normalize_alpha_vantage_quote(raw_data)
|
||||
elif api_source == 'yahoo_finance_15':
|
||||
return self._normalize_yahoo_quote(raw_data)
|
||||
elif api_source == 'webull':
|
||||
return self._normalize_webull_quote(raw_data)
|
||||
|
||||
def _normalize_alpha_vantage_quote(self, data: dict) -> dict:
|
||||
"""标准化Alpha Vantage数据格式"""
|
||||
global_quote = data.get('Global Quote', {})
|
||||
return {
|
||||
'symbol': global_quote.get('01. symbol'),
|
||||
'price': float(global_quote.get('05. price', 0)),
|
||||
'change': float(global_quote.get('09. change', 0)),
|
||||
'change_percent': global_quote.get('10. change percent', '0%'),
|
||||
'volume': int(global_quote.get('06. volume', 0)),
|
||||
'source': 'alpha_vantage'
|
||||
}
|
||||
|
||||
def _normalize_yahoo_quote(self, data: dict) -> dict:
|
||||
"""标准化Yahoo Finance数据格式"""
|
||||
body = data.get('body', {})
|
||||
return {
|
||||
'symbol': body.get('symbol'),
|
||||
'price': float(body.get('regularMarketPrice', 0)),
|
||||
'change': float(body.get('regularMarketChange', 0)),
|
||||
'change_percent': f"{body.get('regularMarketChangePercent', 0):.2f}%",
|
||||
'volume': int(body.get('regularMarketVolume', 0)),
|
||||
'source': 'yahoo_finance_15'
|
||||
}
|
||||
```
|
||||
|
||||
## 📊 监控和统计
|
||||
|
||||
### API使用统计
|
||||
|
||||
```python
|
||||
class APIUsageMonitor:
|
||||
"""API使用监控器"""
|
||||
|
||||
def __init__(self):
|
||||
self.usage_stats = {
|
||||
'alpha_vantage': {'calls': 0, 'errors': 0, 'avg_response_time': 0},
|
||||
'yahoo_finance_15': {'calls': 0, 'errors': 0, 'avg_response_time': 0},
|
||||
'webull': {'calls': 0, 'errors': 0, 'avg_response_time': 0},
|
||||
'seeking_alpha': {'calls': 0, 'errors': 0, 'avg_response_time': 0}
|
||||
}
|
||||
|
||||
def record_api_call(self, api_name: str, response_time: float, success: bool):
|
||||
"""记录API调用统计"""
|
||||
stats = self.usage_stats[api_name]
|
||||
stats['calls'] += 1
|
||||
if not success:
|
||||
stats['errors'] += 1
|
||||
|
||||
# 更新平均响应时间
|
||||
current_avg = stats['avg_response_time']
|
||||
total_calls = stats['calls']
|
||||
stats['avg_response_time'] = (current_avg * (total_calls - 1) + response_time) / total_calls
|
||||
|
||||
def get_load_distribution(self) -> dict:
|
||||
"""获取负载分布统计"""
|
||||
total_calls = sum(stats['calls'] for stats in self.usage_stats.values())
|
||||
if total_calls == 0:
|
||||
return {}
|
||||
|
||||
return {
|
||||
api: {
|
||||
'percentage': (stats['calls'] / total_calls) * 100,
|
||||
'success_rate': ((stats['calls'] - stats['errors']) / stats['calls']) * 100 if stats['calls'] > 0 else 0,
|
||||
'avg_response_time': stats['avg_response_time']
|
||||
}
|
||||
for api, stats in self.usage_stats.items()
|
||||
}
|
||||
```
|
||||
|
||||
## 🎯 实施计划
|
||||
|
||||
### 第一阶段:基础负载均衡
|
||||
1. **实现核心负载均衡器** - 基本的API轮换逻辑
|
||||
2. **数据标准化处理** - 统一不同API的数据格式
|
||||
3. **简单故障转移** - 基本的备用API切换
|
||||
|
||||
### 第二阶段:智能优化
|
||||
1. **速率限制监控** - 实时监控API使用情况
|
||||
2. **健康检查机制** - 定期检测API可用性
|
||||
3. **性能优化** - 基于响应时间优化API选择
|
||||
|
||||
### 第三阶段:高级功能
|
||||
1. **预测性负载均衡** - 基于历史数据预测API负载
|
||||
2. **成本优化** - 基于API成本优化调用策略
|
||||
3. **实时监控面板** - 可视化API使用情况
|
||||
|
||||
## 📈 预期效果
|
||||
|
||||
### 性能提升
|
||||
- **API负载分散**: 单个API负载降低60-70%
|
||||
- **系统稳定性**: 故障率降低80%以上
|
||||
- **响应速度**: 平均响应时间提升30%
|
||||
|
||||
### 成本控制
|
||||
- **API使用优化**: 避免单一API过度使用
|
||||
- **故障恢复**: 减少因API故障导致的数据缺失
|
||||
- **扩展性**: 支持更多API的无缝接入
|
||||
|
||||
## 🔧 配置示例
|
||||
|
||||
### 环境配置
|
||||
```bash
|
||||
# Doppler环境变量
|
||||
RAPIDAPI_KEY=your_rapidapi_key
|
||||
ALPHA_VANTAGE_API_KEY=your_alpha_vantage_key
|
||||
|
||||
# 负载均衡配置
|
||||
LOAD_BALANCER_ENABLED=true
|
||||
API_HEALTH_CHECK_INTERVAL=300 # 5分钟
|
||||
RATE_LIMIT_BUFFER=50 # 保留50个请求的缓冲
|
||||
```
|
||||
|
||||
### 使用示例
|
||||
```python
|
||||
# 在稷下学宫系统中使用
|
||||
from jixia_load_balancer import JixiaLoadBalancer
|
||||
|
||||
load_balancer = JixiaLoadBalancer()
|
||||
|
||||
# 八仙论道时,每个仙人获取数据
|
||||
for immortal in ['吕洞宾', '何仙姑', '张果老', '韩湘子', '汉钟离', '蓝采和', '曹国舅', '铁拐李']:
|
||||
quote_data = load_balancer.get_data_for_immortal(immortal, 'stock_quote', 'TSLA')
|
||||
overview_data = load_balancer.get_data_for_immortal(immortal, 'company_overview', 'TSLA')
|
||||
|
||||
print(f"{immortal}: 获取到{quote_data['source']}的数据")
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🎉 总结
|
||||
|
||||
通过这套负载分担策略,稷下学宫八仙论道系统可以:
|
||||
|
||||
1. **智能分配API调用** - 不同仙人使用不同API获取相同数据
|
||||
2. **实现真正的负载均衡** - 避免单一API过载
|
||||
3. **提高系统稳定性** - 多重故障转移保障
|
||||
4. **优化成本效益** - 充分利用现有API资源
|
||||
5. **支持无缝扩展** - 新API可轻松接入系统
|
||||
|
||||
**"八仙过海,各显神通"** - 让每个仙人都有自己的数据获取路径,共同构建稳定可靠的智能投资决策系统!🚀
|
||||
165
modules/documentation-suite/docs/rapidapi/optimized_config.md
Normal file
165
modules/documentation-suite/docs/rapidapi/optimized_config.md
Normal file
@@ -0,0 +1,165 @@
|
||||
# 优化的RapidAPI配置
|
||||
|
||||
基于实际测试结果,优化八仙论道系统的API配置。
|
||||
|
||||
## 🎯 可用API配置 (4个)
|
||||
|
||||
### 高性能API (响应时间 < 2s)
|
||||
```python
|
||||
FAST_APIS = {
|
||||
'alpha_vantage': {
|
||||
'host': 'alpha-vantage.p.rapidapi.com',
|
||||
'response_time': 1.26,
|
||||
'data_types': ['quote', 'overview', 'earnings'],
|
||||
'specialty': 'fundamental_analysis'
|
||||
},
|
||||
'webull': {
|
||||
'host': 'webull.p.rapidapi.com',
|
||||
'response_time': 1.56,
|
||||
'data_types': ['search', 'quote', 'gainers'],
|
||||
'specialty': 'stock_search'
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 标准API (响应时间 2-4s)
|
||||
```python
|
||||
STANDARD_APIS = {
|
||||
'yahoo_finance_1': {
|
||||
'host': 'yahoo-finance15.p.rapidapi.com',
|
||||
'response_time': 2.07,
|
||||
'data_types': ['quote', 'gainers', 'losers'],
|
||||
'specialty': 'market_data'
|
||||
},
|
||||
'seeking_alpha': {
|
||||
'host': 'seeking-alpha.p.rapidapi.com',
|
||||
'response_time': 3.32,
|
||||
'data_types': ['profile', 'news'],
|
||||
'specialty': 'analysis_news'
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 🎭 优化的八仙API分配
|
||||
|
||||
基于可用API重新分配八仙的数据源:
|
||||
|
||||
```python
|
||||
OPTIMIZED_IMMORTAL_APIS = {
|
||||
'吕洞宾': { # 技术分析专家
|
||||
'primary': 'alpha_vantage',
|
||||
'backup': ['yahoo_finance_1'],
|
||||
'data_type': 'overview',
|
||||
'specialty': 'comprehensive_analysis'
|
||||
},
|
||||
'何仙姑': { # 风险控制专家
|
||||
'primary': 'yahoo_finance_1',
|
||||
'backup': ['webull'],
|
||||
'data_type': 'quote',
|
||||
'specialty': 'risk_management'
|
||||
},
|
||||
'张果老': { # 历史数据分析师
|
||||
'primary': 'seeking_alpha',
|
||||
'backup': ['alpha_vantage'],
|
||||
'data_type': 'profile',
|
||||
'specialty': 'fundamental_analysis'
|
||||
},
|
||||
'韩湘子': { # 新兴资产专家
|
||||
'primary': 'webull',
|
||||
'backup': ['yahoo_finance_1'],
|
||||
'data_type': 'search',
|
||||
'specialty': 'emerging_trends'
|
||||
},
|
||||
'汉钟离': { # 热点追踪
|
||||
'primary': 'yahoo_finance_1',
|
||||
'backup': ['webull'],
|
||||
'data_type': 'gainers',
|
||||
'specialty': 'hot_trends'
|
||||
},
|
||||
'蓝采和': { # 潜力股发现
|
||||
'primary': 'webull',
|
||||
'backup': ['alpha_vantage'],
|
||||
'data_type': 'search',
|
||||
'specialty': 'undervalued_stocks'
|
||||
},
|
||||
'曹国舅': { # 机构分析
|
||||
'primary': 'seeking_alpha',
|
||||
'backup': ['alpha_vantage'],
|
||||
'data_type': 'profile',
|
||||
'specialty': 'institutional_analysis'
|
||||
},
|
||||
'铁拐李': { # 逆向投资
|
||||
'primary': 'alpha_vantage',
|
||||
'backup': ['seeking_alpha'],
|
||||
'data_type': 'overview',
|
||||
'specialty': 'contrarian_analysis'
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 📊 端点映射
|
||||
|
||||
### Alpha Vantage
|
||||
```python
|
||||
'alpha_vantage': {
|
||||
'quote': f'/query?function=GLOBAL_QUOTE&symbol={symbol}',
|
||||
'overview': f'/query?function=OVERVIEW&symbol={symbol}',
|
||||
'earnings': f'/query?function=EARNINGS&symbol={symbol}'
|
||||
}
|
||||
```
|
||||
|
||||
### Yahoo Finance 15
|
||||
```python
|
||||
'yahoo_finance_1': {
|
||||
'quote': f'/api/yahoo/qu/quote/{symbol}',
|
||||
'gainers': '/api/yahoo/co/collections/day_gainers',
|
||||
'losers': '/api/yahoo/co/collections/day_losers'
|
||||
}
|
||||
```
|
||||
|
||||
### Seeking Alpha
|
||||
```python
|
||||
'seeking_alpha': {
|
||||
'profile': f'/symbols/get-profile?symbols={symbol}',
|
||||
'news': '/news/list?category=market-news'
|
||||
}
|
||||
```
|
||||
|
||||
### Webull
|
||||
```python
|
||||
'webull': {
|
||||
'search': f'/stock/search?keyword={symbol}',
|
||||
'gainers': '/market/get-active-gainers'
|
||||
}
|
||||
```
|
||||
|
||||
## 🚀 性能优化建议
|
||||
|
||||
### 1. API优先级策略
|
||||
- **第一优先级**: Alpha Vantage, Webull (< 2s)
|
||||
- **第二优先级**: Yahoo Finance 15 (2-3s)
|
||||
- **第三优先级**: Seeking Alpha (3-4s)
|
||||
|
||||
### 2. 故障转移策略
|
||||
- 快速API之间互为备份
|
||||
- 避免使用不可用的API作为备份
|
||||
- 设置合理的超时时间 (8s)
|
||||
|
||||
### 3. 负载均衡
|
||||
- 将高频请求分散到不同API
|
||||
- 避免单一API过载
|
||||
- 监控API使用统计
|
||||
|
||||
## 💡 实施建议
|
||||
|
||||
1. **更新永动机引擎**: 移除不可用的API配置
|
||||
2. **优化八仙分配**: 基于API可用性重新分配
|
||||
3. **添加健康检查**: 定期测试API可用性
|
||||
4. **监控和告警**: 跟踪API响应时间和成功率
|
||||
|
||||
## 📈 预期效果
|
||||
|
||||
- **成功率提升**: 从当前的60%提升到95%+
|
||||
- **响应时间**: 平均响应时间从3s降低到2s
|
||||
- **稳定性**: 减少API调用失败导致的辩论中断
|
||||
- **用户体验**: 更快的辩论响应和更稳定的数据获取
|
||||
@@ -0,0 +1,112 @@
|
||||
# RapidAPI 测试报告
|
||||
|
||||
## 📊 测试概览
|
||||
|
||||
- **测试时间**: 2025-08-02 12:09:25
|
||||
- **总API数**: 17
|
||||
- **成功数**: 4 (23.5%)
|
||||
- **失败数**: 13 (76.5%)
|
||||
|
||||
## ✅ 可用的API (4个)
|
||||
|
||||
### alpha_vantage
|
||||
- **主机**: `alpha-vantage.p.rapidapi.com`
|
||||
- **响应时间**: 1.26s
|
||||
- **数据字段**: Global Quote
|
||||
|
||||
### webull
|
||||
- **主机**: `webull.p.rapidapi.com`
|
||||
- **响应时间**: 1.56s
|
||||
- **数据字段**: stocks, busiModel
|
||||
|
||||
### yahoo_finance_1
|
||||
- **主机**: `yahoo-finance15.p.rapidapi.com`
|
||||
- **响应时间**: 2.07s
|
||||
- **数据字段**: meta, body
|
||||
|
||||
### seeking_alpha
|
||||
- **主机**: `seeking-alpha.p.rapidapi.com`
|
||||
- **响应时间**: 3.32s
|
||||
- **数据字段**: data
|
||||
|
||||
## ❌ 失败的API (13个)
|
||||
|
||||
### yh_finance_complete
|
||||
- **主机**: `yh-finance.p.rapidapi.com`
|
||||
- **状态码**: 204
|
||||
- **错误**: Unknown...
|
||||
|
||||
### yahoo_finance_api_data
|
||||
- **主机**: `yahoo-finance-api1.p.rapidapi.com`
|
||||
- **状态码**: 403
|
||||
- **错误**: {"message":"You are not subscribed to this API."}...
|
||||
|
||||
### yahoo_finance_realtime
|
||||
- **主机**: `yahoo-finance-low-latency.p.rapidapi.com`
|
||||
- **状态码**: 404
|
||||
- **错误**: {"message":"API doesn't exists"}...
|
||||
|
||||
### yh_finance
|
||||
- **主机**: `yh-finance-complete.p.rapidapi.com`
|
||||
- **状态码**: 404
|
||||
- **错误**: {"message":"Endpoint '\/stock\/v2\/get-summary' does not exist"}...
|
||||
|
||||
### yahoo_finance_basic
|
||||
- **主机**: `yahoo-finance127.p.rapidapi.com`
|
||||
- **状态码**: 403
|
||||
- **错误**: {"message":"You are not subscribed to this API."}...
|
||||
|
||||
### morning_star
|
||||
- **主机**: `morningstar1.p.rapidapi.com`
|
||||
- **状态码**: 403
|
||||
- **错误**: {"message":"You are not subscribed to this API."}...
|
||||
|
||||
### tradingview
|
||||
- **主机**: `tradingview-ta.p.rapidapi.com`
|
||||
- **状态码**: 404
|
||||
- **错误**: {"message":"API doesn't exists"}...
|
||||
|
||||
### investing_com
|
||||
- **主机**: `investing-cryptocurrency-markets.p.rapidapi.com`
|
||||
- **状态码**: 403
|
||||
- **错误**: {"message":"You are not subscribed to this API."}...
|
||||
|
||||
### finance_api
|
||||
- **主机**: `real-time-finance-data.p.rapidapi.com`
|
||||
- **状态码**: 403
|
||||
- **错误**: {"message":"You are not subscribed to this API."}...
|
||||
|
||||
### ms_finance
|
||||
- **主机**: `ms-finance.p.rapidapi.com`
|
||||
- **状态码**: 404
|
||||
- **错误**: {"message":"Endpoint '\/stock\/v2\/get-summary' does not exist"}...
|
||||
|
||||
### sec_filings
|
||||
- **主机**: `sec-filings.p.rapidapi.com`
|
||||
- **状态码**: 404
|
||||
- **错误**: {"message":"API doesn't exists"}...
|
||||
|
||||
### exchangerate_api
|
||||
- **主机**: `exchangerate-api.p.rapidapi.com`
|
||||
- **状态码**: 404
|
||||
- **错误**: {"message":"Endpoint '\/latest' does not exist"}...
|
||||
|
||||
### crypto_news
|
||||
- **主机**: `cryptocurrency-news2.p.rapidapi.com`
|
||||
- **状态码**: 404
|
||||
- **错误**: {"message":"Endpoint '\/v1\/cryptonews' does not exist"}...
|
||||
|
||||
## 🔧 优化建议
|
||||
|
||||
### 立即可用的API
|
||||
以下API响应快速,建议优先使用:
|
||||
- **alpha_vantage**: 1.26s
|
||||
- **webull**: 1.56s
|
||||
|
||||
### 需要修复的API
|
||||
以下API需要检查端点配置或权限:
|
||||
- **yh_finance_complete**: Unknown error...
|
||||
- **yahoo_finance_api_data**: {"message":"You are not subscribed to this API."}...
|
||||
- **yahoo_finance_realtime**: {"message":"API doesn't exists"}...
|
||||
- **yh_finance**: {"message":"Endpoint '\/stock\/v2\/get-summary' do...
|
||||
- **yahoo_finance_basic**: {"message":"You are not subscribed to this API."}...
|
||||
Reference in New Issue
Block a user