如今,量化分析在股市领域风靡一时,其核心要素在于数据,获取股票数据,是踏上量化分析之路的第一步。你可以选择亲手编写爬虫来抓取,但更便捷的方式,莫过于利用专业的股票数据API接口。自编爬虫虽零成本,却伴随着时间与精力的巨大消耗,且常因目标页面变动而失效。大家可以依据自己的实际情况来决定数据获取方式。
接下来,我将分享200多个实测可用且免费的专业股票数据接口,并通过Python、JavaScript(Node.js)、Java、C#、Ruby等五种主流语言,逐一演示如何高效获取各类股票数据,希望能够对大家有所帮助。
先把数据接口的地址给大家,大家可以直接点击地址或复制到地址栏打开,马上就可以验证接口的有效性
沪深A股融资融券历史走势股数据API接口:http://api.mairui.club/hsrq/lszs/000001/LICENCE-66D8-9F96-0C7F0FBCD073
接口URL中,000001是股票代码,LICENCE-66D8-9F96-0C7F0FBCD073是请求证书,这个是官方提供的测试证书只能测试000001的数据,随后大家自己可以去领取一个免费的请求证书就可以获取其他股票的数据了。
1、python
python
import requests
url = "http://api.mairui.club/hsrq/lszs/000001/LICENCE-66D8-9F96-0C7F0FBCD073"
response = requests.get(url)
data = response.json()
print(data)
2、JavaScript (Node.js)
javascript
const axios = require('axios');
const url = "http://api.mairui.club/hsrq/lszs/000001/LICENCE-43D5-9F96-0C7F0FBCD073";
axios.get(url)
.then(response => {
console.log(response.data);
})
.catch(error => {
console.log(error);
});
3、Java
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("http://api.mairui.club/hsrq/lszs/000001/LICENCE-43D5-9F96-0C7F0FBCD073"))
.build();
try {
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
}
4、C#
csharp
using System;
using System.Net.Http;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
using (HttpClient client = new HttpClient())
{
string url = "http://api.mairui.club/hsrq/lszs/000001/LICENCE-43D5-9F96-0C7F0FBCD073";
HttpResponseMessage response = await client.GetAsync(url);
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
}
}
}
5、Ruby
ruby
require 'net/http'
require 'json'
url = URI("http://api.mairui.club/hsrq/lszs/000001/LICENCE-43D5-9F96-0C7F0FBCD073")
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
返回数据示例:
json
[{"rq":"2025-01-22","rzrqye":4878153364.0,"rzrqyecz":4871341886.0,"p":11.09,"zdf1":-2.12,"zdf3":-3.14,"zdf5":-3.4,"zdf10":-3.57,"rzye":4874747625.0,"rzyezb":2.27,"rzmre1":271154323.0,"rzmre3":596470944.0,"rzmre5":824929259.0,"rzmre10":1396631870.0,"rzche1":123876772.0,"rzche3":352926487.0,"rzche5":573355662.0,"rzche10":1178590192.0,"rzjm1":147277551.0,"rzjm3":243544457.0,"rzjm5":251573597.0,"rzjm10":218041678.0,"rqye":3405739.0,"rqyl":307100.0,"rqmcl1":51700.0,"rqmcl3":100300.0,"rqmcl5":354500.0,"rqmcl10":639300.0,"rqchl1":102700.0,"rqchl3":282400.0,"rqchl5":346500.0,"rqchl10":807400.0,"rqjmc1":-51000.0,"rqjmc3":-182100.0,"rqjmc5":8000.0,"rqjmc10":-168100.0},
返回的数据字段说明:
rq代表:交易日期(yyyy-MM-dd),rzrqye代表:当日融资融券余额(元),rzrqyecz代表:当日融资融券余额差值(元),p代表:当日收盘价(元),zdf1代表:当日涨跌幅(%),zdf3代表:3日涨跌幅(%),zdf5代表:5日涨跌幅(%),zdf10代表:10日涨跌幅(%),rzye代表:融资当日余额(元),rzyezb代表:融资当日余额占流通市值比(%),rzmre1代表:融资当日买入额(元),rzmre3代表:融资3日买入额(元),rzmre5代表:融资5日买入额(元),rzmre10代表:融资10日买入额(元),rzche1代表:融资当日偿还额(元),rzche3代表:融资3日偿还额(元),rzche5代表:融资5日偿还额(元),rzche10代表:融资10日偿还额(元),rzjm1代表:融资当日净买入额(元),rzjm3代表:融资3日净买入额(元),rzjm5代表:融资5日净买入额(元),rzjm10代表:融资10日净买入额(元),rqye代表:融券当日余额(元),rqyl代表:融券当日余量(股),rqmcl1代表:融券当日卖出量(股),rqmcl3代表:融券3日卖出量(股),rqmcl5代表:融券5日卖出量(股),rqmcl10代表:融券10日卖出量(股),rqchl1代表:融券当日偿还量(股),rqchl3代表:融券3日偿还量(股),rqchl5代表:融券5日偿还量(股),rqchl10代表:融券10日偿还量(股),rqjmc1代表:融券当日净卖出量(股),rqjmc3代表:融券3日净卖出量(股),rqjmc5代表:融券5日净卖出量(股),rqjmc10代表:融券10日净卖出量(股)