增强版 —— 订阅文章
finlight.me WebSocket API 允许您实时订阅文章更新。连接并订阅后,您会立即收到与您查询匹配的最新文章,随后会在符合条件的新文章出现时收到它们。
文章模型
响应中的文章模型包含有关文章的所有信息,例如链接、标题、发布日期和来源。它还包含情绪及其对该情绪的置信度。
- Name
link- Type
- string
- Description
指向完整文章的 URL。
- Name
source- Type
- string
- Description
来源网站。例如
www.reuters.com
- Name
title- Type
- string
- Description
文章标题。
- Name
summary- Type
- string
- Description
文章摘要(如果存在)。可为空。
- Name
publishDate- Type
- Date
- Description
发布日期,采用 ISO 日期格式。
- Name
createdAt- Type
- Date
- Description
文章在 finlight 系统中的内部创建日期,采用 ISO 日期格式。
- Name
revisedDate- Type
- Date | null
- Description
文章在首次发布后最后一次修订的日期。当文章从未修订时为
null。当启用includeUpdates且文章已被修订时存在。
- Name
isUpdate- Type
- boolean
- Description
当本次投递由文章发布后的更新触发时为
true。仅在启用includeUpdates时存在。
- Name
language- Type
- string
- Description
ISO 639-1 语言代码。例如
en|de|fr
- Name
sentiment- Type
- string
- Description
情绪分析结果。值可以是
positive|neutral|negative
- Name
confidence- Type
- number
- Description
情绪分析的置信度,从 0 到 1。
- Name
images- Type
- string[]
- Description
文章中的图片 URL 数组。
- Name
countries- Type
- string[]
- Description
表示与文章相关的国家/地区的代码数组,采用 ISO 3166-1 alpha-2 格式。例如
["US", "GB", "DE"]。可为空。
- Name
categories- Type
- string[]
- Description
文章类别数组。可能的值:
markets|economy|business|politics|geopolitics|regulation|technology|energy|commodities|crypto|health|climate|security。可为空。
- Name
companies- Type
- Company[]
- Description
文章中提及的公司数组。仅在特定订阅层级中显示/可用。可为空。
公司模型
响应中的公司模型包含有关文章中提及的某家公司的信息。它包括公司名称、股票代码、行业等详情。
- Name
companyId- Type
- number
- Description
公司的唯一标识符。
- Name
confidence- Type
- string
- Description
公司识别的置信度,从 0 到 1。
- Name
country- Type
- string
- Description
公司所在国家/地区,采用 ISO 3166-1 alpha-2 格式。例如
US|DE|GB
- Name
exchange- Type
- string
- Description
公司上市的证券交易所。
- Name
industry- Type
- Date
- Description
公司的细分行业。例如
Biotechnology, Technology
- Name
name- Type
- string
- Description
公司全称。例如
Apple Inc.
- Name
sector- Type
- string
- Description
公司的行业板块。例如
Technology|Health Care
- Name
ticker- Type
- string
- Description
公司的股票代码。例如
AAPL|GOOGL
- Name
isin- Type
- string
- Description
公司的国际证券识别码(ISIN)。例如
US0378331005
- Name
openfigi- Type
- string
- Description
公司的 OpenFIGI 标识符。例如
BBG000B9XRY4
- Name
primaryListing- Type
- object
- Description
公司的主要证券交易所上市信息。
- Name
primaryListing.ticker- Type
- string
- Description
主交易所上的主要股票代码。
- Name
primaryListing.exchangeCode- Type
- string
- Description
该股票上市的主要交易所的代码。
- Name
primaryListing.exchangeCountry- Type
- string
- Description
该股票上市的主要交易所所在国家/地区。
- Name
isins- Type
- string[]
- Description
公司的国际证券识别码(ISIN)数组。
- Name
otherListings- Type
- object[]
- Description
公司的其他证券交易所上市信息数组。
- Name
otherListings[].ticker- Type
- string
- Description
备选交易所上的股票代码。
- Name
otherListings[].exchangeCode- Type
- string
- Description
该股票上市的备选交易所的代码。
- Name
otherListings[].exchangeCountry- Type
- string
- Description
该股票上市的备选交易所所在国家/地区。
获取文章
订阅后,您会首先收到与您查询匹配的最新文章,随后会在新文章发布时收到它们。
订阅时,您可以指定各种参数来过滤您接收的文章:
- Name
query- Type
- string
- Description
用于查找相关文章的搜索查询。高级查询
- Name
sources- Type
- string[]
- Description
按单个或多个文章来源过滤。例如 ["www.reuters.com", "www.cnbc.com"]。有效值请参见 source 端点。支持通配符
"*"以包含所有来源。
- Name
excludeSources- Type
- string[]
- Description
排除单个或多个来源。例如 ["www.reuters.com", "www.cnbc.com"]。有效值请参见 source 端点。
- Name
tickers- Type
- string[]
- Description
按股票代码过滤(字符串数组)。这将返回提及这些代码的文章。支持通配符
"*"以包含所有代码。
- Name
countries- Type
- string[]
- Description
使用 ISO 3166-1 alpha-2 国家/地区代码按公司所在国家/地区过滤(字符串数组)。例如
["US", "GB", "DE"]
- Name
includeEntities- Type
- boolean
- Description
包含文章中提及的公司。需要特定的订阅层级。
- Name
includeUpdates- Type
- boolean
- Description
启用后,更新的文章会以
isUpdate=true和revisedDate时间戳重新投递。可用于监控文章在首次发布后的更正或内容补充。
- Name
extended- Type
- boolean
- Description
(已弃用)
true表示接收扩展的文章信息(包含summary)。
Request
import { FinlightApi } from 'finlight-client'
const client = new FinlightApi({
apiKey: 'YOUR_API_KEY', // Replace with your API key
})
client.websocket.connect(
{
query: 'Nvidia',
language: 'en',
extended: true,
countries: ['US', 'GB'],
},
(article) => {
console.log('New article received:', article)
},
)
管理连接限制:如果您的订阅层级限制了并行 WebSocket 连接的数量,您可以使用 takeover 选项,在尝试打开超出上限的新连接时自动关闭最旧的连接。这可防止在开发或应用重启期间出现连接错误。
// TypeScript example with takeover enabled
const client = new FinlightApi(
{
apiKey: 'YOUR_API_KEY',
},
{
takeover: true, // Automatically close oldest connection when limit is reached
},
)
# Python example with takeover enabled
from finlight_client import FinlightApi, ApiConfig, WebSocketOptions
client = FinlightApi(
config=ApiConfig(api_key="YOUR_API_KEY"),
websocket_options=WebSocketOptions(takeover=True)
)
默认情况下,takeover 设置为 false,这意味着如果您已达到上限,新连接将被拒绝。在开发期间启用它以方便操作,但在生产环境中可考虑保持禁用以实现明确的连接管理。
Response
{
"link": "https://www.example.com/article1",
"source": "www.example.com",
"title": "Stock Market Hits New Highs",
"summary": "A brief summary of the article...",
"publishDate": "2023-10-01T12:34:56Z",
"createdAt": "2023-10-01T12:35:10Z",
"language": "en",
"sentiment": "positive",
"confidence": 0.95,
"images": [
"https://www.example.com/image1.jpg",
"https://www.example.com/image2.jpg"
],
"countries": ["US"],
"categories": ["markets", "technology"],
"companies": [
{
"companyId": 41494,
"confidence": "0.9335401058197021",
"country": "US",
"exchange": "XNAS",
"industry": "Biotechnology: Pharmaceutical Preparations",
"name": "Summit Therapeutics Inc. Common Stock",
"sector": "Health Care",
"ticker": "SMMT",
"isin": "US86627T1088",
"openfigi": "BBG01PH11VP5",
"primaryListing": {
"ticker": "SMMT",
"exchangeCode": "XNAS",
"exchangeCountry": "US"
},
"isins": ["US86627T1088", "US86627T2088"],
"otherListings": [
{
"ticker": "SMMT.L",
"exchangeCode": "XLON",
"exchangeCountry": "GB"
}
]
}
]
}
Response (includeUpdates: true)
{
"link": "https://www.example.com/article1",
"source": "www.example.com",
"title": "Stock Market Hits New Highs — Updated",
"summary": "An updated summary of the article...",
"publishDate": "2023-10-01T12:34:56Z",
"createdAt": "2023-10-01T12:35:10Z",
"revisedDate": "2023-10-02T08:00:00Z",
"isUpdate": true,
"language": "en",
"sentiment": "positive",
"confidence": 0.95,
"images": [
"https://www.example.com/image1.jpg"
],
"countries": ["US"],
"categories": ["markets"],
"companies": []
}
您可以保持连接打开,实时接收文章,无需额外请求。当有新文章可用时,它们会被直接推送到您的回调函数。