Files
2022-05-13 16:23:07 +08:00

4.2 KiB
Raw Permalink Blame History

id, title, slug, sidebar_position
id title slug sidebar_position
quote_intraday 获取标的当日分时 intraday 9

该接口用于获取标的的当日分时数据。

:::info

业务指令18

:::

Request

Parameters

Name Type Required Description
symbol string 标的代码,使用 ticker.region 格式,例如:700.HK

Protobuf

message SecurityIntradayRequest {
  string symbol = 1;
}

Request Example

# 获取标的分时
# https://open.longbridgeapp.com/docs/quote/pull/intraday
import os
import time
from longbridge.http import Auth, Config, HttpClient
from longbridge.ws import ReadyState, WsCallback, WsClient
# Protobuf 变量定义参见https://github.com/longbridgeapp/openapi-protobufs/blob/main/quote/api.proto
from longbridge.proto.quote_pb2 import (Command, SecurityIntradayRequest, SecurityIntradayResponse)

class MyWsCallback(WsCallback):
    def on_state(self, state: ReadyState):
        print(f"-> state: {state}")

auth = Auth(os.getenv("LONGBRIDGE_APP_KEY"), os.getenv("LONGBRIDGE_APP_SECRET"), access_token=os.getenv("LONGBRIDGE_ACCESS_TOKEN"))
http = HttpClient(auth, Config(base_url="https://openapi.longbridgeapp.com"))
ws = WsClient("wss://openapi-quote.longbridgeapp.com", http, MyWsCallback())

# 运行前请访问 “开发者中心“ 确保账户有正确的行情权限。
# 如没有开通行情权限,可以通过 "长桥" 手机客户端,并进入 “我的 - 我的行情 - 行情商城“ 购买开通行情权限。
req = SecurityIntradayRequest(symbol="700.HK")
result = ws.send_request(Command.QueryIntraday, req.SerializeToString())
resp = SecurityIntradayResponse()
resp.ParseFromString(result)

print(f"Intraday:\n\n {resp}")

Response

Response Properties

Name Type Description
symbol string 标的代码,例如:AAPL.US
lines object[] 分时数据
∟ price string 当前分钟的收盘价格
∟ timestamp int64 当前分钟的开始时间
∟ volume int64 成交量
∟ turnover string 成交额
∟ avg_price string 均价

Protobuf

message SecurityIntradayResponse{
  string symbol = 1;
  repeated Line lines = 2;
}

message Line {
  string price = 1;
  int64 timestamp = 2;
  int64 volume = 3;
  string turnover = 4;
  string avg_price = 5;
}

Response JSON Example

{
  "symbol": "700.HK",
  "lines": [
    {
      "price": "330.400",
      "timestamp": 1651023000,
      "volume": 375870,
      "turnover": "123949699.000",
      "avg_price": "329.767470"
    },
    {
      "price": "331.200",
      "timestamp": 1651023060,
      "volume": 233095,
      "turnover": "77269032.800",
      "avg_price": "330.427416"
    },
    {
      "price": "330.400",
      "timestamp": 1651023120,
      "volume": 192565,
      "turnover": "63711556.000",
      "avg_price": "330.530719"
    },
    {
      "price": "330.800",
      "timestamp": 1651023180,
      "volume": 143397,
      "turnover": "47471072.400",
      "avg_price": "330.608989"
    },
    {
      "price": "330.800",
      "timestamp": 1651023240,
      "volume": 141834,
      "turnover": "46890605.600",
      "avg_price": "330.608078"
    }
  ]
}

错误码

协议错误码 业务错误码 描述 排查建议
3 301600 无效的请求 请求参数有误或解包失败
3 301606 限流 降低请求频次
7 301602 服务端内部错误 请重试或联系技术人员处理
7 301600 请求标的不存在 检查请求的 symbol 是否正确
7 301603 标的无行情 标的没有请求的行情数据
7 301604 无权限 没有获取标的行情的权限