K 线数据 API
获取股票的历史 K 线数据,支持多种时间周期。
| 方法 | 端点 | 说明 |
|---|
| GET | /v1/indicators/time_series | 历史 K 线(OHLCV)时间序列 |
| GET | /v1/market/quote | 实时行情(买卖盘/最新价) |
| GET | /v1/market/history | 可导出历史行情 |
| POST | /v1/market/chart/batch | 批量生成静态图表 |
1. 时间序列 (Time Series)
获取股票的历史 K 线数据,支持多种时间周期。
端点
| 方法 | 端点 |
|---|
| GET | /v1/indicators/time_series |
请求参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|
symbol | string | ✅ | - | 股票代码 (如 000001.SZ, SZSE:000001) |
interval | string | - | 1d | 时间周期: 1m, 5m, 15m, 30m, 1h, 4h, 1d, 1w |
start_date | string | - | - | 开始日期 (YYYY-MM-DD) |
end_date | string | - | - | 结束日期 (YYYY-MM-DD) |
adjust | string | - | qfq | 复权类型: qfq(前复权), hfq(后复权), 空字符串(不复权) |
outputsize | int | - | 5000 | 返回数据条数 |
在线试用
代码示例
Python
import requests
import pandas as pd
API_KEY = "your_api_key"
# 获取平安银行日线数据
response = requests.get(
"https://tickerlab.org/v1/indicators/time_series",
params={
"symbol": "000001.SZ",
"interval": "1d",
"start_date": "2024-01-01",
"outputsize": 100
},
headers={"X-API-Key": API_KEY}
)
data = response.json()
# 转换为 DataFrame
df = pd.DataFrame(data["values"])
df["datetime"] = pd.to_datetime(df["datetime"])
print(df.head())
# datetime open high low close volume
# 0 2024-01-15 00:00:00 10.25 10.35 10.20 10.30 12345678
# 1 2024-01-14 00:00:00 10.20 10.28 10.15 10.25 11234567
JavaScript
const API_KEY = 'your_api_key';
async function getKLineData(symbol, interval = '1d', days = 100) {
const params = new URLSearchParams({
symbol,
interval,
outputsize: days
});
const response = await fetch(
`https://tickerlab.org/v1/indicators/time_series?${params}`,
{ headers: { 'X-API-Key': API_KEY } }
);
return response.json();
}
// 使用示例
const data = await getKLineData('000001.SZ', '1d', 30);
console.log(`获取 ${data.values.length} 条数据`);
cURL
curl -G "https://tickerlab.org/v1/indicators/time_series" \
-H "X-API-Key: your_api_key" \
-d "symbol=000001.SZ" \
-d "interval=1d" \
-d "start_date=2024-01-01" \
-d "outputsize=100"
响应示例
{
"meta": {
"symbol": "000001.SZ",
"interval": "1d",
"currency": "CNY",
"exchange_timezone": "Asia/Shanghai",
"exchange": "SZSE",
"mic_code": "XSHE",
"type": "Common Stock"
},
"values": [
{
"datetime": "2024-01-15 00:00:00",
"open": "10.25",
"high": "10.35",
"low": "10.20",
"close": "10.30",
"volume": "12345678"
},
{
"datetime": "2024-01-14 00:00:00",
"open": "10.20",
"high": "10.28",
"low": "10.15",
"close": "10.25",
"volume": "11234567"
}
],
"status": "ok"
}
数据字段说明
| 字段 | 说明 |
|---|
datetime | 时间戳 |
open | 开盘价 |
high | 最高价 |
low | 最低价 |
close | 收盘价 |
volume | 成交量 |
2. 实时报价 (Quote)
获取最新的市场报价信息。
端点
参数
| 参数 | 类型 | 必填 | 说明 |
|---|
symbol | string | ✅ | 股票或加密货币代码 (如 BTCUSDT, 000001.SZ) |
在线试用
代码示例
Python
import requests
API_KEY = "your_api_key"
# 获取 BTCUSDT 实时报价
response = requests.get(
"https://tickerlab.org/v1/market/quote",
params={"symbol": "BTCUSDT"},
headers={"X-API-Key": API_KEY}
)
data = response.json()
print(f"当前价格: {data['price']}")
print(f"涨跌幅: {data['change_percent']}%")
JavaScript
const API_KEY = 'your_api_key';
const response = await fetch(
"https://tickerlab.org/v1/market/quote?symbol=BTCUSDT",
{ headers: { "X-API-Key": API_KEY } }
);
const data = await response.json();
console.log(`当前价格: ${data.price}`);
cURL
curl -H "X-API-Key: your_key" "https://tickerlab.org/v1/market/quote?symbol=BTCUSDT"
响应示例
{
"symbol": "BTCUSDT",
"price": 42000.50,
"change": 120.50,
"change_percent": 0.28,
"volume": 1500.23,
"timestamp": "2024-03-20T10:00:00Z"
}
3. 历史数据导出 (History Export)
获取标准化的 OHLCV 历史数据列表,支持 CSV/JSON 导出。
端点
| 方法 | 端点 |
|---|
| GET | /v1/export/history |
参数
| 参数 | 类型 | 必填 | 默认 | 说明 |
|---|
symbol | string | ✅ | - | 标的代码 |
start_date | string | ✅ | - | 开始日期 (YYYY-MM-DD) |
end_date | string | ✅ | - | 结束日期 (YYYY-MM-DD) |
interval | string | - | 1d | 周期 |
format | string | - | csv | 输出格式: csv 或 json |
在线试用
代码示例
Python
import requests
API_KEY = "your_api_key"
response = requests.get(
"https://tickerlab.org/v1/export/history",
params={
"symbol": "SZSE:000001",
"start_date": "2024-01-01",
"end_date": "2024-12-31",
"format": "csv"
},
headers={"X-API-Key": API_KEY}
)
# 保存为 CSV 文件
with open("data.csv", "wb") as f:
f.write(response.content)
JavaScript
const response = await fetch(
"https://tickerlab.org/v1/export/history?symbol=SZSE:000001&start_date=2024-01-01&end_date=2024-12-31&format=json",
{ headers: { "X-API-Key": "your_api_key" } }
);
const data = await response.json();
console.log(data.values.slice(0, 5));
cURL
curl -H "X-API-Key: your_key" \
"https://tickerlab.org/v1/export/history?symbol=SZSE:000001&start_date=2024-01-01&end_date=2024-12-31&format=csv" \
-o data.csv
4. 批量图表生成 (Batch Chart)
一次性生成多张 K 线图表 (PNG格式)。
端点
| 方法 | 端点 |
|---|
| POST | /v1/market/chart/batch |
请求体 (JSON)
[
{
"symbol": "BTCUSDT",
"interval": "4h",
"studies": [{"name": "RSI"}]
},
{
"symbol": "000001.SZ",
"interval": "1d",
"studies": [{"name": "MACD"}, {"name": "VWAP"}]
}
]
代码示例
Python
import requests
API_KEY = "your_api_key"
# 定义批量生成的配置
payload = [
{
"symbol": "BTCUSDT",
"interval": "4h",
"studies": [{"name": "RSI"}]
},
{
"symbol": "000001.SZ",
"interval": "1d",
"studies": [{"name": "MACD"}, {"name": "VWAP"}]
}
]
response = requests.post(
"https://tickerlab.org/v1/market/chart/batch",
json=payload,
headers={"X-API-Key": API_KEY}
)
results = response.json()
# 打印生成的图表链接
for res in results["results"]:
print(f"股票代码: {res['symbol']}")
print(f"图表地址: {res['data']['url']}")
print("-" * 30)
JavaScript
const API_KEY = 'your_api_key';
const payload = [
{ symbol: "BTCUSDT", interval: "4h", studies: [{ name: "RSI" }] },
{ symbol: "000001.SZ", interval: "1d", studies: [{ name: "MACD" }] }
];
const response = await fetch("https://tickerlab.org/v1/market/chart/batch", {
method: "POST",
headers: {
"X-API-Key": API_KEY,
"Content-Type": "application/json"
},
body: JSON.stringify(payload)
});
const data = await response.json();
data.results.forEach(res => {
console.log(`${res.symbol}: ${res.data.url}`);
});
响应示例
{
"count": 2,
"results": [
{
"status": "ok",
"symbol": "BTCUSDT",
"data": {
"url": "https://tickerlab.org/static/charts/btc_rsi_4h.png",
"expires_at": "2024-03-20T11:00:00Z"
}
},
{
"status": "ok",
"symbol": "000001.SZ",
"data": {
"url": "https://tickerlab.org/static/charts/sz000001_macd_vwap_1d.png",
"expires_at": "2024-03-20T11:00:00Z"
}
}
]
}