? 隨著量化投資在金融市場的快速發展,高質量數據源已成為量化研究的核心基礎設施。本文將系統介紹股票量化分析中的數據獲取解決方案,涵蓋實時行情、歷史數據及基本面信息等關鍵數據類型。
本文將重點演示這些接口在以下技術棧中的實現:
Python | JavaScript(Node.js) | Java | C# | Ruby五種主流語言的代碼示例,詳細演示如何高效獲取各類股票數據。
1、python
import requests url = "http://api.biyingapi.com/hsindex/real/time/000001/biyinglicence"
response = requests.get(url)
data = response.json()
print(data)
2、JavaScript (Node.js)
const axios = require('axios'); const url = "http://api.biyingapi.com/hsindex/real/time/000001/biyinglicence";
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("http://api.biyingapi.com/hsindex/real/time/000001/biyinglicence")) .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.biyingapi.com/hsindex/real/time/000001/biyinglicence"; 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.biyingapi.com/hsindex/real/time/000001/biyinglicence") 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
返回的數據示例:
{"ud":57.803,"pc":1.5109,"zf":1.1394,"p":3883.562,"o":3848.163,"h":3883.562,"l":3839.972,"yc":3825.759,"cje":1360903869000,"v":885474802,"pv":885474802,"tv":1407023,"t":"2025-08-25 15:00:09"}
實時交易數據
API接口:http://api.biyingapi.com/hsindex/real/time/000001/biyinglicence
接口說明:根據《指數列表》得到的股票代碼獲取實時交易數據(您可以理解為日線的最新數據)。
數據更新:實時
字段名稱 | 數據類型 | 字段說明 |
---|---|---|
p | number | 最新價 |
o | number | 開盤價 |
h | number | 最高價 |
l | number | 最低價 |
yc | number | 前收盤價 |
cje | number | 成交總額 |
v | number | 成交總量 |
pv | number | 原始成交總量 |
ud | float | 漲跌額 |
pc | float | 漲跌幅 |
zf | float | 振幅 |
t | string | 更新時間 |