跳转到内容

K 线

已订阅标的的实时 K 线数据推送。回调在当前 K 线更新时触发(Realtime 模式)或在一根 K 线周期结束时触发(Confirmed 模式)。

Tip

本页介绍的是推送 API(subscribe_candlesticks)。如需按需拉取历史 K 线数据,请参见 K 线 - 拉取

行情权限要求免费
  • 美股:默认免费赠送 US LV1 实时行情。
  • 港股:默认赠送 LV1 实时行情。
  • K 线推送所需权限与订阅行情相同。
Info

数据格式

Properties

NameTypeDescription
symbolstring标的代码,例如:AAPL.US
periodint32K 线周期,详见 Period
candlestickobjectK 线数据
∟ closestring收盘价
∟ openstring开盘价
∟ highstring最高价
∟ lowstring最低价
∟ volumeint64成交量
∟ turnoverstring成交额
∟ timestampint64K 线时间(Unix 时间戳)
∟ trade_sessionint32交易时段,详见 TradeSession

Protobuf

protobuf
message PushCandlestick {
  string symbol = 1;
  Period period = 2;
  Candlestick candlestick = 3;
}

message Candlestick {
  string close = 1;
  string open = 2;
  string high = 3;
  string low = 4;
  int64 volume = 5;
  string turnover = 6;
  int64 timestamp = 7;
  TradeSession trade_session = 8;
}

Example

python
from time import sleep
from longbridge.openapi import QuoteContext, Config, Period, PushCandlestick, OAuthBuilder

def on_candlestick(symbol: str, event: PushCandlestick):
    print(symbol, event)

oauth = OAuthBuilder("your-client-id").build(lambda url: print("Visit:", url))
config = Config.from_oauth(oauth)
ctx = QuoteContext(config)
ctx.set_on_candlestick(on_candlestick)

ctx.subscribe_candlesticks("700.HK", Period.Min_1)
sleep(30)

JSON Example

json
{
  "symbol": "700.HK",
  "period": 1,
  "candlestick": {
    "close": "162.500",
    "open": "160.000",
    "high": "163.000",
    "low": "159.800",
    "volume": 123456,
    "turnover": "19987654.000",
    "timestamp": 1651103700,
    "trade_session": 0
  }
}