Historical K-Line API: Periods & Limits
Use K-line query parameters and Python timestamp pagination for supported FX/metals instruments, with explicit stock cursor and per-request limits.
Core Takeaway · 30-Second Brief
K-line queries specify symbol, timeframe, end timestamp, and count. The current /kline specification permits timestamp pagination for forex, precious metals, and crypto, but not stock codes. The EURUSD example paginates backward with deduplication; stock history must be evaluated separately against the official specification and plan.
01
AllTick K-Line Query Parameters
| Parameter | Meaning | Notes |
|---|---|---|
code | Ticker symbol | EURUSD for this FX pagination example |
kline_type | Bar timeframe | Minute, hour, daily, weekly, etc. (see official docs) |
kline_timestamp_end | End timestamp cursor | 0 starts from latest; stock codes do not support timestamp cursors |
query_kline_num | Number of bars requested | Maximum 500 per request |
adjust_type | Corporate action adjustment | 0 for unadjusted; check docs for other modes |
02
Single Fetch & Backward Pagination in Python
import json, os, time, uuidimport requestsBASE_URL = "https://quote.alltick.co/quote-b-api"def fetch_kline(code: str, kline_type: int, end_ts: int = 0, num: int = 100) -> list[dict]: token = os.getenv("ALLTICK_API_TOKEN", "YOUR_API_TOKEN") query = { "trace": str(uuid.uuid4()), "data": { "code": code, "kline_type": kline_type, "kline_timestamp_end": end_ts, "query_kline_num": num, "adjust_type": 0, }, } resp = requests.get( f"{BASE_URL}/kline", params={"token": token, "query": json.dumps(query)}, timeout=10, ) body = resp.json() if resp.content else {} if body.get("ret") != 200: raise RuntimeError(f"ret={body.get('ret')} msg={body.get('msg')}") resp.raise_for_status() return body.get("data", {}).get("kline_list", [])def fetch_history(code: str, kline_type: int, pages: int = 3, num: int = 100) -> list[dict]: bars: dict[int, dict] = {} end_ts = 0 for _ in range(pages): batch = fetch_kline(code, kline_type, end_ts, num) if not batch: break for bar in batch: bars[int(bar["timestamp"])] = bar earliest = min(int(b["timestamp"]) for b in batch) if end_ts and earliest >= end_ts: break end_ts = earliest time.sleep(10) return [bars[k] for k in sorted(bars)]if __name__ == "__main__": klines = fetch_history("EURUSD", kline_type=8, pages=2, num=10) for bar in klines[-5:]: print(bar.get("timestamp"), bar.get("close_price"), bar.get("volume"))03
Historical Depth & Plan Tier Limits
A 500-bar per-request cap does not establish the total history available. Timestamp pagination is asset-specific and currently unavailable for stock codes. Verify permitted history, intervals, and token quotas for your chosen asset and plan before designing a backtest.
- Stop paginating when the response returns an empty list or the earliest timestamp stops advancing.
- For multi-year backtesting, check plan lookback limits first and persist bars into your own database.
- Daily and higher timeframes cover a much longer calendar span per bar than 1-minute bars.
Sources & Verification · 2026-10-13
Relevant endpoint, field, and exchange rules were checked against the primary specifications linked below.
Python examples passed ast.parse on Python 3.14.0. This checks syntax only; dependencies, runtime compatibility, and network responses were not tested.
Authenticated AllTick requests and production end-to-end tests were not run for this review. Record your token plan, library versions, market session, ret/trace, and observed results when reproducing these checks.
Primary specifications
Reproduce before deployment
- The current /kline timestamp cursor supports FX, precious metals, and crypto, not stock codes. The EURUSD example uses /quote-b-api; do not promise deeper stock history with this loop.
- Request at most 500 bars, deduplicate boundaries, and stop on empty or nonadvancing pages. Per-request caps and plan lookback limits are separate; apply the token quota between requests.