股票信息
股票信息 API
获取股票的基本信息,包括公司名称、所属行业、市场等。
端点
| 方法 | 端点 |
|---|---|
| GET | /ticker_info |
在线试用
GET
/ticker_info请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
symbol | string | ✅ | 股票代码 (如 000001.SZ, 002415.SZ) |
代码示例
Python
import requests
API_KEY = "your_api_key"
response = requests.get(
"https://tickerlab.org/ticker_info",
params={"symbol": "000001.SZ"},
headers={"X-API-Key": API_KEY}
)
info = response.json()
print(f"名称: {info.get('name')}")
print(f"行业: {info.get('industry')}")
print(f"市场: {info.get('market')}")
JavaScript
const response = await fetch(
'https://tickerlab.org/ticker_info?symbol=000001.SZ',
{ headers: { 'X-API-Key': 'your_api_key' } }
);
const info = await response.json();
console.log(`${info.name} - ${info.industry}`);
cURL
curl "https://tickerlab.org/ticker_info?symbol=000001.SZ" \
-H "X-API-Key: your_api_key"
响应示例
{
"code": "000001",
"name": "平安银行",
"market": "SZ",
"industry": "银行",
"list_date": "1991-04-03",
"total_share": 19405918198,
"float_share": 19380084397,
"pe_ratio": 5.23,
"pb_ratio": 0.58
}
字段说明
| 字段 | 说明 |
|---|---|
code | 股票代码 (6位) |
name | 股票名称 |
market | 市场 (SZ/SH) |
industry | 所属行业 |
list_date | 上市日期 |
total_share | 总股本 |
float_share | 流通股本 |
pe_ratio | 市盈率 |
pb_ratio | 市净率 |
完整示例:构建股票分析工具
以下是一个完整的 Python 示例,展示如何组合使用多个 API:
import requests
import pandas as pd
import matplotlib.pyplot as plt
class StockAnalyzer:
def __init__(self, api_key, base_url="https://tickerlab.org"):
self.api_key = api_key
self.base_url = base_url
self.headers = {"X-API-Key": api_key}
def get_info(self, symbol):
"""获取股票基本信息"""
r = requests.get(
f"{self.base_url}/ticker_info",
params={"symbol": symbol},
headers=self.headers
)
return r.json()
def get_kline(self, symbol, days=60):
"""获取 K 线数据"""
r = requests.get(
f"{self.base_url}/v1/indicators/time_series",
params={"symbol": symbol, "outputsize": days},
headers=self.headers
)
data = r.json()
df = pd.DataFrame(data["values"])
df["datetime"] = pd.to_datetime(df["datetime"])
for col in ["open", "high", "low", "close"]:
df[col] = df[col].astype(float)
return df
def get_indicators(self, symbol):
"""获取技术指标"""
indicators = {}
# RSI
r = requests.get(
f"{self.base_url}/v1/indicators/rsi",
params={"symbol": symbol},
headers=self.headers
)
indicators["rsi"] = float(r.json()["values"][0]["rsi"])
# MACD
r = requests.get(
f"{self.base_url}/v1/indicators/macd",
params={"symbol": symbol},
headers=self.headers
)
macd_data = r.json()["values"][0]
indicators["macd"] = float(macd_data["macd"])
indicators["macd_signal"] = float(macd_data["macd_signal"])
return indicators
def analyze(self, symbol):
"""综合分析"""
info = self.get_info(symbol)
kline = self.get_kline(symbol)
indicators = self.get_indicators(symbol)
print(f"=== {info['name']} ({symbol}) ===")
print(f"行业: {info.get('industry', 'N/A')}")
print(f"最新价: {kline['close'].iloc[0]:.2f}")
print(f"RSI: {indicators['rsi']:.2f}")
print(f"MACD: {indicators['macd']:.4f}")
# 简单信号判断
if indicators["rsi"] > 70:
print("⚠️ RSI 超买")
elif indicators["rsi"] < 30:
print("📈 RSI 超卖")
return {"info": info, "kline": kline, "indicators": indicators}
# 使用示例
analyzer = StockAnalyzer("your_api_key")
result = analyzer.analyze("000001.SZ")