获取标的历史 K 线
该接口用于获取标的的历史 K 线数据。
SDK Links
Python |
Rust |
Go |
Node.js |
信息
业务指令:27
Request
Parameters
Name | Type | Required | Description |
---|---|---|---|
symbol | string | 是 | 标的代码,使用 ticker.region 格式,例如:700.HK |
period | int32 | 是 | k 线周期,例如:1000 ,详见 Period |
adjust_type | int32 | 是 | 复权类型,例如:0 ,详见 AdjustType |
query_type | int32 | 是 | 查询方式 可选值: 1 - 按偏移查询 2 - 按日期区间查询 |
date_request | object | 否 | 按日期查询时必填 |
∟ start_date | string | 否 | 开始日期,格式为 YYYYMMDD ,例如:20231016 参数说明: 1. start_date 和 end_date 均不填:返回最新的 1000 根 K 线; 2. 仅填 start_date:返回 start_date 与最新交易日区间内的 K 线。若此区间内 K 线超过 1000 根,则优先返回靠近 start_date 的 1000 根 K 线; 3. 仅填 end_date:返回 end_date 及以前的 1000 根 K 线; 4. start_date 和 end_date 均填:返回此区间内的 K 线数据。若此区间内 K 线超过 1000 根,则优先返回靠近 end_date 的 1000 根 K 线 |
∟ end_date | string | 否 | 结束日期,格式为 YYYYMMDD ,例如:20231016 |
offset_request | object | 否 | 按偏移查询时必填 |
∟ direction | int32 | 是 | 查询方向 可选值: 0 - 向历史数据方向查找 1 - 向最新数据方向查找 |
∟ date | string | 否 | 查询日期,格式为 YYYYMMDD ,例如:20231016,为空时使用标的所在市场的最新交易日 |
∟ minute | string | 否 | 查询时间,格式为 HHMM ,例如:09:35,仅在查询分钟级别 K 线时有效 |
∟ count | int32 | 否 | 查询数量,填写范围 [1,1000] ,为空时默认查询 10 条 |
trade_session | int32 | 否 | 交易時段,0: 盤中,100: 所有延長時段(盤前,盤中,盤後,夜盤) |
Protobuf
message SecurityHistoryCandlestickRequest {
message OffsetQuery {
Direction direction = 1;
string date = 2;
string minute = 3;
int32 count = 4;
}
message DateQuery {
string start_date = 1;
string end_date = 2;
}
string symbol = 1;
Period period = 2;
AdjustType adjust_type = 3;
HistoryCandlestickQueryType query_type = 4;
OffsetQuery offset_request = 5;
DateQuery date_request = 6;
}
Request Example
# 获取标的历史 K 线
#
# 运行前请访问“开发者中心”确保账户有正确的行情权限。
# 如没有开通行情权限,可以通过“LongPort”手机客户端,并进入“我的 - 我的行情 - 行情商城”购买开通行情权限。
from datetime import datetime, date
from longport.openapi import QuoteContext, Config, Period, AdjustType
config = Config.from_env()
ctx = QuoteContext(config)
# Query after 2023-01-01
resp = ctx.history_candlesticks_by_offset("700.HK", Period.Day, AdjustType.NoAdjust, True, 10, datetime(2023, 1, 1))
print(resp)
# Query before 2023-01-01
resp = ctx.history_candlesticks_by_offset("700.HK", Period.Day, AdjustType.NoAdjust, False, 10, datetime(2023, 1, 1))
print(resp)
# Query 2023-01-01 to 2023-02-01
resp = ctx.history_candlesticks_by_date("700.HK", Period.Day, AdjustType.NoAdjust, date(2023, 1, 1), date(2023, 2, 1))
print(resp)
Response
Response Properties
Name | Type | Description |
---|---|---|
symbol | string | 标的代码,例如:AAPL.US |
candlesticks | object[] | K 线数据 |
∟ close | string | 当前周期收盘价 |
∟ open | string | 当前周期开盘价 |
∟ low | string | 当前周期最低价 |
∟ high | string |