
Why Is Your Stock API Returning No Data? Check the Date, Symbol, and Trading Status
Learn how to troubleshoot empty stock API responses by checking trading dates, stock codes, API parameters, permissions, and market status before assuming a data service failure.
When integrating a stock market data API into a financial application, developers sometimes encounter a confusing situation: the request succeeds, the server returns a JSON response, but the chart displays no data.
For example, an application requests daily candles for a stock. The API returns ret=200, yet the frontend has no K-line records to display. Retrying the request or repeatedly changing the API Key is unlikely to solve the problem.
An empty response from a stock API does not necessarily indicate a service failure. A more effective troubleshooting process is to check the requested date first, verify the ticker symbol and API parameters, and then examine the instrument's trading status.
Check the Date First: Is There Actually Data for the Requested Period?
Stock markets do not trade every day. Weekends, public holidays, and temporary market closures generally do not generate new trading records. US stocks, Hong Kong stocks, and A-shares also follow different trading schedules, so the server's local time should not be used as the only reference for determining whether a trading session has started.
This matters particularly when building applications that handle multiple markets. Developers should use the relevant exchange timezone when processing dates and convert timestamps into the format expected by the API. Otherwise, the date displayed in the application may differ from the actual trading date represented in the request.
There is another important detail: the API's own timestamp limitations.
In AllTick's current stock K-line REST API, kline_timestamp_end defines the reference point for the query. However, stock symbols do not support custom timestamps. The parameter must be set to 0 to retrieve K-lines backward from the latest trading day. A single request can return up to 500 bars.
This means that converting an arbitrary historical date into a Unix timestamp and passing it to the stock API will not retrieve data before that date. Applications that need to reference historical data by arbitrary dates should consider maintaining their own local historical data store rather than assuming the API supports unrestricted timestamp-based queries.
The requested interval also matters. Stock K-lines support 1-minute, 5-minute, 15-minute, 30-minute, 1-hour, daily, weekly, and monthly intervals. However, 2-hour and 4-hour K-lines are not supported for stocks. An unsupported interval should be investigated as a parameter issue before treating it as a data-source failure.
Check the Stock Symbol: A Valid Ticker Is Not Necessarily a Supported Instrument
Stock symbols follow different formats across markets.
For example, AllTick uses 700.HK for Tencent Holdings and AAPL.US for Apple. The symbol must match the official product code list, including its capitalization and market suffix.
Sending a company name instead of its supported symbol, or mixing ticker formats from different markets, can prevent the API from locating the requested instrument.
Another easily overlooked issue is that stock data and forex or cryptocurrency data use different API endpoints.
AllTick's stock REST API uses a dedicated stock endpoint. Forex, precious metals, and cryptocurrencies use a separate API endpoint. Even when the ticker itself is correct, using the wrong endpoint can cause the instrument code to be rejected.
When troubleshooting, check the following:
- Confirm that the stock appears in the official product code list.
- Verify the market suffix and capitalization.
- Make sure the request uses the stock endpoint rather than the forex or cryptocurrency endpoint.
- Check whether the current API Key has permission to access the requested instrument.
Error responses should also be interpreted separately from empty data. For example, in the legacy HTTP Interface API, error code 600 indicates an invalid product code, while 604 indicates that the Token is not authorized to access the requested code.
There is an important version distinction: the newer /v1 REST API and the legacy HTTP Interface API use different endpoint paths, authentication methods, and request parameters. Developers should consult the documentation for the API version they actually use rather than automatically applying legacy error-code explanations to newer REST requests.
Check Trading Status: No New Trades Does Not Mean an API Failure
Once the requested date and stock symbol have been verified, check whether the market is open and whether the instrument has been suspended from trading.
Two situations need to be distinguished: a lack of new market updates and an inability to retrieve historical data are not the same problem.
For example, after the US market closes, the latest trade price may remain at the price recorded during the most recent trading session. A WebSocket connection that stops receiving new trade updates is not necessarily malfunctioning.
The same applies to the midday break in the Hong Kong market. A temporary pause in new trades does not mean that historical K-line records should disappear.
When a stock suspension is suspected, developers should also check the relevant exchange announcements and suspension or resumption information.
AllTick provides trading-status REST API endpoints for the Shanghai Stock Exchange (SSE), New York Stock Exchange (NYSE), and NASDAQ. These endpoints can be used to query suspension and resumption information for the supported exchanges. However, they do not directly cover Hong Kong stock suspensions. Developers working with Hong Kong stocks should check the relevant exchange announcements separately.
For applications using a real-time stock data API, trading status should be handled as an independent piece of information. A stock should not automatically be marked as abnormal just because no new Tick updates have arrived for a period of time.
Inspect the Actual K-Line API Response with Python
When troubleshooting empty data, it is useful to bypass the frontend chart and call the API directly. Inspecting the JSON response helps determine whether the data source returned no records or whether the frontend failed to parse or display the response correctly.
The following example requests daily K-lines for Tencent Holdings (700.HK) using AllTick's current REST API request format:
import os
import json
import uuid
import requests
from urllib.parse import quote
api_key = os.environ["ALLTICK_API_KEY"]
query_data = {
"trace": str(uuid.uuid4()),
"data": {
"code": "700.HK",
"kline_type": 8,
"kline_timestamp_end": 0,
"query_kline_num": 10,
"adjust_type": 0
}
}
encoded_data = quote(
json.dumps(query_data, separators=(",", ":")),
safe=""
)
url = (
"https://quote.alltick.co/"
"quote-stock-b-api/v1/kline/"
+ encoded_data
)
response = requests.get(
url,
headers={"X-API-Key": api_key},
timeout=15
)
response.raise_for_status()
result = response.json()
if result.get("ret") != 200:
raise RuntimeError(
f"API error: {result.get('ret')} - {result.get('msg')}"
)
data = result.get("data") or {}
kline_list = data.get("kline_list") or []
if not kline_list:
print("No K-line data returned")
else:
print("Returned bars:", len(kline_list))
print("Latest bar:", kline_list[-1])
Several parameters are worth understanding.
kline_type=8 specifies daily K-lines. kline_timestamp_end=0 retrieves data backward from the latest trading day. query_kline_num=10 requests 10 K-line bars, while adjust_type=0 specifies the stock adjustment type currently supported by the API.
The code first checks the response's ret value and then reads data.kline_list. If the request succeeds but the array is empty, developers can continue investigating the date, symbol, interval, and access permissions rather than assuming that a successful HTTP request guarantees available market data.
There is also a difference between an empty K-line array and a valid K-line record containing zero-valued fields.
For example, if the response includes K-line records but volume or turnover contains the string "0", that alone does not mean the data is missing. Check the open price, close price, and timestamp as well before determining whether the record is valid.
Do Not Rely on Retries to Solve Every Empty-Data Problem
For fintech developers, retry mechanisms can help recover from temporary network failures. However, they cannot fix an incorrect stock symbol, an unsupported K-line interval, or an invalid time parameter.
A better approach is to classify problems according to their likely causes.
If the requested date or trading session is incorrect, check the market calendar and timezone. If the symbol is invalid, verify the product code and market-specific endpoint. If access is denied, review the API Key and subscription permissions. If the request succeeds but returns no K-line records, examine the query parameters and available data coverage.
AllTick provides stock market data APIs covering US stocks, Hong Kong stocks, and A-shares, with REST API access to latest quotes and historical K-line data. For teams building stock dashboards, historical charts, or market-monitoring applications, REST API requests can be used to retrieve historical data and initialize snapshots, while real-time API connections can handle continuous market updates.
Before integrating multiple markets, review AllTick's stock API product information and the official stock K-line REST API documentation. Start by testing one confirmed supported symbol, verify the response, and then expand to additional markets. This approach is generally more effective than investigating a large group of instruments simultaneously.