如今,量化分析在股市领域风靡一时,其核心要素在于数据,获取股票数据,是踏上量化分析之路的第一步。你可以选择亲手编写爬虫来抓取,但更便捷的方式,莫过于利用专业的股票数据API接口。自编爬虫虽零成本,却伴随着时间与精力的巨大消耗,且常因目标页面变动而失效。大家可以依据自己的实际情况来决定数据获取方式。
接下来,我将分享200多个实测可用且免费的专业股票数据接口>股票数据接口,并通过Python、JavaScript(Node.js)、Java、C#、Ruby等五种主流语言,逐一演示如何高效获取各类股票数据,希望能够对大家有所帮助。
先把数据接口的地址给大家,大家可以直接点击地址或复制到地址栏打开,马上就可以验证接口的有效性
沪深A股最新分时MA数据API接口:http://api.mairui.club/hszb/ma/000001/60m/LICENCE-66D8-9F96-0C7F0FBCD073
接口URL中,000001是股票代码,60m是分时级别,LICENCE-66D8-9F96-0C7F0FBCD073是请求证书。
1、python
python">import requests
url = "http://api.mairui.club/hszb/ma/000001/60m/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/hszb/ma/000001/60m/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/hszb/ma/000001/60m/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#
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/hszb/ma/000001/60m/LICENCE-43D5-9F96-0C7F0FBCD073";
HttpResponseMessage response = await client.GetAsync(url);
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
}
}
}
5、Ruby
require 'net/http'
require 'json'
url = URI("http://api.mairui.club/hszb/ma/000001/60m/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
返回数据示例:
{"t":"2024-08-30 15:00","ma3":"10.21","ma5":"10.18","ma10":"10.21","ma15":"10.27","ma20":"10.32","ma30":"10.34","ma60":"10.23","ma120":"10.17","ma200":null,"ma250":null}
返回的数据字段说明:
t代表:时间,短分时级别格式为YYYY-MM-DD HH:MM,日线级别为yyyy-MM-dd,ma3代表:MA3,没有则为null,ma5代表:MA5,没有则为null,ma10代表:MA10,没有则为null,ma15代表:MA20,没有则为null,ma20代表:MA20,没有则为null,ma30代表:MA30,没有则为null,ma60代表:MA60,没有则为null,ma120代表:MA120,没有则为null,ma200代表:MA200,没有则为null,ma250代表:MA250,没有则为null