在量化分析领域,实时且准确的数据接口是成功的基石。经过多次实际测试,我将已确认可用的数据接口分享给正在从事量化分析的朋友们,希望能够对你们的研究和工作有所帮助,接下来我会用Python、JavaScript(Node.js)、Java、C#和Ruby五种主流语言的实例代码给大家逐一演示一下如何获取各类股票数据。
在下方,所有演示中的API接口Url链接结尾的ZHITU_TOKEN_LIMIT_TEST,均为数据请求token证书,因为这个证书是官方测试证书,仅可用于验证各个接口的有效性,所以这个证书限制了只可请求股票代码为000001的数据,正式环境中是不能使用的,证书可以自己去申请一个替换掉就好了(证书是免费申请的),替换成自己申请的证书就可以请求任何股票数据了。
1、python
import requests
url = "https://api.zhituapi.com/hs/msg/cwbg/000001?token=ZHITU_TOKEN_LIMIT_TEST"
response = requests.get(url)
data = response.json()
print(data)
2、JavaScript (Node.js)
const axios = require('axios');
const url = "https://api.zhituapi.com/hs/msg/cwbg/000001?token=ZHITU_TOKEN_LIMIT_TEST";
axios.get(url)
.then(response => {
console.log(response.data);
})
.catch(error => {
console.log(error);
});
3、Java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.io.IOException;
public class Main {
public static void main(String[] args) {
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.zhituapi.com/hs/msg/cwbg/000001?token=ZHITU_TOKEN_LIMIT_TEST"))
.build();
try {
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
}
4、C#
using System;
using System.Net.Http;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
using (HttpClient client = new HttpClient())
{
string url = "https://api.zhituapi.com/hs/msg/cwbg/000001?token=ZHITU_TOKEN_LIMIT_TEST";
HttpResponseMessage response = await client.GetAsync(url);
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
}
}
}
5、Ruby
require 'net/http'
require 'json'
url = URI("https://api.zhituapi.com/hs/msg/cwbg/000001?token=ZHITU_TOKEN_LIMIT_TEST")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Get.new(url)
response = http.request(request)
data = JSON.parse(response.read_body)
puts data
返回的数据:
[{"t":"2025-03-15","title":"平安银行:2024年年度报告","type":"年度报告全文","file":"https://pdf.dfcfw.com/pdf/H2_AN202503141644379555_1.pdf"},{"t":"2025-03-15","title":"平安银行:2024年年度报告摘要","type":"年度报告摘要","file":"https://pdf.dfcfw.com/pdf/H2_AN202503141644379768_1.pdf"},{"t":"2025-03-15","title":"平安银行:2024年度利润分配预案公告","type":"分配预案","file":"https://pdf.dfcfw.com/pdf/H2_AN202503141644379773_1.pdf"},{"t":"2024-12-07","title":"平安银行:2023年年度报告补充公告","type":"年度报告补充公告","file":"https://pdf.dfcfw.com/pdf/H2_AN202412061641211135_1.pdf"},{"t":"2024-10-19","title":"平安银行:2024年第三季度报告","type":"三季度报告全文","file":"https://pdf.dfcfw.com/pdf/H2_AN202410181640364060_1.pdf"},{"t":"2024-09-26","title":"平安银行:2024年半年度权益分派实施公告","type":"分配方案实施","file":"https://pdf.dfcfw.com/pdf/H2_AN202409251640035609_1.pdf"},{"t":"2024-08-16","title":"平安银行:2024年半年度报告","type":"半年度报告全文","file":"https://pdf.dfcfw.com/pdf/H2_AN202408151639295945_1.pdf"},{"t":"2024-08-16","title":"平安银行:2024年半年度财务报告","type":"半年度财务报告","file":"https://pdf.dfcfw.com/pdf/H2_AN202408151639295936_1.pdf"},{"t":"2024-08-16","title":"平安银行:2024年半年度报告摘要","type":"半年度报告摘要","file":"https://pdf.dfcfw.com/pdf/H2_AN202408151639295932_1.pdf"},{"t":"2024-06-06","title":"平安银行:2023年年度权益分派实施公告","type":"分配方案实施","file":"https://pdf.dfcfw.com/pdf/H2_AN202406051635603437_1.pdf"},{"t":"2024-05-25","title":"平安银行:2023年年度股东大会决议公告","type":"分配方案决议公告","file":"https://pdf.dfcfw.com/pdf/H2_AN202405241634558155_1.pdf"},{"t":"2024-04-20","title":"平安银行:2024年第一季度报告","type":"一季度报告全文","file":"https://pdf.dfcfw.com/pdf/H2_AN202404191630666627_1.pdf"},{"t":"2024-03-15","title":"平安银行:2023年年度报告","type":"年度报告全文","file":"https://pdf.dfcfw.com/pdf/H2_AN202403141626755379_1.pdf"}]
API地址:https://api.zhituapi.com/hs/msg/cwbg/股票代码?token=token证书
描述:个股历史所有财务报告类公告,按日期倒序。
更新频率:每日20:20
字段名称 | 数据类型 | 字段说明 |
---|---|---|
t | string | 公告日期,yyyy-MM-dd |
title | string | 公告标题 |
type | string | 公告类型 |
file | string | 原文件,http://xxx.pdf |