mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-11 23:07:01 +08:00
feat: dynamic stock search via Sina suggest API
- Add searchStock() using Sina's suggest API (type=11,31,41) - Supports A-share, HK, and US markets dynamically - No longer limited to hardcoded knownStocks map - resolveStockCodeDynamic: tries static map first, then API fallback - extractStockKeyword: smart keyword extraction from natural language - New LLM tool 'search_stock': agent can proactively search stocks - Top 3 search results auto-enriched with real-time quotes - System prompts updated for both zh/en
This commit is contained in:
@@ -294,6 +294,7 @@ func (a *Agent) buildSystemPrompt(lang string) string {
|
||||
|
||||
## 工具使用
|
||||
你可以调用以下工具来执行操作:
|
||||
- **search_stock** — 搜索股票(支持中文名、英文名、代码)。当用户提到你不认识的股票时,先用这个工具搜索。
|
||||
- **execute_trade** — 下单交易(做多/做空/平多/平空)。调用后会创建待确认订单,用户需回复"确认 trade_xxx"才会真正执行。
|
||||
- **get_positions** — 查看当前所有持仓
|
||||
- **get_balance** — 查看账户余额
|
||||
@@ -338,6 +339,7 @@ func (a *Agent) buildSystemPrompt(lang string) string {
|
||||
|
||||
## Tools
|
||||
You can call these tools to take action:
|
||||
- **search_stock** — Search for stocks by name, ticker, or code. Covers A-share, HK, and US markets. Use when the user mentions an unknown stock.
|
||||
- **execute_trade** — Place a trade order (open_long/open_short/close_long/close_short). Creates a pending order that requires user confirmation.
|
||||
- **get_positions** — View all current open positions
|
||||
- **get_balance** — View account balance and equity
|
||||
@@ -376,8 +378,8 @@ func (a *Agent) gatherContext(text string) string {
|
||||
}
|
||||
}
|
||||
|
||||
// A-share / stocks — try Sina Finance
|
||||
stockCode, stockName := resolveStockCode(text)
|
||||
// A-share / stocks — try Sina Finance (dynamic search as fallback)
|
||||
stockCode, stockName := resolveStockCodeDynamic(text)
|
||||
if stockCode != "" {
|
||||
quote, err := fetchStockQuote(stockCode)
|
||||
if err == nil && quote.Price > 0 {
|
||||
|
||||
Reference in New Issue
Block a user