
Can a Hong Kong Stock API Retrieve Historical K-Line Data? A Guide to Daily Bars, Minute Bars, and Historical Data
Learn how to retrieve historical Hong Kong stock K-line data, including daily and minute intervals, API limits, historical coverage, and data management strategies.
When developing a Hong Kong stock market data page, retrieving the latest price is usually only the first step. To let users review price movements over the past few months or switch to 1-minute and 5-minute intervals to monitor intraday changes, developers also need to consider how historical K-line data is retrieved and stored.
Therefore, when choosing a Hong Kong stock API, it is not enough to check whether it supports K-line data. Developers also need to understand which intervals are available, how many bars can be returned in a single request, and whether data before a specified date can be retrieved.
A Hong Kong stock API can provide historical K-line data, but daily and minute bars have different coverage ranges, and there are clear limits on the number of records returned per request and the methods available for retrieving older data. Projects that require several years of historical data, especially those involving quantitative backtesting, should confirm these limitations before development begins.
Which Historical K-Line Intervals Does a Hong Kong Stock API Support?
Daily and minute bars serve different market data use cases. Daily bars are commonly used to review medium- and long-term price movements and calculate indicators such as moving averages. Minute bars are more suitable for intraday charts and short-term analysis.
AllTick's stock K-line API supports the following intervals:
| K-Line Interval | Parameter Value | Common Use |
|---|---|---|
| 1 minute | 1 | Intraday price movements |
| 5 minutes | 2 | Short-term market monitoring |
| 15 minutes | 3 | Intraday trend analysis |
| 30 minutes | 4 | Intraday charts with longer intervals |
| 1 hour | 5 | Hourly trend analysis |
| Daily | 8 | Daily market and trend analysis |
| Weekly | 9 | Medium- and long-term price movements |
| Monthly | 10 | Long-term market analysis |
Hong Kong stocks belong to the stock data category. The shortest supported interval is 1 minute, while 2-hour and 4-hour K-lines are not supported. The single-symbol K-line API can return a maximum of 500 bars per request.
In practice, the initial data request can be determined by the default chart view. For example, a stock detail page can display daily bars by default and request the corresponding minute interval only when a user switches to an intraday chart. This avoids loading data that is not immediately needed when the page first opens.
How to Retrieve Historical K-Line Data with a Hong Kong Stock API
Take Tencent Holdings, identified by the symbol 700.HK, as an example. Suppose a market data page needs to display the latest 200 daily bars. This can be done through AllTick's stock K-line API.
The request uses the X-API-Key header for authentication, with query parameters placed in the queryData portion of the API path. The following is a Python example:
import os
import json
import uuid
import requests
from decimal import Decimal
from urllib.parse import quote
api_key = os.environ.get("ALLTICK_API_KEY")
if not api_key:
raise RuntimeError("Missing ALLTICK_API_KEY")
query_data = {
"trace": str(uuid.uuid4()),
"data": {
"code": "700.HK",
"kline_type": 8,
"kline_timestamp_end": 0,
"query_kline_num": 200,
"adjust_type": 0
}
}
base_url = (
"https://quote.alltick.co/"
"quote-stock-b-api/v1/kline/"
)
encoded_query = quote(
json.dumps(query_data, separators=(",", ":")),
safe=""
)
response = requests.get(
base_url + encoded_query,
headers={"X-API-Key": api_key},
timeout=15
)
response.raise_for_status()
result = response.json()
if result.get("ret") != 200:
raise RuntimeError(
f"AllTick API error: {result.get('msg')}"
)
raw_klines = result.get("data", {}).get("kline_list")
if not isinstance(raw_klines, list):
raise RuntimeError("Invalid K-line response")
bars = []
seen_timestamps = set()
for item in raw_klines:
timestamp = int(item["timestamp"])
if timestamp in seen_timestamps:
raise RuntimeError(
f"Duplicate K-line timestamp: {timestamp}"
)
seen_timestamps.add(timestamp)
bars.append({
"timestamp": timestamp,
"open": Decimal(item["open_price"]),
"high": Decimal(item["high_price"]),
"low": Decimal(item["low_price"]),
"close": Decimal(item["close_price"]),
"volume": Decimal(item["volume"]),
"turnover": Decimal(item["turnover"])
})
bars.sort(key=lambda item: item["timestamp"])
print(bars)
Several parameters directly determine the query results:
code: Specifies the stock symbol. In this example,700.HKrepresents Tencent Holdings.kline_type: Specifies the K-line interval.8represents daily bars, while1represents 1-minute bars.kline_timestamp_end: Specifies the query's ending position. Setting it to0retrieves data starting from the latest available trading interval.query_kline_num: Specifies the number of bars to retrieve. A maximum of 500 bars can be requested per call.adjust_type: Specifies the stock adjustment parameter. The currently documented supported value is0. Other values should not be treated as supported adjustment options unless the API documentation confirms them.
The response's kline_list contains fields such as timestamps, open prices, high prices, low prices, close prices, trading volume, and turnover. Price and trading data may be returned as strings. The example uses Decimal to preserve numerical precision and avoid the errors that can arise from using binary floating-point numbers directly in financial calculations.
The code also checks for duplicate timestamps and sorts the records chronologically. In a production environment, the stock symbol, K-line interval, and timestamp can be used together as a composite key to prevent duplicate records from being stored during repeated synchronization.
This code demonstrates the request structure and basic data-processing logic. It has not been tested with an actual API key.
How Much Historical Hong Kong Stock Data Can 500 K-Lines Cover?
This is an important limitation to consider when evaluating a historical data API for Hong Kong stocks.
Five hundred daily bars and 500 one-minute bars represent very different time spans. Daily bars generally cover a longer trading period, while minute bars accumulate much more quickly during market hours. Therefore, a maximum of 500 bars should not be interpreted as 500 days of historical data. Nor should developers assume that every interval provides the same historical coverage.
The restrictions on kline_timestamp_end also need to be considered. AllTick's documentation explains that setting this parameter to 0 retrieves data starting from the latest available trading interval. However, using a specified historical timestamp as the query boundary is not supported for stock symbols. In other words, developers cannot directly apply the timestamp-based pagination method used for forex or cryptocurrency data and repeatedly change the ending timestamp to retrieve older Hong Kong stock K-lines.
Plan coverage also needs to be understood separately. AllTick's comprehensive plan page lists different general historical K-line coverage periods, while stock data is separately specified as providing the latest 500 historical K-lines. The All HK Stocks plan also lists the latest 500 historical K-lines and covers approximately 3,000 Hong Kong stock symbols.
Therefore, the general historical coverage period displayed on a plan page should not be interpreted as meaning that every minute interval for every Hong Kong stock can be retrieved over the same number of years. The actual available coverage needs to be confirmed based on the stock symbol, K-line interval, and specific plan.
For projects that require several years of historical Hong Kong stock data, especially for long-term backtesting or research, developers should first identify the target symbols, required intervals, and start and end dates. They should then confirm whether the available data meets those requirements. If the API does not support querying historical stock data by a specified timestamp, alternative methods of obtaining historical data should be evaluated before development is completed, rather than discovering data gaps after the backtesting system has been built.
How to Reduce Repeated Requests for Hong Kong Stock Minute Data
Suppose a market data platform displays dozens of Hong Kong stocks, with both daily and 1-minute charts for each symbol. If the system retrieves the full set of historical K-lines every time a user opens a page, it not only increases API usage but also repeatedly transfers data that has already been stored.
A more suitable approach is to separate historical data initialization from the updating of the latest data:

Two K-line APIs are relevant here:
Single-symbol K-line API /v1/kline/{queryData}
This endpoint retrieves historical K-lines for a single symbol and returns up to 500 bars per request. It is suitable for initial chart loading when a user opens a stock detail page or when the local database does not contain the required interval data.
Batch K-line API /v1/batch-kline
This endpoint can query multiple symbols and multiple K-line intervals in a single request. However, it returns a maximum of the latest 2 bars for each symbol and each interval. It is more suitable for periodically updating the latest records in a local database and cannot replace historical K-line retrieval.
It is also important to note that AllTick WebSocket does not support K-line push. If an application needs real-time trade prices, Tick data, or order book data, developers should use the corresponding interfaces according to their requirements. Real-time market data push should not be treated as equivalent to K-line push.
For systems that monitor multiple Hong Kong stocks simultaneously, historical data can be retrieved as needed and stored in a database first. The batch K-line API can then be used to update the latest records. Using the stock symbol, interval, and timestamp to identify each record helps reduce duplicate storage and makes it easier to check whether the data is continuous.
How to Check the Completeness of Historical Hong Kong Stock K-Lines
Retrieving data from an API does not automatically mean that the returned K-lines meet an application's requirements. For minute bars in particular, a gap between timestamps should not automatically be treated as missing market data.
The Hong Kong stock market has normal non-trading periods, including the midday break, weekends, public holidays, and periods when individual stocks are suspended from trading. The absence of minute bars during these periods does not necessarily indicate a problem with the data source.
A more reliable approach is to first establish a trading calendar and then generate the expected timestamps based on the target stock's trading status and the selected K-line interval. Only when a timestamp is missing during a period when data is expected should the system investigate whether a data gap exists.
The following checks are also recommended:
- Timestamps: Store timestamps using a consistent time standard and convert them to Hong Kong time for display. This helps prevent K-line misalignment caused by inconsistent timezone handling.
- Duplicate records: Use the stock symbol, interval, and timestamp as a composite key to prevent duplicate records from being stored after repeated requests.
- Price fields: Check whether OHLC values can be parsed correctly. Also verify basic numerical relationships, such as the high being no lower than the open, close, and low, and the low being no higher than the open, close, and high.
- Trading fields: Confirm that volume and turnover can be parsed correctly. Do not automatically treat missing values as actual zero trading activity.
- Historical coverage: Record the earliest and latest timestamps retrieved for each symbol. This prevents the number of records returned by an API from being mistaken for complete historical coverage.
For a Hong Kong stock market data application, historical K-lines may be used not only for chart displays but also for indicator calculations, statistical analysis, and backtesting. Checking timestamps, duplicate records, and trading hours at an early stage can reduce the effort required to investigate problems later.
For projects that need to access a larger number of Hong Kong stock symbols, AllTick offers the All HK Stocks plan, which covers approximately 3,000 symbols and lists the latest 500 historical K-lines along with other market data capabilities. Developers can evaluate whether the plan is suitable based on the number of symbols, historical data requirements, and real-time update frequency.
Developers building Hong Kong stock charts, stock monitoring tools, or historical market analysis systems can visit the AllTick Hong Kong Stock Market Data Access Page to learn about the integration process. Before starting full development, it is recommended to verify the actual data coverage for the target symbols and intervals, then use those results to determine the data storage and historical market data management approach.