update pay promo
This commit is contained in:
109
mcp_server.py
109
mcp_server.py
@@ -569,7 +569,7 @@ TOOLS: List[ToolDefinition] = [
|
||||
),
|
||||
ToolDefinition(
|
||||
name="get_stock_trade_data",
|
||||
description="获取股票交易数据,包括价格、成交量、涨跌幅、换手率等日线行情数据。",
|
||||
description="获取股票历史日线交易数据(收盘价、成交量、涨跌幅、换手率等)。注意:此工具返回的是历史收盘数据,不是实时价格。如需查询当前/实时价格,请使用 get_stock_realtime_timeline 工具。",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -729,9 +729,23 @@ TOOLS: List[ToolDefinition] = [
|
||||
}
|
||||
),
|
||||
# ==================== 分钟频数据工具 ====================
|
||||
ToolDefinition(
|
||||
name="get_stock_realtime_quote",
|
||||
description="【查询当前/实时价格首选】获取股票实时报价。当用户询问'当前价格'、'现在多少钱'、'实时行情'时使用此工具。返回最新价、涨跌幅、成交量等实时数据。比分时数据更轻量快速。",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "string",
|
||||
"description": "股票代码,例如:'600519' 或 '000001'"
|
||||
}
|
||||
},
|
||||
"required": ["code"]
|
||||
}
|
||||
),
|
||||
ToolDefinition(
|
||||
name="get_stock_realtime_timeline",
|
||||
description="获取股票最新分时走势数据(自动获取今日数据,无需指定时间)。返回今日每分钟的价格、涨跌幅、成交量等数据,适合查看股票当前走势。",
|
||||
description="获取股票今日完整分时走势数据。当用户询问'今天走势'、'分时图'、'日内波动'时使用。返回今日每分钟的价格、成交量数据。如只需查询当前价格,建议使用更快的 get_stock_realtime_quote。",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -1842,6 +1856,93 @@ async def handle_get_user_following_events(args: Dict[str, Any]) -> Any:
|
||||
|
||||
# ==================== 分钟频数据处理函数 ====================
|
||||
|
||||
async def handle_get_stock_realtime_quote(args: Dict[str, Any]) -> Any:
|
||||
"""获取股票实时报价(轻量级,只返回当前价格信息)"""
|
||||
code = args["code"]
|
||||
|
||||
# 标准化股票代码
|
||||
base_code = code.split('.')[0] if '.' in code else code
|
||||
|
||||
# 判断交易所
|
||||
if base_code.startswith('6'):
|
||||
full_code = f"{base_code}.SH"
|
||||
else:
|
||||
full_code = f"{base_code}.SZ"
|
||||
|
||||
try:
|
||||
# 调用 flex-screen/quotes API 获取实时数据
|
||||
response = await HTTP_CLIENT.post(
|
||||
f"{ServiceEndpoints.MAIN_APP_API}/api/flex-screen/quotes",
|
||||
json={"codes": [full_code]},
|
||||
headers={"Content-Type": "application/json"}
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
result = response.json()
|
||||
if result.get('success') and result.get('data'):
|
||||
quote_data = result['data'].get(full_code)
|
||||
if quote_data:
|
||||
return {
|
||||
"success": True,
|
||||
"data": {
|
||||
"code": full_code,
|
||||
"name": quote_data.get('name', ''),
|
||||
"current_price": quote_data.get('last_px'),
|
||||
"change": quote_data.get('change'),
|
||||
"change_pct": quote_data.get('change_pct'),
|
||||
"open": quote_data.get('open_px'),
|
||||
"high": quote_data.get('high_px'),
|
||||
"low": quote_data.get('low_px'),
|
||||
"prev_close": quote_data.get('prev_close_px'),
|
||||
"volume": quote_data.get('total_volume_trade'),
|
||||
"amount": quote_data.get('total_value_trade'),
|
||||
"update_time": quote_data.get('update_time')
|
||||
},
|
||||
"source": result.get('source', 'realtime')
|
||||
}
|
||||
|
||||
# 如果实时数据获取失败,回退到 quote-detail API
|
||||
response = await HTTP_CLIENT.get(
|
||||
f"{ServiceEndpoints.MAIN_APP_API}/api/stock/{base_code}/quote-detail"
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
result = response.json()
|
||||
if result.get('success'):
|
||||
data = result.get('data', {})
|
||||
return {
|
||||
"success": True,
|
||||
"data": {
|
||||
"code": full_code,
|
||||
"name": data.get('name', ''),
|
||||
"current_price": data.get('current_price'),
|
||||
"change_pct": data.get('change_percent'),
|
||||
"open": data.get('today_open'),
|
||||
"high": data.get('today_high'),
|
||||
"low": data.get('today_low'),
|
||||
"prev_close": data.get('yesterday_close'),
|
||||
"pe": data.get('pe'),
|
||||
"pb": data.get('pb'),
|
||||
"market_cap": data.get('market_cap'),
|
||||
"turnover_rate": data.get('turnover_rate')
|
||||
},
|
||||
"source": "daily",
|
||||
"note": "实时数据暂不可用,返回最近交易日收盘数据"
|
||||
}
|
||||
|
||||
return {
|
||||
"success": False,
|
||||
"error": "无法获取股票报价数据"
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"获取实时报价失败: {e}")
|
||||
return {
|
||||
"success": False,
|
||||
"error": str(e)
|
||||
}
|
||||
|
||||
|
||||
async def handle_get_stock_realtime_timeline(args: Dict[str, Any]) -> Any:
|
||||
"""获取股票最新分时走势数据(自动获取今日数据)"""
|
||||
from datetime import datetime, date
|
||||
@@ -1950,8 +2051,10 @@ TOOL_HANDLERS = {
|
||||
"get_stock_comparison": handle_get_stock_comparison,
|
||||
"get_user_watchlist": handle_get_user_watchlist,
|
||||
"get_user_following_events": handle_get_user_following_events,
|
||||
# 分钟频数据工具
|
||||
# 实时行情工具
|
||||
"get_stock_realtime_quote": handle_get_stock_realtime_quote,
|
||||
"get_stock_realtime_timeline": handle_get_stock_realtime_timeline,
|
||||
# 分钟频数据工具
|
||||
"get_stock_minute_data": handle_get_stock_minute_data,
|
||||
"get_stock_minute_aggregation": handle_get_stock_minute_aggregation,
|
||||
"get_stock_intraday_statistics": handle_get_stock_intraday_statistics,
|
||||
|
||||
Reference in New Issue
Block a user