Longbridge Developers
立即开始

交易日历

该接口用于获取市场的交易日信息。

行情权限要求免费

开通 OpenAPI 后自动获得,无需额外购买。

>_ CLI
# 港股未来交易日
longbridge trading days HK
# 美股未来交易日
longbridge trading days US
# A 股未来交易日
longbridge trading days CN

Info

业务指令:9

Request

Parameters

NameTypeRequiredDescription
marketstring是市场

可选值:
US - 美股市场
HK - 港股市场
CN - A 股市场
SG - 新加坡市场
beg_daystring是开始时间,使用 YYMMDD 格式,例如:20220401
end_daystring是结束时间,使用 YYMMDD 格式,例如:20220420

校验规则:
开始时间 和 结束时间,间隔不能大于一个月
仅支持查询最近一年的数据

Protobuf

message MarketTradeDayRequest {
  string market = 1;
  string beg_day = 2;
  string end_day = 3;
}

Request Example

from datetime import date
from longbridge.openapi import QuoteContext, Config, Market, OAuthBuilder

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

resp = ctx.trading_days(Market.HK, date(2022, 1, 1), date(2022, 2, 1))
print(resp)
import asyncio
from datetime import date
from longbridge.openapi import AsyncQuoteContext, Config, Market, OAuthBuilder

async def main() -> None:
    oauth = await OAuthBuilder("your-client-id").build_async(lambda url: print("Visit:", url))
    config = Config.from_oauth(oauth)
    ctx = AsyncQuoteContext.create(config)

    resp = await ctx.trading_days(Market.HK, date(2022, 1, 1), date(2022, 2, 1))
    print(resp)

if __name__ == "__main__":
    asyncio.run(main())
const { Config, QuoteContext, OAuth, Market, NaiveDate } = require('longbridge')

async function main() {
  const oauth = await OAuth.build("your-client-id", (_, url) => {
    console.log("Open this URL to authorize: " + url)
  })
  const config = Config.fromOAuth(oauth)
  const ctx = QuoteContext.new(config)
  const resp = await ctx.tradingDays(Market.HK, new NaiveDate(2022, 1, 1), new NaiveDate(2022, 2, 1))
  console.log(resp)
}
main().catch(console.error)
import com.longbridge.*;
import com.longbridge.quote.*;
import java.time.LocalDate;

class Main {
    public static void main(String[] args) throws Exception {
        try (OAuth oauth = new OAuthBuilder("your-client-id")
                .build(url -> System.out.println("Open to authorize: " + url))
                .get();
             Config config = Config.fromOAuth(oauth);
             QuoteContext ctx = QuoteContext.create(config)) {
            MarketTradingDays resp = ctx.getTradingDays(Market.HK, LocalDate.of(2022, 1, 1), LocalDate.of(2022, 2, 1)).get();
            System.out.println(resp);
        }
    }
}
use std::sync::Arc;
use longbridge::{oauth::OAuthBuilder, quote::QuoteContext, Config, Market};
use time::macros::date;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let oauth = OAuthBuilder::new("your-client-id")
        .build(|url| println!("Open this URL to authorize: {url}"))
        .await?;
    let config = Arc::new(Config::from_oauth(oauth));
    let (ctx, _) = QuoteContext::new(config);
    let resp = ctx.trading_days(Market::HK, date!(2022 - 01 - 01), date!(2022 - 02 - 01)).await?;
    println!("{:?}", resp);
    Ok(())
}
#include &lt;iostream&gt;
#include <longbridge.hpp>

#ifdef WIN32
#include <windows.h>
#endif

using namespace longbridge;
using namespace longbridge::quote;

static void
run(const OAuth& oauth)
{
    Config config = Config::from_oauth(oauth);
    QuoteContext ctx = QuoteContext::create(config);

    ctx.trading_days(Market::HK, Date{2022, 1, 1}, Date{2022, 2, 1}, [](auto res) {
        if (!res) {
            std::cout << "failed: " << *res.status().message() << std::endl;
            return;
        }
        std::cout << "trade_days: " << res->trade_day.size() << std::endl;
    });
}

int main(int argc, char const* argv[]) {
#ifdef WIN32
    SetConsoleOutputCP(CP_UTF8);
#endif

    const std::string client_id = "your-client-id";
    OAuthBuilder(client_id).build(
    [](const std::string& url) {
        std::cout << "Open this URL to authorize: " << url << std::endl;
    },
    [](auto res) {
        if (!res) {
            std::cout << "authorization failed: " << *res.status().message() << std::endl;
            return;
        }
        run(*res);
    });

    std::cin.get();
    return 0;
}
package main

import (
	"context"
	"fmt"
	"log"
	"time"

	"github.com/longbridge/openapi-go/config"
	"github.com/longbridge/openapi-go/oauth"
	"github.com/longbridge/openapi-go/quote"
	openapi "github.com/longbridge/openapi-go"
)

func main() {
	o := oauth.New("your-client-id").
		OnOpenURL(func(url string) { fmt.Println("Open this URL to authorize:", url) })
	if err := o.Build(context.Background()); err != nil {
		log.Fatal(err)
	}
	conf, err := config.New(config.WithOAuthClient(o))
	if err != nil {
		log.Fatal(err)
	}
	qctx, err := quote.NewFromCfg(conf)
	if err != nil {
		log.Fatal(err)
	}
	defer qctx.Close()
	begin := time.Date(2022, 1, 1, 0, 0, 0, 0, time.UTC)
	end := time.Date(2022, 2, 1, 0, 0, 0, 0, time.UTC)
	days, err := qctx.TradingDays(context.Background(), openapi.MarketHK, &begin, &end)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("trade_days:", len(days.TradeDay))
}

Response

Response Properties

NameTypeDescription
trade_daystring[]交易日,使用 YYMMDD 格式
half_trade_daystring[]半日市,使用 YYMMDD 格式

Protobuf

message MarketTradeDayResponse {
  repeated string trade_day = 1;
  repeated string half_trade_day = 2;
}

Response JSON Example

{
  "trade_day": [
    "20220120",
    "20220121",
    "20220124",
    "20220125",
    "20220126",
    "20220127",
    "20220128",
    "20220204",
    "20220207",
    "20220208",
    "20220209",
    "20220210"
  ],
  "half_trade_day": ["20220131"]
}

错误码

协议错误码业务错误码描述排查建议
3301600无效的请求请求参数有误或解包失败
3301606限流降低请求频次
7301602服务端内部错误请重试或联系技术人员处理
7301600请求数据非法检查请求的市场,日期是否在正确范围内