跳轉到內容

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
  }
}