快速开始
5 分钟完成首次请求:注册获取 API Key → 复制示例 → 发起首个调用 → 订阅实时推送。
1. 获取 API Key
在 定价 选择 Free 套餐即可免费获取 API Key,无需信用卡。Key 形如 rtk_xxxx_<secret>,明文仅展示一次,请妥善保存。
2. 发起首个 HTTP 请求(curl)
curl "https://api.rtick.io/api/market/kline/history?sym=AAPL.US&ktype=1m&count=500" \
-H "apiKey: <your_api_key>"
响应(按时间升序返回最新 500 根 1 分钟 K 线):
{
"code": 200,
"msg": "success",
"data": [
{
"sym": "AAPL.US",
"ktype": "1m",
"data": [
[1781962200, 180.50, 181.20, 182.00, 179.80, 480220.0, 86677688.40, 180.00, 1.20, 0.67, 2]
]
}
]
}
单根 K 线 11 列索引定义见 历史 K 线。
3. Python 示例
import requests
api_key = "<your_api_key>"
r = requests.get(
"https://api.rtick.io/api/market/kline/history",
headers={"apiKey": api_key},
params={"sym": "AAPL.US", "ktype": "1m", "count": 500},
)
bars = r.json()["data"][0]["data"]
# bars[i] = [time, open, close, high, low, volume, turnover,
# pre_close, chg, rate, session]
print("first:", bars[0])
print("last:", bars[-1])
4. JavaScript 示例(HTTP)
const res = await fetch(
"https://api.rtick.io/api/market/kline/history?sym=AAPL.US&ktype=1m&count=500",
{ headers: { apiKey: "<your_api_key>" } }
);
const { data } = await res.json();
console.log("bars:", data[0].data);
5. 订阅实时行情(WebSocket)
const ws = new WebSocket("wss://api.rtick.io/ws?apiKey=<your_api_key>");
ws.onopen = () =>
ws.send(
JSON.stringify({
requestId: "sub-001",
action: "sub",
syms: "AAPL.US,NVDA.US",
sub_types: "1,2", // 1=K线, 2=Tick
ktypes: "1m,5m",
})
);
ws.onmessage = (e) => {
const { event, data } = JSON.parse(e.data);
// event: 1=K线 2=Tick 3=盘口 4=分时
console.log(event, data);
};
WebSocket 协议详见 协议总览。