historical-kline
Historical K-Line Data Query
Query historical K-line data for global stocks, forex, futures, cryptocurrencies, and other instruments. Supports multiple timeframes, returning open, high, low, close, and volume, suitable for financial data analysis.
Usage Cost
5 coins/call
Quick Start
Use a unified response envelope and call directly from your backend.
https://openapi.toolkk.com/v1/aliyunmarket-cmapi029045-query-comkm4v2cURL Example
curl --request GET \
--url 'https://openapi.toolkk.com/v1/aliyunmarket-cmapi029045-query-comkm4v2' \
--header 'Content-Type: application/json' \
--header 'X-API-Key: YOUR_API_KEY' \
--data '{\n "symbol": "品种合约代码(查询连接 http://demo.konpn.com/symbols.shtml",\n "period": "取 1M,3M,5M,10M,15M,30M,1H,2H,3H,4H,D,W,M。周期是1,5,15分钟则返回date当日的数据。 周期是30分钟或1小时则返回...",\n "date": "日期,返回结果排序顺序。接口输出的日周期数据最多只有10年,1分钟周期数据只有最近30天,5分钟及小时周期最多180天",\n "withlast": "是否包含最新的一个动态k线数据,(填写1是,0否)"\n}'Python Example
import os
import requests
url = "https://openapi.toolkk.com/v1/aliyunmarket-cmapi029045-query-comkm4v2"
payload = {
"symbol": "品种合约代码(查询连接 http://demo.konpn.com/symbols.shtml",
"period": "取 1M,3M,5M,10M,15M,30M,1H,2H,3H,4H,D,W,M。周期是1,5,15分钟则返回date当日的数据。 周期是30分钟或1小时则返回...",
"date": "日期,返回结果排序顺序。接口输出的日周期数据最多只有10年,1分钟周期数据只有最近30天,5分钟及小时周期最多180天",
"withlast": "是否包含最新的一个动态k线数据,(填写1是,0否)"
}
headers = {
"Content-Type": "application/json",
"X-API-Key": os.getenv("TOOLKK_API_KEY", "YOUR_API_KEY"),
}
response = requests.get(url, headers=headers, params=payload, timeout=30)
response.raise_for_status()
print(response.json())Go Example
package main
import (
"bytes"
"fmt"
"io"
"net/http"
)
func main() {
endpoint := "https://openapi.toolkk.com/v1/aliyunmarket-cmapi029045-query-comkm4v2"
payload := []byte("{\n \"symbol\": \"品种合约代码(查询连接 http://demo.konpn.com/symbols.shtml\",\n \"period\": \"取 1M,3M,5M,10M,15M,30M,1H,2H,3H,4H,D,W,M。周期是1,5,15分钟则返回date当日的数据。 周期是30分钟或1小时则返回...\",\n \"date\": \"日期,返回结果排序顺序。接口输出的日周期数据最多只有10年,1分钟周期数据只有最近30天,5分钟及小时周期最多180天\",\n \"withlast\": \"是否包含最新的一个动态k线数据,(填写1是,0否)\"\n}")
req, err := http.NewRequest("GET", endpoint, bytes.NewBuffer(payload))
if err != nil {
panic(err)
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-API-Key", "YOUR_API_KEY")
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println(string(body))
}Java Example
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class ToolkkExample {
public static void main(String[] args) throws Exception {
String payload = "{\n \"symbol\": \"品种合约代码(查询连接 http://demo.konpn.com/symbols.shtml\",\n \"period\": \"取 1M,3M,5M,10M,15M,30M,1H,2H,3H,4H,D,W,M。周期是1,5,15分钟则返回date当日的数据。 周期是30分钟或1小时则返回...\",\n \"date\": \"日期,返回结果排序顺序。接口输出的日周期数据最多只有10年,1分钟周期数据只有最近30天,5分钟及小时周期最多180天\",\n \"withlast\": \"是否包含最新的一个动态k线数据,(填写1是,0否)\"\n}";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://openapi.toolkk.com/v1/aliyunmarket-cmapi029045-query-comkm4v2"))
.method("GET", HttpRequest.BodyPublishers.ofString(payload))
.header("Content-Type", "application/json")
.header("X-API-Key", "YOUR_API_KEY")
.build();
HttpResponse<String> response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}PHP Example
<?php
$endpoint = 'https://openapi.toolkk.com/v1/aliyunmarket-cmapi029045-query-comkm4v2';
$payload = "{\n \"symbol\": \"品种合约代码(查询连接 http://demo.konpn.com/symbols.shtml\",\n \"period\": \"取 1M,3M,5M,10M,15M,30M,1H,2H,3H,4H,D,W,M。周期是1,5,15分钟则返回date当日的数据。 周期是30分钟或1小时则返回...\",\n \"date\": \"日期,返回结果排序顺序。接口输出的日周期数据最多只有10年,1分钟周期数据只有最近30天,5分钟及小时周期最多180天\",\n \"withlast\": \"是否包含最新的一个动态k线数据,(填写1是,0否)\"\n}";
$ch = curl_init($endpoint);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'X-API-Key: YOUR_API_KEY',
],
CURLOPT_POSTFIELDS => $payload,
]);
$response = curl_exec($ch);
if ($response === false) {
throw new RuntimeException(curl_error($ch));
}
curl_close($ch);
echo $response;Response Example
{
"code": "SUCCESS",
"message": "success",
"data": {
"Code": 0,
"Msg": "",
"Obj": "1600854240,10452.6,10455.8,10456.2,10452.5,0,5.37;1600854180,10455.8,10452.6,10455.8,10452.6,0,5.08"
}
}Examples illustrate the response structure. Actual results depend on the API response.
- Authentication
- Send X-API-Key in request headers
- Rate limit
- 60 req/min
- Timeout
- 5000 ms
Send your API Key in the X-API-Key header from your backend.
Check both HTTP status and business fields before treating a call as successful.
Use retries and backoff together with rate limits in high-frequency scenarios.
Request Fields
Send requests from your server with the key in the X-API-Key header.
Request Fields
Fields are read from the API schema. Missing descriptions and examples are marked as unspecified.
| Path | Type | Required | Description | Sample |
|---|---|---|---|---|
| symbol | string | Yes | 品种合约代码(查询连接 http://demo.konpn.com/symbols.shtml | Unspecified |
| period | string | Yes | 取 1M,3M,5M,10M,15M,30M,1H,2H,3H,4H,D,W,M。周期是1,5,15分钟则返回date当日的数据。 周期是30分钟或1小时则返回date当日及前2日的数据。 2~4小时则返回date当日及前9日的数据。 日则返回date当月及前2个月的数据,周则返回近2年数据,月则返回近5年数据 | Unspecified |
| date | string | Yes | 日期,返回结果排序顺序。接口输出的日周期数据最多只有10年,1分钟周期数据只有最近30天,5分钟及小时周期最多180天 | Unspecified |
| withlast | int | No | 是否包含最新的一个动态k线数据,(填写1是,0否) | Unspecified |
Request Example
{
"symbol": "品种合约代码(查询连接 http://demo.konpn.com/symbols.shtml",
"period": "取 1M,3M,5M,10M,15M,30M,1H,2H,3H,4H,D,W,M。周期是1,5,15分钟则返回date当日的数据。 周期是30分钟或1小时则返回...",
"date": "日期,返回结果排序顺序。接口输出的日周期数据最多只有10年,1分钟周期数据只有最近30天,5分钟及小时周期最多180天",
"withlast": "是否包含最新的一个动态k线数据,(填写1是,0否)"
}- Authentication
- Send X-API-Key in request headers
- Rate limit
- 60 req/min
- Timeout
- 5000 ms
Response Fields
Examples illustrate the response structure. Actual results depend on the API response.
Response Fields
The fields below are derived from example JSON for integration reference only.
| Path | Type | Required | Description | Sample |
|---|---|---|---|---|
| code | string | Unspecified | Unspecified | SUCCESS |
| message | string | Unspecified | Unspecified | success |
| data | object | Unspecified | Unspecified | {...} |
| data.Code | number | Unspecified | Unspecified | 0 |
| data.Msg | string | Unspecified | Unspecified | Unspecified |
| data.Obj | string | Unspecified | Unspecified | 1600854240,10452.6,10455.8,10456.2,10452.5,0,5.37;1600854180,10455.8,10452.6,10455.8,10452.6,0,5.08 |
Response Example
{
"code": "SUCCESS",
"message": "success",
"data": {
"Code": 0,
"Msg": "",
"Obj": "1600854240,10452.6,10455.8,10456.2,10452.5,0,5.37;1600854180,10455.8,10452.6,10455.8,10452.6,0,5.08"
}
}API overview
Capabilities, use cases, limitations, and frequently asked questions.
API Capabilities
This API provides historical K-line market data queries for various global financial instruments (including stocks, forex, futures, precious metals, cryptocurrencies, stock indices, etc.). It supports multiple timeframes from 1 minute to monthly (e.g., 1M, 5M, 15M, 30M, 1H, 4H, D, W, M). Based on the specified date and period, the API returns K-line data containing core metrics such as timestamp, open price, high price, low price, close price, and volume.
Request and Response
The request requires the instrument contract code (symbol), timeframe (period), base date (date), and whether to include the latest dynamic K-line (withlast). In the response, the Obj field contains a semicolon-separated string of K-line data. Each data group is comma-separated, representing: timestamp, open price, high price, low price, close price, open interest (for some instruments), and volume, respectively. Data is sorted from the start time to the end time.
Use Cases
- Quantitative Trading Backtesting: Obtain historical K-line data for writing and validating quantitative trading strategies and performing historical market backtesting.
- Financial Charting: Provide historical K-line data sources for financial news apps or websites, used for drawing K-line charts and technical indicator analysis.