diff --git a/docs/en/docs/quote/options/option-chain.mdx b/docs/en/docs/quote/options/option-chain.mdx new file mode 100644 index 000000000..92042e753 --- /dev/null +++ b/docs/en/docs/quote/options/option-chain.mdx @@ -0,0 +1,150 @@ +--- +slug: /quote/pull/option-chain +title: Option Chain +sidebar_position: 11 +language_tabs: false +toc_footers: [] +includes: [] +search: true +highlight_theme: '' +headingLevel: 2 +--- + +Get the option contract list of an underlying security for a given expiry date. + +Every contract is an independent entry: calls and puts are not paired, so a strike price +that is listed on one side only yields a single entry. + +## Request + + + + + + +
HTTP MethodGET
HTTP URL/v1/gemini/option/option_chain_list
+ +### Query Parameters + +| Name | Type | Required | Description | +| ------------- | ------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| symbol | string | YES | Underlying security code, in `ticker.region` format, e.g. `BABA.US` | +| expiry_date | string | YES | Option expiry date, in `YYYYMMDD` format, e.g. `20261218` | +| standard_only | bool | NO | Whether to filter out old option contracts generated by corporate actions. `true` / `1` returns standard contracts only. When omitted or `false`, both standard contracts and contracts carrying `standard_attr` = `old` are returned | + +### Request Example + + + + +```bash +curl "https://openapi.longbridge.com/v1/gemini/option/option_chain_list?symbol=BABA.US&expiry_date=20261218" \ + -H "Authorization: Bearer " \ + -H "Accept: application/json" +``` + + + + +## Response + +### Response Headers + +- Content-Type: application/json + +### Ordering + +The list is returned in a fixed order: standard contracts first, then the contracts carrying +`standard_attr` = `old`. Within each group, entries are ordered by `option_type`, then by +`strike_price` ascending, then calls before puts. + +### Response Example + +```json +{ + "code": 0, + "message": "success", + "data": { + "list": [ + { + "expiry_date": "20261218", + "strike_price": "50", + "direction": "C", + "symbol": "BABA261218C50000.US", + "standard_attr": "", + "option_type": "", + "days_to_expiry": 106 + }, + { + "expiry_date": "20261218", + "strike_price": "50", + "direction": "P", + "symbol": "BABA261218P50000.US", + "standard_attr": "", + "option_type": "", + "days_to_expiry": 106 + }, + { + "expiry_date": "20261218", + "strike_price": "55", + "direction": "C", + "symbol": "BABA261218C55000.US", + "standard_attr": "", + "option_type": "", + "days_to_expiry": 106 + }, + { + "expiry_date": "20261218", + "strike_price": "55", + "direction": "P", + "symbol": "BABA261218P55000.US", + "standard_attr": "", + "option_type": "", + "days_to_expiry": 106 + }, + { + "expiry_date": "20261218", + "strike_price": "10", + "direction": "C", + "symbol": "BABA2261218C10000.US", + "standard_attr": "old", + "option_type": "", + "days_to_expiry": 106 + }, + { + "expiry_date": "20261218", + "strike_price": "10", + "direction": "P", + "symbol": "BABA2261218P10000.US", + "standard_attr": "old", + "option_type": "", + "days_to_expiry": 106 + } + ] + } +} +``` + +### Response Status + +| Status | Description | Schema | +| ------ | -------------- | --------------------------------------------------------- | +| 200 | Success | [option_chain_response](#schemaoption_chain_response) | +| 500 | Internal error | None | + +## Schemas + +### option_chain_response + + + +| Name | Type | Required | Description | +| ---------------- | -------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| list | object[] | true | Option contract list | +| ∟ expiry_date | string | true | Expiry date in US Eastern time, in `YYYYMMDD` format | +| ∟ strike_price | string | true | Strike price | +| ∟ direction | string | true | Contract direction. `C`: call; `P`: put | +| ∟ symbol | string | true | Option contract code, in `ticker.region` format | +| ∟ standard_attr | string | true | Indicates whether the contract is an old contract resulting from a corporate action (e.g. stock split, merger). `old` indicates a legacy contract; empty indicates a normal active contract | +| ∟ option_type | string | true | Special expiration cycle type. `W`: weekly option (expires weekly); `Q`: quarterly option (expires quarterly); empty indicates a standard monthly option | +| ∟ days_to_expiry | int32 | true | The number of days remaining until the option expires, updated daily at midnight ET. The value is `0` for options expiring today, and negative for already-expired options | diff --git a/docs/en/docs/quote/options/option-quote.mdx b/docs/en/docs/quote/options/option-quote.mdx index ccd1b9ce8..40d1947a1 100644 --- a/docs/en/docs/quote/options/option-quote.mdx +++ b/docs/en/docs/quote/options/option-quote.mdx @@ -28,7 +28,7 @@ longbridge option quote TSLA260418P350000.US | Name | Type | Required | Description | | ------ | -------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| symbol | string[] | Yes | Security code list. obtain the symbol of the options through the [optionchain](./optionchain-date-strike.md) API, for example: `[BABA230120C160000.US]`

**Check rules:**
The maximum number of symbols in each request is `500` | +| symbol | string[] | Yes | Security code list. obtain the symbol of the options through the option chain API, for example: `[BABA230120C160000.US]`

**Check rules:**
The maximum number of symbols in each request is `500` | ### Protobuf diff --git a/docs/en/docs/quote/options/optionchain-date-strike.mdx b/docs/en/docs/quote/options/optionchain-date-strike.mdx deleted file mode 100644 index 795e51aae..000000000 --- a/docs/en/docs/quote/options/optionchain-date-strike.mdx +++ /dev/null @@ -1,308 +0,0 @@ ---- -id: quote_optionchain_date_strike -title: Option Chain -slug: /quote/pull/optionchain-date-strike -sidebar_position: 12 ---- - -This API is used to obtain a list of option securities by the option chain expiry date. - - - - -# AAPL strike prices for 2026-04-17 expiry -longbridge option chain AAPL.US --date 2026-04-17 -# TSLA strike prices for 2026-04-17 expiry -longbridge option chain TSLA.US --date 2026-04-17 - - - - -:::info - -[Business Command](../../socket/biz_command): `21` - -::: - -## Request - -### Parameters - -| Name | Type | Required | Description | -| ----------- | ------ | -------- | ---------------------------------------------------------------------------------------------------------------------------- | -| symbol | string | Yes | Security code, in `ticker.region` format, for example:`700.HK` | -| expiry_date | string | Yes | Option expiry date,in `YYMMDD` format, for example: `20220429`, obtained by [Option Expiry Date](./optionchain-date) API | - -### Protobuf - -```protobuf -message OptionChainDateStrikeInfoRequest { - string symbol = 1; - string expiry_date = 2; -} -``` - -### Request Example - - - - -```python -from datetime import date -from longbridge.openapi import QuoteContext, Config, OAuthBuilder - -oauth = OAuthBuilder("your-client-id").build(lambda url: print("Visit:", url)) -config = Config.from_oauth(oauth) -ctx = QuoteContext(config) - -resp = ctx.option_chain_info_by_date("AAPL.US", date(2023, 1, 20)) -print(resp) -``` - - - - -```python -import asyncio -from datetime import date -from longbridge.openapi import AsyncQuoteContext, Config, 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.option_chain_info_by_date("AAPL.US", date(2023, 1, 20)) - print(resp) - -if __name__ == "__main__": - asyncio.run(main()) -``` - - - - -```javascript -const { Config, QuoteContext, OAuth, 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.optionChainInfoByDate('AAPL.US', new NaiveDate(2023, 1, 20)) - console.log(resp) -} -main().catch(console.error) -``` - - - - -```java -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)) { - StrikePriceInfo[] resp = ctx.getOptionChainInfoByDate("AAPL.US", LocalDate.of(2023, 1, 20)).get(); - for (StrikePriceInfo o : resp) System.out.println(o); - } - } -} -``` - - - - -```rust -use std::sync::Arc; -use longbridge::{oauth::OAuthBuilder, quote::QuoteContext, Config}; -use time::macros::date; - -#[tokio::main] -async fn main() -> Result<(), Box> { - 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.option_chain_info_by_date("AAPL.US", date!(2023 - 01 - 20)).await?; - println!("{:?}", resp); - Ok(()) -} -``` - - - - -```cpp -#include -#include - -#ifdef WIN32 -#include -#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.option_chain_info_by_date("AAPL.US", Date{2023, 1, 20}, [](auto res) { - if (!res) { - std::cout << "failed: " << *res.status().message() << std::endl; - return; - } - for (const auto& o : *res) std::cout << o.price << 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; -} -``` - - - - -```go -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" -) - -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() - expiry := time.Date(2023, 1, 20, 0, 0, 0, 0, time.UTC) - list, err := qctx.OptionChainInfoByDate(context.Background(), "AAPL.US", &expiry) - if err != nil { - log.Fatal(err) - } - for _, o := range list { - fmt.Println(o.Price) - } -} -``` - - - - -## Response - -### Response Properties - -| Name | Type | Description | -| ----------------- | -------- | ---------------------------- | -| strike_price_info | object[] | Option security info | -| ∟ price | string | Strike price | -| ∟ call_symbol | string | Security code of call option | -| ∟ put_symbol | string | Security code of put option | -| ∟ standard | bool | Is standard | - -### Protobuf - -```protobuf -message OptionChainDateStrikeInfoResponse { - repeated StrikePriceInfo strike_price_info = 1; -} - -message StrikePriceInfo { - string price = 1; - string call_symbol = 2; - string put_symbol = 3; - bool standard = 4; -} -``` - -### Response JSON Example - -```json -{ - "strike_price_info": [ - { - "price": "100", - "call_symbol": "AAPL220429C100000.US", - "put_symbol": "AAPL220429P100000.US", - "standard": true - }, - { - "price": "105", - "call_symbol": "AAPL220429C105000.US", - "put_symbol": "AAPL220429P105000.US", - "standard": true - }, - { - "price": "110", - "call_symbol": "AAPL220429C110000.US", - "put_symbol": "AAPL220429P110000.US", - "standard": true - }, - { - "price": "115", - "call_symbol": "AAPL220429C115000.US", - "put_symbol": "AAPL220429P115000.US", - "standard": true - } - ] -} -``` - -## Error Code - -| Protocol Error Code | Business Error Code | Description | Troubleshooting Suggestions | -| ------------------- | ------------------- | -------------------------- | ------------------------------------------------------------- | -| 3 | 301600 | Invalid request | Invalid request parameters or unpacking request failed | -| 3 | 301606 | Request rate limit | Reduce the frequency of requests | -| 7 | 301602 | Server error | Please try again or contact a technician to resolve the issue | -| 7 | 301600 | Invalue request parameters | Please check the request parameter: `symbol`,`expiry_date` | diff --git a/docs/en/docs/quote/options/optionchain_date.mdx b/docs/en/docs/quote/options/optionchain_date.mdx deleted file mode 100644 index ee87fe156..000000000 --- a/docs/en/docs/quote/options/optionchain_date.mdx +++ /dev/null @@ -1,284 +0,0 @@ ---- -id: quote_optionchain_date -title: Expiry Dates -slug: /quote/pull/optionchain-date -sidebar_position: 11 ---- - -This API is used to obtain the the list of expiration dates of option chain - - - - -# list all expiry dates for AAPL options -longbridge option chain AAPL.US -# list all expiry dates for TSLA options -longbridge option chain TSLA.US - - - - -:::info - -[Business Command](../../socket/biz_command): `20` - -::: - -## Request - -### Parameters - -| Name | Type | Required | Description | -| ------ | ------ | -------- | -------------------------------------------------------------- | -| symbol | string | Yes | Security code, in `ticker.region` format, for example:`700.HK` | - -### Protobuf - -```protobuf -message SecurityRequest { - string symbol = 1; -} -``` - -### Request Example - - - - -```python -from longbridge.openapi import QuoteContext, Config, OAuthBuilder - -oauth = OAuthBuilder("your-client-id").build(lambda url: print("Visit:", url)) -config = Config.from_oauth(oauth) -ctx = QuoteContext(config) - -resp = ctx.option_chain_expiry_date_list("AAPL.US") -print(resp) -``` - - - - -```python -import asyncio -from longbridge.openapi import AsyncQuoteContext, Config, 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.option_chain_expiry_date_list("AAPL.US") - print(resp) - -if __name__ == "__main__": - asyncio.run(main()) -``` - - - - -```javascript -const { Config, QuoteContext, OAuth } = 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.optionChainExpiryDateList('AAPL.US') - console.log(resp) -} -main().catch(console.error) -``` - - - - -```java -import com.longbridge.*; -import com.longbridge.quote.*; - -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)) { - LocalDate[] resp = ctx.getOptionChainExpiryDateList("AAPL.US").get(); - for (LocalDate d : resp) System.out.println(d); - } - } -} -``` - - - - -```rust -use std::sync::Arc; -use longbridge::{oauth::OAuthBuilder, quote::QuoteContext, Config}; - -#[tokio::main] -async fn main() -> Result<(), Box> { - 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.option_chain_expiry_date_list("AAPL.US").await?; - println!("{:?}", resp); - Ok(()) -} -``` - - - - -```cpp -#include -#include - -#ifdef WIN32 -#include -#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.option_chain_expiry_date_list("AAPL.US", [](auto res) { - if (!res) { - std::cout << "failed: " << *res.status().message() << std::endl; - return; - } - for (const auto& d : *res) std::cout << d.year << "-" << (int)d.month << "-" << (int)d.day << 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; -} -``` - - - - -```go -package main - -import ( - "context" - "fmt" - "log" - - "github.com/longbridge/openapi-go/config" - "github.com/longbridge/openapi-go/oauth" - "github.com/longbridge/openapi-go/quote" -) - -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() - dates, err := qctx.OptionChainExpiryDateList(context.Background(), "AAPL.US") - if err != nil { - log.Fatal(err) - } - for _, d := range dates { - fmt.Println(d.Format("2006-01-02")) - } -} -``` - - - - -## Response - -### Response Properties - -| Name | Type | Description | -| ----------- | -------- | -------------------------------------------------- | -| expiry_date | string[] | option chain expiry dates list,in `YYMMDD` format | - -### Protobuf - -```protobuf -message OptionChainDateListResponse { - repeated string expiry_date = 1; -} -``` - -### Response JSON Example - -```json -{ - "expiry_date": [ - "20220422", - "20220429", - "20220506", - "20220513", - "20220520", - "20220527", - "20220603", - "20220617", - "20220715", - "20220819", - "20220916", - "20221021", - "20221118", - "20230120", - "20230317", - "20230616", - "20230915", - "20240119", - "20240621" - ] -} -``` - -## Error Code - -| Protocol Error Code | Business Error Code | Description | Troubleshooting Suggestions | -| ------------------- | ------------------- | ------------------ | ------------------------------------------------------------- | -| 3 | 301600 | Invalid request | Invalid request parameters or unpacking request failed | -| 3 | 301606 | Request rate limit | Reduce the frequency of requests | -| 7 | 301602 | Server error | Please try again or contact a technician to resolve the issue | -| 7 | 301600 | Symbol not found | Check that the requested `symbol` is correct | diff --git a/docs/en/docs/quote/overview.mdx b/docs/en/docs/quote/overview.mdx index 1f2bf5b00..7a0d32348 100644 --- a/docs/en/docs/quote/overview.mdx +++ b/docs/en/docs/quote/overview.mdx @@ -13,7 +13,7 @@ slug: overview Description - Pull + Pull Get Basic Information Of Securities @@ -44,10 +44,7 @@ slug: overview Get Security Candlestick - Get Option Chain Expiry Date List - - - Get Option Chain Info By Date + Get Option Chain Get Warrant Issuer IDs diff --git a/docs/en/docs/socket/biz_command.mdx b/docs/en/docs/socket/biz_command.mdx index 5da953a2f..aee300597 100644 --- a/docs/en/docs/socket/biz_command.mdx +++ b/docs/en/docs/socket/biz_command.mdx @@ -17,7 +17,7 @@ And stock quote and order have difference endpoints, [check here](./hosts). Description - Pull + Pull Get Basic Information Of Securities @@ -47,12 +47,6 @@ And stock quote and order have difference endpoints, [check here](./hosts). Get Security Candlestick - - Get Option Chain Expiry Date List - - - Get Option Chain Info By Date - Get Warrant Issuer IDs diff --git a/docs/zh-CN/docs/quote/options/option-chain.mdx b/docs/zh-CN/docs/quote/options/option-chain.mdx new file mode 100644 index 000000000..26fe35306 --- /dev/null +++ b/docs/zh-CN/docs/quote/options/option-chain.mdx @@ -0,0 +1,148 @@ +--- +slug: /quote/pull/option-chain +title: 期权链 +sidebar_position: 11 +language_tabs: false +toc_footers: [] +includes: [] +search: true +highlight_theme: '' +headingLevel: 2 +--- + +获取标的在指定到期日下的期权合约列表。 + +每张合约都是独立的一项,认购与认沽不配对,因此只有单边挂牌的行权价只会返回一项。 + +## 请求 + + + + + + +
HTTP 方法GET
HTTP URL/v1/gemini/option/option_chain_list
+ +### 查询参数 + +| 名称 | 类型 | 必填 | 描述 | +| ------------- | ------ | ---- | ------------------------------------------------------------------------------------------------------------------------------------------ | +| symbol | string | 是 | 正股标的代码,使用 `ticker.region` 格式,例如:`BABA.US` | +| expiry_date | string | 是 | 期权到期日,使用 `YYYYMMDD` 格式,例如:`20261218` | +| standard_only | bool | 否 | 是否过滤因公司行动产生的旧期权合约。`true` / `1` 仅返回标准期权合约;不传或 `false` 则返回全部合约,含 `standard_attr` 为 `old` 的旧合约 | + +### 请求示例 + + + + +```bash +curl "https://openapi.longbridge.com/v1/gemini/option/option_chain_list?symbol=BABA.US&expiry_date=20261218" \ + -H "Authorization: Bearer " \ + -H "Accept: application/json" +``` + + + + +## 响应 + +### 响应头 + +- Content-Type: application/json + +### 排序规则 + +列表按固定顺序返回:标准合约在前,`standard_attr` 为 `old` 的合约在后;组内先按 `option_type`, +再按 `strike_price` 升序,认购排在认沽之前。 + +### 响应示例 + +```json +{ + "code": 0, + "message": "success", + "data": { + "list": [ + { + "expiry_date": "20261218", + "strike_price": "50", + "direction": "C", + "symbol": "BABA261218C50000.US", + "standard_attr": "", + "option_type": "", + "days_to_expiry": 106 + }, + { + "expiry_date": "20261218", + "strike_price": "50", + "direction": "P", + "symbol": "BABA261218P50000.US", + "standard_attr": "", + "option_type": "", + "days_to_expiry": 106 + }, + { + "expiry_date": "20261218", + "strike_price": "55", + "direction": "C", + "symbol": "BABA261218C55000.US", + "standard_attr": "", + "option_type": "", + "days_to_expiry": 106 + }, + { + "expiry_date": "20261218", + "strike_price": "55", + "direction": "P", + "symbol": "BABA261218P55000.US", + "standard_attr": "", + "option_type": "", + "days_to_expiry": 106 + }, + { + "expiry_date": "20261218", + "strike_price": "10", + "direction": "C", + "symbol": "BABA2261218C10000.US", + "standard_attr": "old", + "option_type": "", + "days_to_expiry": 106 + }, + { + "expiry_date": "20261218", + "strike_price": "10", + "direction": "P", + "symbol": "BABA2261218P10000.US", + "standard_attr": "old", + "option_type": "", + "days_to_expiry": 106 + } + ] + } +} +``` + +### 响应状态 + +| 状态码 | 描述 | Schema | +| ------ | ---------- | ----------------------------------------------------- | +| 200 | 成功 | [option_chain_response](#schemaoption_chain_response) | +| 500 | 服务端错误 | 无 | + +## Schemas + +### option_chain_response + + + +| 名称 | 类型 | 必填 | 描述 | +| ---------------- | -------- | ---- | --------------------------------------------------------------------------------------------------------------------- | +| list | object[] | true | 期权合约列表 | +| ∟ expiry_date | string | true | 到期日,美东时间,使用 `YYYYMMDD` 格式 | +| ∟ strike_price | string | true | 行权价 | +| ∟ direction | string | true | 合约方向。`C`:认购期权(Call);`P`:认沽期权(Put) | +| ∟ symbol | string | true | 期权标的代码,使用 `ticker.region` 格式 | +| ∟ standard_attr | string | true | 标识该期权合约是否为公司行动(如股票拆分、并购等)后产生的旧合约。`old`:表示旧期权合约;无值表示正常有效合约 | +| ∟ option_type | string | true | 特殊到期周期类型标识。`W`:周期权(每周到期);`Q`:季度期权(每季度到期);无值表示标准月度期权 | +| ∟ days_to_expiry | int32 | true | 期权距到期日的剩余天数,以美东时间零点为基准每日更新。当天到期的期权值为 `0`,已过期的期权值为负数 | diff --git a/docs/zh-CN/docs/quote/options/option-quote.mdx b/docs/zh-CN/docs/quote/options/option-quote.mdx index 3ce4d9803..8f81538a1 100644 --- a/docs/zh-CN/docs/quote/options/option-quote.mdx +++ b/docs/zh-CN/docs/quote/options/option-quote.mdx @@ -28,7 +28,7 @@ longbridge option quote TSLA260418P350000.US | Name | Type | Required | Description | | ------ | -------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| symbol | string[] | 是 | 标的代码列表,通过[期权链接口](./optionchain-date-strike.md) 获取期权标的的 symbol,例如:`[BABA230120C160000.US]`

**校验规则:**
每次请求支持传入的标的数量上限是 `500` 个 | +| symbol | string[] | 是 | 标的代码列表,通过期权链接口获取期权标的的 symbol,例如:`[BABA230120C160000.US]`

**校验规则:**
每次请求支持传入的标的数量上限是 `500` 个 | ### Protobuf diff --git a/docs/zh-CN/docs/quote/options/optionchain-date-strike.mdx b/docs/zh-CN/docs/quote/options/optionchain-date-strike.mdx deleted file mode 100644 index dac287311..000000000 --- a/docs/zh-CN/docs/quote/options/optionchain-date-strike.mdx +++ /dev/null @@ -1,309 +0,0 @@ ---- -id: quote_optionchain_date_strike -title: 期权链 -slug: /quote/pull/optionchain-date-strike -sidebar_position: 12 ---- - -该接口用于获取标的的期权链到期日期权标的列表。 - - - - -# AAPL 2026-04-17 到期的行权价列表 -longbridge option chain AAPL.US --date 2026-04-17 -# TSLA 2026-04-17 到期的行权价列表 -longbridge option chain TSLA.US --date 2026-04-17 - - - - -:::info - -[业务指令](../../socket/biz_command):`21` - -::: - -## Request - -### Parameters - -| Name | Type | Required | Description | -| ----------- | ------ | -------- | --------------------------------------------------------------------------------------------------- | -| symbol | string | 是 | 标的代码,使用 `ticker.region` 格式,例如:`700.HK` | -| expiry_date | string | 是 | 期权到期日,使用 `YYMMDD` 格式,例如:`20220429`,通过 [期权到期日](./optionchain-date) 接口获取 | - -### Protobuf - -```protobuf -message OptionChainDateStrikeInfoRequest { - string symbol = 1; - string expiry_date = 2; -} -``` - -### Request Example - - - - -```python -from datetime import date -from longbridge.openapi import QuoteContext, Config, OAuthBuilder - -oauth = OAuthBuilder("your-client-id").build(lambda url: print("Visit:", url)) -config = Config.from_oauth(oauth) -ctx = QuoteContext(config) - -resp = ctx.option_chain_info_by_date("AAPL.US", date(2023, 1, 20)) -print(resp) -``` - - - - -```python -import asyncio -from datetime import date -from longbridge.openapi import AsyncQuoteContext, Config, 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.option_chain_info_by_date("AAPL.US", date(2023, 1, 20)) - print(resp) - -if __name__ == "__main__": - asyncio.run(main()) -``` - - - - -```javascript -const { Config, QuoteContext, OAuth, 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.optionChainInfoByDate("AAPL.US", new NaiveDate(2023, 1, 20)) - console.log(resp) -} -main().catch(console.error) -``` - - - - -```java -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)) { - StrikePriceInfo[] resp = ctx.getOptionChainInfoByDate("AAPL.US", LocalDate.of(2023, 1, 20)).get(); - for (StrikePriceInfo o : resp) System.out.println(o); - } - } -} -``` - - - - -```rust -use std::sync::Arc; -use longbridge::{oauth::OAuthBuilder, quote::QuoteContext, Config}; -use time::macros::date; - -#[tokio::main] -async fn main() -> Result<(), Box> { - 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.option_chain_info_by_date("AAPL.US", date!(2023 - 01 - 20)).await?; - println!("{:?}", resp); - Ok(()) -} -``` - - - - -```cpp -#include -#include - -#ifdef WIN32 -#include -#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.option_chain_info_by_date("AAPL.US", Date{2023, 1, 20}, [](auto res) { - if (!res) { - std::cout << "failed: " << *res.status().message() << std::endl; - return; - } - for (const auto& o : *res) std::cout << o.price << 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; -} -``` - - - - -```go -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" -) - -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() - expiry := time.Date(2023, 1, 20, 0, 0, 0, 0, time.UTC) - list, err := qctx.OptionChainInfoByDate(context.Background(), "AAPL.US", &expiry) - if err != nil { - log.Fatal(err) - } - for _, o := range list { - fmt.Println(o.Price) - } -} -``` - - - - - -## Response - -### Response Properties - -| Name | Type | Description | -| ----------------- | -------- | ------------------ | -| strike_price_info | object[] | 到期日期权标的列表 | -| ∟ price | string | 行权价 | -| ∟ call_symbol | string | CALL 期权标的代码 | -| ∟ put_symbol | string | PUT 期权标的代码 | -| ∟ standard | bool | 是否标准期权 | - -### Protobuf - -```protobuf -message OptionChainDateStrikeInfoResponse { - repeated StrikePriceInfo strike_price_info = 1; -} - -message StrikePriceInfo { - string price = 1; - string call_symbol = 2; - string put_symbol = 3; - bool standard = 4; -} -``` - -### Response JSON Example - -```json -{ - "strike_price_info": [ - { - "price": "100", - "call_symbol": "AAPL220429C100000.US", - "put_symbol": "AAPL220429P100000.US", - "standard": true - }, - { - "price": "105", - "call_symbol": "AAPL220429C105000.US", - "put_symbol": "AAPL220429P105000.US", - "standard": true - }, - { - "price": "110", - "call_symbol": "AAPL220429C110000.US", - "put_symbol": "AAPL220429P110000.US", - "standard": true - }, - { - "price": "115", - "call_symbol": "AAPL220429C115000.US", - "put_symbol": "AAPL220429P115000.US", - "standard": true - } - ] -} -``` - -## 错误码 - -| 协议错误码 | 业务错误码 | 描述 | 排查建议 | -| ---------- | ---------- | -------------- | ------------------------------------------- | -| 3 | 301600 | 无效的请求 | 请求参数有误或解包失败 | -| 3 | 301606 | 限流 | 降低请求频次 | -| 7 | 301602 | 服务端内部错误 | 请重试或联系技术人员处理 | -| 7 | 301600 | 请求数据非法 | 检查请求的 `symbol`,`expiry_date` 数据格式 | diff --git a/docs/zh-CN/docs/quote/options/optionchain_date.mdx b/docs/zh-CN/docs/quote/options/optionchain_date.mdx deleted file mode 100644 index 2a0e2e284..000000000 --- a/docs/zh-CN/docs/quote/options/optionchain_date.mdx +++ /dev/null @@ -1,284 +0,0 @@ ---- -id: quote_optionchain_date -title: 到期日列表 -slug: /quote/pull/optionchain-date -sidebar_position: 11 ---- - -该接口用于获取标的的期权链到期日列表。 - - - - -# AAPL 期权到期日列表 -longbridge option chain AAPL.US -# TSLA 期权到期日列表 -longbridge option chain TSLA.US - - - - -:::info - -[业务指令](../../socket/biz_command):`20` - -::: - -## Request - -### Parameters - -| Name | Type | Required | Description | -| ------ | ------ | -------- | --------------------------------------------------- | -| symbol | string | 是 | 标的代码,使用 `ticker.region` 格式,例如:`700.HK` | - -### Protobuf - -```protobuf -message SecurityRequest { - string symbol = 1; -} -``` - -### Request Example - - - - -```python -from longbridge.openapi import QuoteContext, Config, OAuthBuilder - -oauth = OAuthBuilder("your-client-id").build(lambda url: print("Visit:", url)) -config = Config.from_oauth(oauth) -ctx = QuoteContext(config) - -resp = ctx.option_chain_expiry_date_list("AAPL.US") -print(resp) -``` - - - - -```python -import asyncio -from longbridge.openapi import AsyncQuoteContext, Config, 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.option_chain_expiry_date_list("AAPL.US") - print(resp) - -if __name__ == "__main__": - asyncio.run(main()) -``` - - - - -```javascript -const { Config, QuoteContext, OAuth } = 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.optionChainExpiryDateList("AAPL.US") - console.log(resp) -} -main().catch(console.error) -``` - - - - -```java -import com.longbridge.*; -import com.longbridge.quote.*; - -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)) { - LocalDate[] resp = ctx.getOptionChainExpiryDateList("AAPL.US").get(); - for (LocalDate d : resp) System.out.println(d); - } - } -} -``` - - - - -```rust -use std::sync::Arc; -use longbridge::{oauth::OAuthBuilder, quote::QuoteContext, Config}; - -#[tokio::main] -async fn main() -> Result<(), Box> { - 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.option_chain_expiry_date_list("AAPL.US").await?; - println!("{:?}", resp); - Ok(()) -} -``` - - - - -```cpp -#include -#include - -#ifdef WIN32 -#include -#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.option_chain_expiry_date_list("AAPL.US", [](auto res) { - if (!res) { - std::cout << "failed: " << *res.status().message() << std::endl; - return; - } - for (const auto& d : *res) std::cout << d.year << "-" << (int)d.month << "-" << (int)d.day << 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; -} -``` - - - - -```go -package main - -import ( - "context" - "fmt" - "log" - - "github.com/longbridge/openapi-go/config" - "github.com/longbridge/openapi-go/oauth" - "github.com/longbridge/openapi-go/quote" -) - -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() - dates, err := qctx.OptionChainExpiryDateList(context.Background(), "AAPL.US") - if err != nil { - log.Fatal(err) - } - for _, d := range dates { - fmt.Println(d.Format("2006-01-02")) - } -} -``` - - - - -## Response - -### Response Properties - -| Name | Type | Description | -| ----------- | -------- | ---------------------------------------------- | -| expiry_date | string[] | 标的对应的期权链到期日列表,使用 `YYMMDD` 格式 | - -### Protobuf - -```protobuf -message OptionChainDateListResponse { - repeated string expiry_date = 1; -} -``` - -### Response JSON Example - -```json -{ - "expiry_date": [ - "20220422", - "20220429", - "20220506", - "20220513", - "20220520", - "20220527", - "20220603", - "20220617", - "20220715", - "20220819", - "20220916", - "20221021", - "20221118", - "20230120", - "20230317", - "20230616", - "20230915", - "20240119", - "20240621" - ] -} -``` - -## 错误码 - -| 协议错误码 | 业务错误码 | 描述 | 排查建议 | -| ---------- | ---------- | -------------- | ---------------------------- | -| 3 | 301600 | 无效的请求 | 请求参数有误或解包失败 | -| 3 | 301606 | 限流 | 降低请求频次 | -| 7 | 301602 | 服务端内部错误 | 请重试或联系技术人员处理 | -| 7 | 301600 | 请求标的不存在 | 检查请求的 `symbol` 是否正确 | diff --git a/docs/zh-CN/docs/quote/overview.mdx b/docs/zh-CN/docs/quote/overview.mdx index d977300d7..ca920c5fa 100644 --- a/docs/zh-CN/docs/quote/overview.mdx +++ b/docs/zh-CN/docs/quote/overview.mdx @@ -14,7 +14,7 @@ slug: overview 功能简介 - 拉取 + 拉取 获取标的基础信息 @@ -45,10 +45,7 @@ slug: overview 获取标的 K 线 - 获取标的的期权链到期日列表 - - - 获取标的的期权链到期日期权标的列表 + 获取标的的期权链合约列表 获取轮证发行商 id diff --git a/docs/zh-CN/docs/socket/biz_command.mdx b/docs/zh-CN/docs/socket/biz_command.mdx index b9c87318e..40e9cf78b 100644 --- a/docs/zh-CN/docs/socket/biz_command.mdx +++ b/docs/zh-CN/docs/socket/biz_command.mdx @@ -15,7 +15,7 @@ sidebar_position: 5 功能简介 - 拉取 + 拉取 获取标的基础信息 @@ -45,12 +45,6 @@ sidebar_position: 5 获取标的 K 线 - - 获取标的的期权链到期日列表 - - - 获取标的的期权链到期日期权标的列表 - 获取轮证发行商 ID diff --git a/docs/zh-HK/docs/quote/options/option-chain.mdx b/docs/zh-HK/docs/quote/options/option-chain.mdx new file mode 100644 index 000000000..d9b6e2f68 --- /dev/null +++ b/docs/zh-HK/docs/quote/options/option-chain.mdx @@ -0,0 +1,148 @@ +--- +slug: /quote/pull/option-chain +title: 期權鏈 +sidebar_position: 11 +language_tabs: false +toc_footers: [] +includes: [] +search: true +highlight_theme: '' +headingLevel: 2 +--- + +獲取標的在指定到期日下的期權合約列表。 + +每張合約都是獨立的一項,認購與認沽不配對,因此只有單邊掛牌的行權價只會返回一項。 + +## 請求 + + + + + + +
HTTP 方法GET
HTTP URL/v1/gemini/option/option_chain_list
+ +### 查詢參數 + +| 名稱 | 類型 | 必填 | 描述 | +| ------------- | ------ | ---- | ------------------------------------------------------------------------------------------------------------------------------------------ | +| symbol | string | 是 | 正股標的代碼,使用 `ticker.region` 格式,例如:`BABA.US` | +| expiry_date | string | 是 | 期權到期日,使用 `YYYYMMDD` 格式,例如:`20261218` | +| standard_only | bool | 否 | 是否過濾因公司行動產生的舊期權合約。`true` / `1` 僅返回標準期權合約;不傳或 `false` 則返回全部合約,含 `standard_attr` 為 `old` 的舊合約 | + +### 請求示例 + + + + +```bash +curl "https://openapi.longbridge.com/v1/gemini/option/option_chain_list?symbol=BABA.US&expiry_date=20261218" \ + -H "Authorization: Bearer " \ + -H "Accept: application/json" +``` + + + + +## 響應 + +### 響應頭 + +- Content-Type: application/json + +### 排序規則 + +列表按固定順序返回:標準合約在前,`standard_attr` 為 `old` 的合約在後;組內先按 `option_type`, +再按 `strike_price` 升序,認購排在認沽之前。 + +### 響應示例 + +```json +{ + "code": 0, + "message": "success", + "data": { + "list": [ + { + "expiry_date": "20261218", + "strike_price": "50", + "direction": "C", + "symbol": "BABA261218C50000.US", + "standard_attr": "", + "option_type": "", + "days_to_expiry": 106 + }, + { + "expiry_date": "20261218", + "strike_price": "50", + "direction": "P", + "symbol": "BABA261218P50000.US", + "standard_attr": "", + "option_type": "", + "days_to_expiry": 106 + }, + { + "expiry_date": "20261218", + "strike_price": "55", + "direction": "C", + "symbol": "BABA261218C55000.US", + "standard_attr": "", + "option_type": "", + "days_to_expiry": 106 + }, + { + "expiry_date": "20261218", + "strike_price": "55", + "direction": "P", + "symbol": "BABA261218P55000.US", + "standard_attr": "", + "option_type": "", + "days_to_expiry": 106 + }, + { + "expiry_date": "20261218", + "strike_price": "10", + "direction": "C", + "symbol": "BABA2261218C10000.US", + "standard_attr": "old", + "option_type": "", + "days_to_expiry": 106 + }, + { + "expiry_date": "20261218", + "strike_price": "10", + "direction": "P", + "symbol": "BABA2261218P10000.US", + "standard_attr": "old", + "option_type": "", + "days_to_expiry": 106 + } + ] + } +} +``` + +### 響應狀態 + +| 狀態碼 | 描述 | Schema | +| ------ | ---------- | ----------------------------------------------------- | +| 200 | 成功 | [option_chain_response](#schemaoption_chain_response) | +| 500 | 服務端錯誤 | 無 | + +## Schemas + +### option_chain_response + + + +| 名稱 | 類型 | 必填 | 描述 | +| ---------------- | -------- | ---- | --------------------------------------------------------------------------------------------------------------------- | +| list | object[] | true | 期權合約列表 | +| ∟ expiry_date | string | true | 到期日,美東時間,使用 `YYYYMMDD` 格式 | +| ∟ strike_price | string | true | 行權價 | +| ∟ direction | string | true | 合約方向。`C`:認購期權(Call);`P`:認沽期權(Put) | +| ∟ symbol | string | true | 期權標的代碼,使用 `ticker.region` 格式 | +| ∟ standard_attr | string | true | 標識該期權合約是否為公司行動(如股票拆分、併購等)後產生的舊合約。`old`:表示舊期權合約;無值表示正常有效合約 | +| ∟ option_type | string | true | 特殊到期週期類型標識。`W`:週期權(每週到期);`Q`:季度期權(每季度到期);無值表示標準月度期權 | +| ∟ days_to_expiry | int32 | true | 期權距到期日的剩餘天數,以美東時間零點為基準每日更新。當天到期的期權值為 `0`,已過期的期權值為負數 | diff --git a/docs/zh-HK/docs/quote/options/option-quote.mdx b/docs/zh-HK/docs/quote/options/option-quote.mdx index a65de612a..5a57b323f 100644 --- a/docs/zh-HK/docs/quote/options/option-quote.mdx +++ b/docs/zh-HK/docs/quote/options/option-quote.mdx @@ -28,7 +28,7 @@ longbridge option quote TSLA260418P350000.US | Name | Type | Required | Description | | ------ | -------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| symbol | string[] | 是 | 標的代碼列表,通過[期權鏈接口](./optionchain-date-strike.md) 獲取期權標的的 symbol,例如:`[BABA230120C160000.US]`

**校驗規則:**
每次請求支持傳入的標的數量上限是 `500` 個 | +| symbol | string[] | 是 | 標的代碼列表,通過期權鏈接口獲取期權標的的 symbol,例如:`[BABA230120C160000.US]`

**校驗規則:**
每次請求支持傳入的標的數量上限是 `500` 個 | ### Protobuf diff --git a/docs/zh-HK/docs/quote/options/optionchain-date-strike.mdx b/docs/zh-HK/docs/quote/options/optionchain-date-strike.mdx deleted file mode 100644 index 554046c48..000000000 --- a/docs/zh-HK/docs/quote/options/optionchain-date-strike.mdx +++ /dev/null @@ -1,309 +0,0 @@ ---- -id: quote_optionchain_date_strike -title: 期權鏈 -slug: /quote/pull/optionchain-date-strike -sidebar_position: 12 ---- - -該接口用於獲取標的的期權鏈到期日期權標的列表。 - - - - -# AAPL 2026-04-17 到期的行權價列表 -longbridge option chain AAPL.US --date 2026-04-17 -# TSLA 2026-04-17 到期的行權價列表 -longbridge option chain TSLA.US --date 2026-04-17 - - - - -:::info - -[業務指令](../../socket/biz_command):`21` - -::: - -## Request - -### Parameters - -| Name | Type | Required | Description | -| ----------- | ------ | -------- | --------------------------------------------------------------------------------------------------- | -| symbol | string | 是 | 標的代碼,使用 `ticker.region` 格式,例如:`700.HK` | -| expiry_date | string | 是 | 期權到期日,使用 `YYMMDD` 格式,例如:`20220429`,通過 [期權到期日](./optionchain-date) 接口獲取 | - -### Protobuf - -```protobuf -message OptionChainDateStrikeInfoRequest { - string symbol = 1; - string expiry_date = 2; -} -``` - -## Response - -### Response Properties - -| Name | Type | Description | -| ----------------- | -------- | ------------------ | -| strike_price_info | object[] | 到期日期權標的列表 | -| ∟ price | string | 行權價 | -| ∟ call_symbol | string | CALL 期權標的代碼 | -| ∟ put_symbol | string | PUT 期權標的代碼 | -| ∟ standard | bool | 是否標準期權 | - -### Protobuf - -```protobuf -message OptionChainDateStrikeInfoResponse { - repeated StrikePriceInfo strike_price_info = 1; -} - -message StrikePriceInfo { - string price = 1; - string call_symbol = 2; - string put_symbol = 3; - bool standard = 4; -} -``` - -### Request Example - - - - -```python -from datetime import date -from longbridge.openapi import QuoteContext, Config, OAuthBuilder - -oauth = OAuthBuilder("your-client-id").build(lambda url: print("Visit:", url)) -config = Config.from_oauth(oauth) -ctx = QuoteContext(config) - -resp = ctx.option_chain_info_by_date("AAPL.US", date(2023, 1, 20)) -print(resp) -``` - - - - -```python -import asyncio -from datetime import date -from longbridge.openapi import AsyncQuoteContext, Config, 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.option_chain_info_by_date("AAPL.US", date(2023, 1, 20)) - print(resp) - -if __name__ == "__main__": - asyncio.run(main()) -``` - - - - -```javascript -const { Config, QuoteContext, OAuth, 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.optionChainInfoByDate("AAPL.US", new NaiveDate(2023, 1, 20)) - console.log(resp) -} -main().catch(console.error) -``` - - - - -```java -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)) { - StrikePriceInfo[] resp = ctx.getOptionChainInfoByDate("AAPL.US", LocalDate.of(2023, 1, 20)).get(); - for (StrikePriceInfo o : resp) System.out.println(o); - } - } -} -``` - - - - -```rust -use std::sync::Arc; -use longbridge::{oauth::OAuthBuilder, quote::QuoteContext, Config}; -use time::macros::date; - -#[tokio::main] -async fn main() -> Result<(), Box> { - 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.option_chain_info_by_date("AAPL.US", date!(2023 - 01 - 20)).await?; - println!("{:?}", resp); - Ok(()) -} -``` - - - - -```cpp -#include -#include - -#ifdef WIN32 -#include -#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.option_chain_info_by_date("AAPL.US", Date{2023, 1, 20}, [](auto res) { - if (!res) { - std::cout << "failed: " << *res.status().message() << std::endl; - return; - } - for (const auto& o : *res) std::cout << o.price << 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; -} -``` - - - - -```go -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" -) - -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() - expiry := time.Date(2023, 1, 20, 0, 0, 0, 0, time.UTC) - list, err := qctx.OptionChainInfoByDate(context.Background(), "AAPL.US", &expiry) - if err != nil { - log.Fatal(err) - } - for _, o := range list { - fmt.Println(o.Price) - } -} -``` - - - - - -### Response JSON Example - -```json -{ - "strike_price_info": [ - { - "price": "100", - "call_symbol": "AAPL220429C100000.US", - "put_symbol": "AAPL220429P100000.US", - "standard": true - }, - { - "price": "105", - "call_symbol": "AAPL220429C105000.US", - "put_symbol": "AAPL220429P105000.US", - "standard": true - }, - { - "price": "110", - "call_symbol": "AAPL220429C110000.US", - "put_symbol": "AAPL220429P110000.US", - "standard": true - }, - { - "price": "115", - "call_symbol": "AAPL220429C115000.US", - "put_symbol": "AAPL220429P115000.US", - "standard": true - } - ] -} -``` - -## 錯誤碼 - -| 協議錯誤碼 | 業務錯誤碼 | 描述 | 排查建議 | -| ---------- | ---------- | -------------- | ------------------------------------------- | -| 3 | 301600 | 無效的請求 | 請求參數有誤或解包失敗 | -| 3 | 301606 | 限流 | 降低請求頻次 | -| 7 | 301602 | 服務端內部錯誤 | 請重試或聯繫技術人員處理 | -| 7 | 301600 | 請求數據非法 | 檢查請求的 `symbol`,`expiry_date` 數據格式 | diff --git a/docs/zh-HK/docs/quote/options/optionchain_date.mdx b/docs/zh-HK/docs/quote/options/optionchain_date.mdx deleted file mode 100644 index ce990f73a..000000000 --- a/docs/zh-HK/docs/quote/options/optionchain_date.mdx +++ /dev/null @@ -1,284 +0,0 @@ ---- -id: quote_optionchain_date -title: 到期日列表 -slug: /quote/pull/optionchain-date -sidebar_position: 11 ---- - -該接口用於獲取標的的期權鏈到期日列表。 - - - - -# AAPL 期權到期日列表 -longbridge option chain AAPL.US -# TSLA 期權到期日列表 -longbridge option chain TSLA.US - - - - -:::info - -[業務指令](../../socket/biz_command):`20` - -::: - -## Request - -### Parameters - -| Name | Type | Required | Description | -| ------ | ------ | -------- | --------------------------------------------------- | -| symbol | string | 是 | 標的代碼,使用 `ticker.region` 格式,例如:`700.HK` | - -### Protobuf - -```protobuf -message SecurityRequest { - string symbol = 1; -} -``` - -### Request Example - - - - -```python -from longbridge.openapi import QuoteContext, Config, OAuthBuilder - -oauth = OAuthBuilder("your-client-id").build(lambda url: print("Visit:", url)) -config = Config.from_oauth(oauth) -ctx = QuoteContext(config) - -resp = ctx.option_chain_expiry_date_list("AAPL.US") -print(resp) -``` - - - - -```python -import asyncio -from longbridge.openapi import AsyncQuoteContext, Config, 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.option_chain_expiry_date_list("AAPL.US") - print(resp) - -if __name__ == "__main__": - asyncio.run(main()) -``` - - - - -```javascript -const { Config, QuoteContext, OAuth } = 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.optionChainExpiryDateList("AAPL.US") - console.log(resp) -} -main().catch(console.error) -``` - - - - -```java -import com.longbridge.*; -import com.longbridge.quote.*; - -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)) { - LocalDate[] resp = ctx.getOptionChainExpiryDateList("AAPL.US").get(); - for (LocalDate d : resp) System.out.println(d); - } - } -} -``` - - - - -```rust -use std::sync::Arc; -use longbridge::{oauth::OAuthBuilder, quote::QuoteContext, Config}; - -#[tokio::main] -async fn main() -> Result<(), Box> { - 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.option_chain_expiry_date_list("AAPL.US").await?; - println!("{:?}", resp); - Ok(()) -} -``` - - - - -```cpp -#include -#include - -#ifdef WIN32 -#include -#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.option_chain_expiry_date_list("AAPL.US", [](auto res) { - if (!res) { - std::cout << "failed: " << *res.status().message() << std::endl; - return; - } - for (const auto& d : *res) std::cout << d.year << "-" << (int)d.month << "-" << (int)d.day << 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; -} -``` - - - - -```go -package main - -import ( - "context" - "fmt" - "log" - - "github.com/longbridge/openapi-go/config" - "github.com/longbridge/openapi-go/oauth" - "github.com/longbridge/openapi-go/quote" -) - -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() - dates, err := qctx.OptionChainExpiryDateList(context.Background(), "AAPL.US") - if err != nil { - log.Fatal(err) - } - for _, d := range dates { - fmt.Println(d.Format("2006-01-02")) - } -} -``` - - - - -## Response - -### Response Properties - -| Name | Type | Description | -| ----------- | -------- | ---------------------------------------------- | -| expiry_date | string[] | 標的對應的期權鏈到期日列表,使用 `YYMMDD` 格式 | - -### Protobuf - -```protobuf -message OptionChainDateListResponse { - repeated string expiry_date = 1; -} -``` - -### Response JSON Example - -```json -{ - "expiry_date": [ - "20220422", - "20220429", - "20220506", - "20220513", - "20220520", - "20220527", - "20220603", - "20220617", - "20220715", - "20220819", - "20220916", - "20221021", - "20221118", - "20230120", - "20230317", - "20230616", - "20230915", - "20240119", - "20240621" - ] -} -``` - -## 錯誤碼 - -| 協議錯誤碼 | 業務錯誤碼 | 描述 | 排查建議 | -| ---------- | ---------- | -------------- | ---------------------------- | -| 3 | 301600 | 無效的請求 | 請求參數有誤或解包失敗 | -| 3 | 301606 | 限流 | 降低請求頻次 | -| 7 | 301602 | 服務端內部錯誤 | 請重試或聯繫技術人員處理 | -| 7 | 301600 | 請求標的不存在 | 檢查請求的 `symbol` 是否正確 | diff --git a/docs/zh-HK/docs/quote/overview.mdx b/docs/zh-HK/docs/quote/overview.mdx index 7bda46c38..ddf0e2257 100644 --- a/docs/zh-HK/docs/quote/overview.mdx +++ b/docs/zh-HK/docs/quote/overview.mdx @@ -14,7 +14,7 @@ slug: overview 功能簡介 - 拉取 + 拉取 獲取標的基礎信息 @@ -45,10 +45,7 @@ slug: overview 獲取標的 k 線 - 獲取標的的期權鏈到期日列表 - - - 獲取標的的期權鏈到期日期權標的列表 + 獲取標的的期權鏈合約列表 獲取輪證發行商 id diff --git a/docs/zh-HK/docs/socket/biz_command.mdx b/docs/zh-HK/docs/socket/biz_command.mdx index d195340a6..d6319ae3a 100644 --- a/docs/zh-HK/docs/socket/biz_command.mdx +++ b/docs/zh-HK/docs/socket/biz_command.mdx @@ -15,7 +15,7 @@ sidebar_position: 5 功能簡介 - 拉取 + 拉取 獲取標的基礎信息 @@ -45,12 +45,6 @@ sidebar_position: 5 獲取標的 k 線 - - 獲取標的的期權鏈到期日列表 - - - 獲取標的的期權鏈到期日期權標的列表 - 獲取輪證發行商 id