mirror of
https://github.com/longbridge/developers.git
synced 2026-09-19 03:34:09 +08:00
4.4 KiB
4.4 KiB
id, title, slug, sidebar_position
| id | title | slug | sidebar_position |
|---|---|---|---|
| quote_trade_session | 获取各市场当日交易时段 | trade-session | 15 |
该接口用于获取各市场当日交易时段。
:::info
业务指令:8
:::
Request
Request Example
# 获取各市场当日交易时段
# https://open.longbridgeapp.com/docs/quote/pull/trade-session
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, MarketTradePeriodResponse)
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())
# 运行前请访问 “开发者中心“ 确保账户有正确的行情权限。
# 如没有开通行情权限,可以通过 "长桥" 手机客户端,并进入 “我的 - 我的行情 - 行情商城“ 购买开通行情权限。
result = ws.send_request(Command.QueryMarketTradePeriod, "")
resp = MarketTradePeriodResponse()
resp.ParseFromString(result)
print(f"Market trade session:\n\n {resp.market_trade_session}")
Response
Response Properties
| Name | Type | Description |
|---|---|---|
| market_trade_session | object[] | 市场交易时段 |
| ∟ market | string | 市场US - 美股市场HK - 港股市场CN - A 股市场SG - 新加坡市场 |
| ∟ trade_session | object[] | 交易时段 |
| ∟∟ beg_time | int32 | 交易开始时间,格式:hhmm 例如:900 |
| ∟∟ end_time | int32 | 交易结束时间,格式:hhmm 例如:1400 |
| ∟∟ trade_session | int32 | 交易时段,详见 TradeSession |
Protobuf
message MarketTradePeriodResponse {
repeated MarketTradePeriod market_trade_session = 1;
}
message MarketTradePeriod {
string market = 1;
repeated TradePeriod trade_session = 2;
}
message TradePeriod {
int32 beg_time = 1;
int32 end_time = 2;
TradeSession trade_session = 3;
}
Response JSON Example
{
"market_trade_session": [
{
"market": "US",
"trade_session": [
{
"beg_time": 930,
"end_time": 1600
},
{
"beg_time": 400,
"end_time": 930,
"trade_session": 1
},
{
"beg_time": 1600,
"end_time": 2000,
"trade_session": 2
}
]
},
{
"market": "HK",
"trade_session": [
{
"beg_time": 930,
"end_time": 1200
},
{
"beg_time": 1300,
"end_time": 1600
}
]
},
{
"market": "CN",
"trade_session": [
{
"beg_time": 930,
"end_time": 1130
},
{
"beg_time": 1300,
"end_time": 1457
}
]
},
{
"market": "SG",
"trade_session": [
{
"beg_time": 900,
"end_time": 1200
},
{
"beg_time": 1300,
"end_time": 1700
}
]
}
]
}
错误码
| 协议错误码 | 业务错误码 | 描述 | 排查建议 |
|---|---|---|---|
| 3 | 301600 | 无效的请求 | 请求参数有误或解包失败 |
| 3 | 301606 | 限流 | 降低请求频次 |
| 7 | 301602 | 服务端内部错误 | 请重试或联系技术人员处理 |