DEV Community

San Si wu
San Si wu

Posted on

Free Access to Stock Historical Quotes and Intraday K-Line Data API

In the global financial markets, obtaining accurate stock historical quote data is crucial. Whether for investors and developers in markets such as Hong Kong stocks, US stocks, A-shares, Japanese stocks, German, or Singapore, reliable stock intraday K-line data is needed to support analysis and decision-making. This article introduces an efficient stock API that supports batch historical K-line data API queries, helping you easily obtain OHLCV data from minute-level to monthly lines, including open price, high price, low price, close price, and trading volume key indicators.

API Overview

This API comes from itick.org, providing historical K-line data for global stock markets, covering thousands of stocks. Supported markets include HK (Hong Kong stocks), US (US stocks), SZ/SH (A-shares), JP (Japanese stocks), DE (Germany), SG (Singapore), etc. The data includes standard OHLC fields (open, high, low, close), and supports multiple time periods such as 1 minute, 5 minutes, daily K, weekly K, and monthly K. Through simple GET requests, you can obtain historical quote data for single or batch stocks, ensuring data accuracy and real-time performance.

This API is particularly suitable for TradingView chart integration, quote software development, or quantitative analysis. Register to obtain a free token with reasonable query limits.

Single Stock Historical K-Line Query

Interface Address

GET /stock/kline?region={region}&code={code}&kType={kType}&limit={limit}&et={et}

Request Parameters

  • region: Market code (e.g., HK, US, SZ, etc.), required.
  • code: Stock code (e.g., 700), required.
  • kType: K-line type (1: minute K, 2: 5-minute K, ..., 10: monthly K), required.
  • limit: Number of K-lines, required.
  • et: End timestamp (optional, defaults to current time).

Response Parameters

  • t: Timestamp
  • o: Open price
  • h: High price
  • l: Low price
  • c: Close price
  • v: Trading volume
  • tu: Trading amount

Python Example Code

The following is an example of using Python to request single stock K-line data:

import requests

url = "https://api.itick.org/stock/kline?region=HK&code=700&kType=2&limit=10"

headers = {
    "accept": "application/json",
    "token": "your_token"
}

response = requests.get(url, headers=headers)

print(response.text)
Enter fullscreen mode Exit fullscreen mode

Java Example Code

The following is an example of using Java (OkHttp library) to request single stock K-line data:

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
    .url("https://api.itick.org/stock/kline?region=HK&code=700&kType=2&limit=10")
    .get()
    .addHeader("accept", "application/json")
    .addHeader("token", "your_token")
    .build();

Response response = client.newCall(request).execute();
System.out.println(response.body().string());
Enter fullscreen mode Exit fullscreen mode

Go Example Code

The following is an example of using Go to request single stock K-line data:

package main

import (
    "fmt"
    "net/http"
    "io"
)

func main() {
    url := "https://api.itick.org/stock/kline?region=HK&code=700&kType=2&limit=10"

    req, _ := http.NewRequest("GET", url, nil)

    req.Header.Add("accept", "application/json")
    req.Header.Add("token", "your_token")

    res, _ := http.DefaultClient.Do(req)

    defer res.Body.Close()
    body, _ := io.ReadAll(res.Body)

    fmt.Println(string(body))
}
Enter fullscreen mode Exit fullscreen mode

Example Response

{
  "code": 0,
  "msg": null,
  "data": [
    {
      "tu": 56119888070.5,
      "c": 534.5,
      "t": 1741239000000,
      "v": 104799385,
      "h": 536,
      "l": 534.5,
      "o": 535
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

Batch Historical K-Line Query

For scenarios where data for multiple stocks needs to be obtained simultaneously, the batch interface is more efficient.

Interface Address

GET /stock/klines?region={region}&codes={codes}&kType={kType}&limit={limit}&et={et}

Request Parameters

  • region: Market code, required.
  • codes: Stock codes, separated by commas (e.g., 700,9988), required.
  • kType: K-line type, required.
  • limit: Number of K-lines, required.
  • et: End timestamp (optional).

Response Parameters

The response is an object where the keys are stock codes and the values are arrays of K-line data (same as single query).

Python Example Code

The following is a Python example for batch query:

import requests

url = "https://api.itick.org/stock/klines?region=HK&codes=700,9988&kType=2&limit=5"

headers = {
    "accept": "application/json",
    "token": "your_token"
}

response = requests.get(url, headers=headers)

print(response.text)
Enter fullscreen mode Exit fullscreen mode

Java Example Code

The following is a Java (OkHttp library) example for batch query:

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
    .url("https://api.itick.org/stock/klines?region=HK&codes=700,9988&kType=2&limit=5")
    .get()
    .addHeader("accept", "application/json")
    .addHeader("token", "your_token")
    .build();

Response response = client.newCall(request).execute();
System.out.println(response.body().string());
Enter fullscreen mode Exit fullscreen mode

Go Example Code

The following is a Go example for batch query:

package main

import (
    "fmt"
    "net/http"
    "io"
)

func main() {
    url := "https://api.itick.org/stock/klines?region=HK&codes=700,9988&kType=2&limit=5"

    req, _ := http.NewRequest("GET", url, nil)

    req.Header.Add("accept", "application/json")
    req.Header.Add("token", "your_token")

    res, _ := http.DefaultClient.Do(req)

    defer res.Body.Close()
    body, _ := io.ReadAll(res.Body)

    fmt.Println(string(body))
}
Enter fullscreen mode Exit fullscreen mode

Example Response

{
  "code": 0,
  "msg": null,
  "data": {
    "700": [
      {
        "tu": 56119888070.5,
        "c": 534.5,
        "t": 1741239000000,
        "v": 104799385,
        "h": 536,
        "l": 534.5,
        "o": 535
      }
    ],
    "9988": [
      {
        "tu": 75404622753.1,
        "c": 140.1,
        "t": 1741239000000,
        "v": 538602171,
        "h": 140.3,
        "l": 139.8,
        "o": 139.9
      }
    ]
  }
}
Enter fullscreen mode Exit fullscreen mode

Usage Notes

  • Replace "your_token" in the headers with your actual registered token.
  • The API supports high concurrency, but the free version has query limits; upgrade as needed.
  • Data timestamps are Unix timestamps for easy processing.
  • Java examples require importing the OkHttp library; Go examples use the standard library.

Conclusion

Through the introduction in this article, we understand that this free stock historical data API is a powerful and easy-to-use tool that can meet the K-line data needs for different markets and different periods. Whether you are an individual investor, financial analyst, or quantitative trading developer, this API can provide you with accurate and timely global stock quote data support.
For users who wish to build their own financial analysis systems, develop trading strategies, or conduct market research, this API is undoubtedly an ideal choice. The free quota is sufficient to support small and medium-scale project development and testing, while paid plans can provide higher frequency and more stable data services for professional users.

Friendly Reminder: This article is for reference only and does not constitute any investment advice. The market involves risks; invest with caution.

Reference Documentation: https://docs.itick.org/
GitHub: https://github.com/itick-org/

Top comments (0)