diff --git a/docs/.vitepress/theme/components/SDKLinks.vue b/docs/.vitepress/theme/components/SDKLinks.vue index 583a4322e..fae6bae10 100644 --- a/docs/.vitepress/theme/components/SDKLinks.vue +++ b/docs/.vitepress/theme/components/SDKLinks.vue @@ -180,6 +180,7 @@ const JAVA_ANCHOR_MAP: Record = { setOnTrades: 'setOnTrades(com.longbridge.quote.TradesHandler)', getHistoryExecutions: 'getHistoryExecutions(com.longbridge.trade.GetHistoryExecutionsOptions)', getTodayExecutions: 'getTodayExecutions(com.longbridge.trade.GetTodayExecutionsOptions)', + getAllExecutions: 'getAllExecutions(com.longbridge.trade.GetAllExecutionsOptions)', getHistoryOrders: 'getHistoryOrders(com.longbridge.trade.GetHistoryOrdersOptions)', getTodayOrders: 'getTodayOrders(com.longbridge.trade.GetTodayOrdersOptions)', replaceOrder: 'replaceOrder(com.longbridge.trade.ReplaceOrderOptions)', diff --git a/docs/en/docs/trade/execution/all_executions.md b/docs/en/docs/trade/execution/all_executions.md new file mode 100644 index 000000000..c637134fc --- /dev/null +++ b/docs/en/docs/trade/execution/all_executions.md @@ -0,0 +1,294 @@ +--- +slug: all_executions +sidebar_position: 3 +title: All Executions +language_tabs: false +toc_footers: [] +includes: [] +search: true +highlight_theme: '' +headingLevel: 2 +--- + +This API is used to query execution (fill) records, including both buy and sell records. It supports querying today's and historical executions at the same time. Compared with the today/history execution APIs, each record additionally returns the trade `side`. + + + +## Request + + + + + + +
HTTP MethodGET
HTTP URL/v3/trade/execution/all
+ +### Parameters + +> Content-Type: application/json; charset=utf-8 + +| Name | Type | Required | Description | +| -------- | ------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| symbol | string | NO | Stock symbol, use `ticker.region` format, example: `AAPL.US` | +| order_id | string | NO | Order ID, example: `701276261045858304` | +| start_at | string | NO | Start time, formatted as a timestamp (second), example: `1650410999`.

If the start time is null, the default is the 90 days before of the end time or 90 days before of the current time. | +| end_at | string | NO | End time, formatted as a timestamp (second), example: `1650410999`.

If the end time is null, the default is the current time or 90 days after of the start time. | +| page | int32 | NO | Page number, starting from `1`. The maximum number of records per query is 1000. If the number of results exceeds 1000, `has_more` will be `true`, use `page` together with `has_more` to paginate. | + +### Request Example + + + + +```python +from datetime import datetime +from longbridge.openapi import TradeContext, Config, OAuthBuilder + +oauth = OAuthBuilder("your-client-id").build(lambda url: print("Visit:", url)) +config = Config.from_oauth(oauth) +ctx = TradeContext(config) + +resp = ctx.all_executions( + symbol = "700.HK", + start_at = datetime(2022, 5, 9), + end_at = datetime(2022, 5, 12), +) +print(resp) +``` + + + + +```python +import asyncio +from datetime import datetime +from longbridge.openapi import AsyncTradeContext, 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 = AsyncTradeContext.create(config) + + resp = await ctx.all_executions( + symbol = "700.HK", + start_at = datetime(2022, 5, 9), + end_at = datetime(2022, 5, 12), + ) + print(resp) + +if __name__ == "__main__": + asyncio.run(main()) +``` + + + + +```javascript +const { Config, TradeContext, 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 = TradeContext.new(config) + const resp = await ctx.allExecutions({ symbol: '700.HK' }) + console.log(resp) +} +main().catch(console.error) +``` + + + + +```java +import com.longbridge.*; +import com.longbridge.trade.*; + +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); + TradeContext ctx = TradeContext.create(config)) { + AllExecutionsResponse resp = ctx.getAllExecutions(null).get(); + for (Execution e : resp.getTrades()) System.out.println(e); + } + } +} +``` + + + + +```rust +use std::sync::Arc; +use longbridge::{oauth::OAuthBuilder, trade::TradeContext, 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, _) = TradeContext::new(config); + let resp = ctx.all_executions(None).await?; + println!("{:?}", resp); + Ok(()) +} +``` + + + + +```cpp +#include +#include + +#ifdef WIN32 +#include +#endif + +using namespace longbridge; +using namespace longbridge::trade; + +static void +run(const OAuth& oauth) +{ + Config config = Config::from_oauth(oauth); + TradeContext ctx = TradeContext::create(config); + + ctx.all_executions(std::nullopt, [](auto res) { + if (!res) { std::cout << "failed" << std::endl; return; } + for (const auto& e : res->trades) std::cout << e.order_id << 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/trade" +) + +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) + } + tctx, err := trade.NewFromCfg(conf) + if err != nil { + log.Fatal(err) + } + defer tctx.Close() + start := time.Date(2022, 5, 9, 0, 0, 0, 0, time.UTC) + end := time.Date(2022, 5, 12, 0, 0, 0, 0, time.UTC) + resp, err := tctx.AllExecutions(context.Background(), &trade.GetAllExecutions{ + Symbol: "700.HK", + StartAt: start, + EndAt: end, + }) + if err != nil { + log.Fatal(err) + } + for _, e := range resp.Trades { + fmt.Println(e.OrderId) + } +} +``` + + + + +## Response + +### Response Headers + +- Content-Type: application/json + +### Response Example + +```json +{ + "code": 0, + "message": "success", + "data": { + "has_more": false, + "trades": [ + { + "order_id": "693664675163312128", + "price": "388", + "quantity": "100", + "symbol": "700.HK", + "trade_done_at": "1648611351", + "trade_id": "693664675163312128-1648611351433741210", + "side": "Buy" + } + ] + } +} +``` + +### Response Status + +| Status | Description | Schema | +| ------ | -------------------------------------------------------- | ----------------------------------------------- | +| 200 | Get All Executions Success | [all_executions_rsp](#schemaall_executions_rsp) | +| 400 | The query failed with an error in the request parameter. | None | + + + +## Schemas + +### all_executions_rsp + + + + +| Name | Type | Required | Description | +| --------------- | -------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | +| has_more | boolean | true | has more orders record.

The maximum number of orders per query is 1000, if the number of results exceeds 1000, then has_more will be true | +| trades | object[] | false | Execution Detail | +| ∟ order_id | string | true | Order ID | +| ∟ trade_id | string | true | Execution ID | +| ∟ symbol | string | true | Stock symbol, use `ticker.region` format,example: `AAPL.US` | +| ∟ trade_done_at | string | true | Trade done time, formatted as a timestamp (second) | +| ∟ quantity | string | true | Executed quantity | +| ∟ price | string | true | Executed price | +| ∟ side | string | true | Trade side

**Enum Value:**
`Buy`
`Sell` | diff --git a/docs/en/docs/trade/order/submit.md b/docs/en/docs/trade/order/submit.md index b08e642da..72e6f9ba1 100644 --- a/docs/en/docs/trade/order/submit.md +++ b/docs/en/docs/trade/order/submit.md @@ -44,7 +44,7 @@ longbridge order sell TSLA.US 100 --price 260.00 | trailing_percent | string | NO | Trailing percent

`TSLPPCT` Order Required | | expire_date | string | NO | Long term order expire date, format `YYYY-MM-DD`, example: `2022-12-05`

Required when `time_in_force` is `GTD` | | side | string | YES | Order Side

**Enum Value:**
`Buy`
`Sell` | -| outside_rth | string | NO | Enable or disable outside regular trading hours

**Enum Value:**
`RTH_ONLY` - regular trading hour only
`ANY_TIME` - any time
`OVERNIGHT` - Overnight | +| outside_rth | string | NO | Enable or disable outside regular trading hours

**Enum Value:**
`RTH_ONLY` - regular trading hour only
`ANY_TIME` - any time
`OVERNIGHT` - Overnight
`OPTION_PRE_MARKET` - Overnight option | | time_in_force | string | YES | Time in force Type

**Enum Value:**
`Day` - Day Order
`GTC` - Good Til Canceled Order
`GTD` - Good Til Date Order | | remark | string | NO | remark (Maximum 255 characters) | | limit_depth_level | int32 | NO | Specifies the bid/ask depth level. Value range is -5 ~ 0 ~ 5.
Negative numbers indicate bid levels (e.g., -1 means best bid level 1),
positive numbers indicate ask levels (e.g., 1 means best ask level 1).
When set to 0, the `limit_offset` parameter takes effect.
Valid for `TSLPAMT` / `TSLPPCT` orders. | diff --git a/docs/en/docs/trade/overview.md b/docs/en/docs/trade/overview.md index 83db47ff1..94543b21b 100644 --- a/docs/en/docs/trade/overview.md +++ b/docs/en/docs/trade/overview.md @@ -16,7 +16,7 @@ sidebar_position: 1 - Trade + Trade Submit Order @@ -37,6 +37,9 @@ sidebar_position: 1 Get History Executions + + Get All Executions + Asset Get Account Balance diff --git a/docs/zh-CN/docs/trade/execution/all_executions.md b/docs/zh-CN/docs/trade/execution/all_executions.md new file mode 100644 index 000000000..3b76ad9e1 --- /dev/null +++ b/docs/zh-CN/docs/trade/execution/all_executions.md @@ -0,0 +1,294 @@ +--- +slug: all_executions +sidebar_position: 3 +title: 全部成交明细 +language_tabs: false +toc_footers: [] +includes: [] +search: true +highlight_theme: '' +headingLevel: 2 +--- + +该接口用于获取订单的成交明细,包括买入和卖出的成交记录,同时支持当日成交和历史成交查询。相比当日/历史成交接口,每条记录额外返回买卖方向 `side`。 + + + +## Request + + + + + + +
HTTP MethodGET
HTTP URL/v3/trade/execution/all
+ +### Parameters + +> Content-Type: application/json; charset=utf-8 + +| Name | Type | Required | Description | +| -------- | ------ | -------- | ----------------------------------------------------------------------------------------------------------------- | +| symbol | string | NO | 股票代码,使用 `ticker.region` 格式,例如:`AAPL.US` | +| order_id | string | NO | 订单 ID,例如:`701276261045858304` | +| start_at | string | NO | 开始时间,格式为时间戳 (秒),例如:`1650410999`。

开始时间为空时,默认为结束时间或当前时间前九十天。 | +| end_at | string | NO | 结束时间,格式为时间戳 (秒),例如:`1650410999`。

结束时间为空时,默认为开始时间后九十天或当前时间。 | +| page | int32 | NO | 页码,从 `1` 开始。单次查询最多返回 1000 条记录,若结果超过 1000 条,`has_more` 为 `true`,可结合 `has_more` 翻页。 | + +### Request Example + + + + +```python +from datetime import datetime +from longbridge.openapi import TradeContext, Config, OAuthBuilder + +oauth = OAuthBuilder("your-client-id").build(lambda url: print("Visit:", url)) +config = Config.from_oauth(oauth) +ctx = TradeContext(config) + +resp = ctx.all_executions( + symbol = "700.HK", + start_at = datetime(2022, 5, 9), + end_at = datetime(2022, 5, 12), +) +print(resp) +``` + + + + +```python +import asyncio +from datetime import datetime +from longbridge.openapi import AsyncTradeContext, 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 = AsyncTradeContext.create(config) + + resp = await ctx.all_executions( + symbol = "700.HK", + start_at = datetime(2022, 5, 9), + end_at = datetime(2022, 5, 12), + ) + print(resp) + +if __name__ == "__main__": + asyncio.run(main()) +``` + + + + +```javascript +const { Config, TradeContext, 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 = TradeContext.new(config) + const resp = await ctx.allExecutions({ symbol: '700.HK' }) + console.log(resp) +} +main().catch(console.error) +``` + + + + +```java +import com.longbridge.*; +import com.longbridge.trade.*; + +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); + TradeContext ctx = TradeContext.create(config)) { + AllExecutionsResponse resp = ctx.getAllExecutions(null).get(); + for (Execution e : resp.getTrades()) System.out.println(e); + } + } +} +``` + + + + +```rust +use std::sync::Arc; +use longbridge::{oauth::OAuthBuilder, trade::TradeContext, 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, _) = TradeContext::new(config); + let resp = ctx.all_executions(None).await?; + println!("{:?}", resp); + Ok(()) +} +``` + + + + +```cpp +#include +#include + +#ifdef WIN32 +#include +#endif + +using namespace longbridge; +using namespace longbridge::trade; + +static void +run(const OAuth& oauth) +{ + Config config = Config::from_oauth(oauth); + TradeContext ctx = TradeContext::create(config); + + ctx.all_executions(std::nullopt, [](auto res) { + if (!res) { std::cout << "failed" << std::endl; return; } + for (const auto& e : res->trades) std::cout << e.order_id << 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/trade" +) + +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) + } + tctx, err := trade.NewFromCfg(conf) + if err != nil { + log.Fatal(err) + } + defer tctx.Close() + start := time.Date(2022, 5, 9, 0, 0, 0, 0, time.UTC) + end := time.Date(2022, 5, 12, 0, 0, 0, 0, time.UTC) + resp, err := tctx.AllExecutions(context.Background(), &trade.GetAllExecutions{ + Symbol: "700.HK", + StartAt: start, + EndAt: end, + }) + if err != nil { + log.Fatal(err) + } + for _, e := range resp.Trades { + fmt.Println(e.OrderId) + } +} +``` + + + + +## Response + +### Response Headers + +- Content-Type: application/json + +### Response Example + +```json +{ + "code": 0, + "message": "success", + "data": { + "has_more": false, + "trades": [ + { + "order_id": "693664675163312128", + "price": "388", + "quantity": "100", + "symbol": "700.HK", + "trade_done_at": "1648611351", + "trade_id": "693664675163312128-1648611351433741210", + "side": "Buy" + } + ] + } +} +``` + +### Response Status + +| Status | Description | Schema | +| ------ | ------------------ | ----------------------------------------------- | +| 200 | 获取全部成交明细成功 | [all_executions_rsp](#schemaall_executions_rsp) | +| 400 | 请求参数有误,查询失败 | None | + + + +## Schemas + +### all_executions_rsp + + + + +| Name | Type | Required | Description | +| --------------- | -------- | -------- | --------------------------------------------------------------------- | +| has_more | boolean | true | 是否有更多记录。

单次查询最多返回 1000 条记录,若结果超过 1000 条,has_more 为 true | +| trades | object[] | false | 成交明细 | +| ∟ order_id | string | true | 订单 ID | +| ∟ trade_id | string | true | 成交 ID | +| ∟ symbol | string | true | 股票代码,使用 `ticker.region` 格式,例如:`AAPL.US` | +| ∟ trade_done_at | string | true | 成交时间,格式为时间戳 (秒) | +| ∟ quantity | string | true | 成交数量 | +| ∟ price | string | true | 成交价格 | +| ∟ side | string | true | 买卖方向

**可选值:**
`Buy` - 买入
`Sell` - 卖出 | diff --git a/docs/zh-CN/docs/trade/order/submit.md b/docs/zh-CN/docs/trade/order/submit.md index 56fe84bfa..4db734844 100644 --- a/docs/zh-CN/docs/trade/order/submit.md +++ b/docs/zh-CN/docs/trade/order/submit.md @@ -40,7 +40,7 @@ longbridge order sell TSLA.US 100 --price 260.00 | trailing_percent | string | NO | 跟踪涨跌幅,单位为百分比,例如 "2.5" 表示 "2.5%"

`TSLPPCT` 订单必填 | | expire_date | string | NO | 长期单过期时间,格式为 `YYYY-MM-DD`, 例如:`2022-12-05`

time_in_force 为 `GTD` 时必填 | | side | string | YES | 买卖方向

**可选值:**
`Buy` - 买入
`Sell` - 卖出 | -| outside_rth | string | NO | 是否允许盘前盘后,美股必填

**可选值:**
`RTH_ONLY` - 不允许盘前盘后
`ANY_TIME` - 允许盘前盘后
`OVERNIGHT` - 夜盘 | +| outside_rth | string | NO | 是否允许盘前盘后,美股必填

**可选值:**
`RTH_ONLY` - 不允许盘前盘后
`ANY_TIME` - 允许盘前盘后
`OVERNIGHT` - 夜盘
`OPTION_PRE_MARKET` - 夜盘期权 | | time_in_force | string | YES | 订单有效期类型

**可选值:**
`Day` - 当日有效
`GTC` - 撤单前有效
`GTD` - 到期前有效 | | remark | string | NO | 备注 (最大 64 字符) | | limit_depth_level | int32 | NO | 指定买卖档位,取值范围为 -5 ~ 0 ~ 5,负数代表买盘档位(如 -1 表示买一),
正数代表卖盘档位(如 1 表示卖一),为 0 时 limit_offset 参数生效
`TSLPAMT` / `TSLPPCT` 订单有效 | diff --git a/docs/zh-CN/docs/trade/overview.md b/docs/zh-CN/docs/trade/overview.md index 60232a1bf..ff2710671 100644 --- a/docs/zh-CN/docs/trade/overview.md +++ b/docs/zh-CN/docs/trade/overview.md @@ -17,7 +17,7 @@ sidebar_position: 1 - 交易 + 交易 委托下单 @@ -38,6 +38,9 @@ sidebar_position: 1 获取历史成交明细 + + 获取全部成交明细 + 资产 获取账户资金信息 diff --git a/docs/zh-HK/docs/trade/execution/all_executions.md b/docs/zh-HK/docs/trade/execution/all_executions.md new file mode 100644 index 000000000..39dce7b56 --- /dev/null +++ b/docs/zh-HK/docs/trade/execution/all_executions.md @@ -0,0 +1,294 @@ +--- +slug: all_executions +sidebar_position: 3 +title: 全部成交明細 +language_tabs: false +toc_footers: [] +includes: [] +search: true +highlight_theme: '' +headingLevel: 2 +--- + +該接口用於獲取訂單的成交明細,包括買入和賣出的成交記錄,同時支持當日成交和歷史成交查詢。相比當日/歷史成交接口,每條記錄額外返回買賣方向 `side`。 + + + +## Request + + + + + + +
HTTP MethodGET
HTTP URL/v3/trade/execution/all
+ +### Parameters + +> Content-Type: application/json; charset=utf-8 + +| Name | Type | Required | Description | +| -------- | ------ | -------- | ----------------------------------------------------------------------------------------------------------------- | +| symbol | string | NO | 股票代碼,使用 `ticker.region` 格式,例如:`AAPL.US` | +| order_id | string | NO | 訂單 ID,例如:`701276261045858304` | +| start_at | string | NO | 開始時間,格式為時間戳 (秒),例如:`1650410999`。

開始時間為空時,默認為結束時間或當前時間前九十天。 | +| end_at | string | NO | 結束時間,格式為時間戳 (秒),例如:`1650410999`。

結束時間為空時,默認為開始時間後九十天或當前時間。 | +| page | int32 | NO | 頁碼,從 `1` 開始。單次查詢最多返回 1000 條記錄,若結果超過 1000 條,`has_more` 為 `true`,可結合 `has_more` 翻頁。 | + +### Request Example + + + + +```python +from datetime import datetime +from longbridge.openapi import TradeContext, Config, OAuthBuilder + +oauth = OAuthBuilder("your-client-id").build(lambda url: print("Visit:", url)) +config = Config.from_oauth(oauth) +ctx = TradeContext(config) + +resp = ctx.all_executions( + symbol = "700.HK", + start_at = datetime(2022, 5, 9), + end_at = datetime(2022, 5, 12), +) +print(resp) +``` + + + + +```python +import asyncio +from datetime import datetime +from longbridge.openapi import AsyncTradeContext, 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 = AsyncTradeContext.create(config) + + resp = await ctx.all_executions( + symbol = "700.HK", + start_at = datetime(2022, 5, 9), + end_at = datetime(2022, 5, 12), + ) + print(resp) + +if __name__ == "__main__": + asyncio.run(main()) +``` + + + + +```javascript +const { Config, TradeContext, 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 = TradeContext.new(config) + const resp = await ctx.allExecutions({ symbol: '700.HK' }) + console.log(resp) +} +main().catch(console.error) +``` + + + + +```java +import com.longbridge.*; +import com.longbridge.trade.*; + +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); + TradeContext ctx = TradeContext.create(config)) { + AllExecutionsResponse resp = ctx.getAllExecutions(null).get(); + for (Execution e : resp.getTrades()) System.out.println(e); + } + } +} +``` + + + + +```rust +use std::sync::Arc; +use longbridge::{oauth::OAuthBuilder, trade::TradeContext, 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, _) = TradeContext::new(config); + let resp = ctx.all_executions(None).await?; + println!("{:?}", resp); + Ok(()) +} +``` + + + + +```cpp +#include +#include + +#ifdef WIN32 +#include +#endif + +using namespace longbridge; +using namespace longbridge::trade; + +static void +run(const OAuth& oauth) +{ + Config config = Config::from_oauth(oauth); + TradeContext ctx = TradeContext::create(config); + + ctx.all_executions(std::nullopt, [](auto res) { + if (!res) { std::cout << "failed" << std::endl; return; } + for (const auto& e : res->trades) std::cout << e.order_id << 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/trade" +) + +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) + } + tctx, err := trade.NewFromCfg(conf) + if err != nil { + log.Fatal(err) + } + defer tctx.Close() + start := time.Date(2022, 5, 9, 0, 0, 0, 0, time.UTC) + end := time.Date(2022, 5, 12, 0, 0, 0, 0, time.UTC) + resp, err := tctx.AllExecutions(context.Background(), &trade.GetAllExecutions{ + Symbol: "700.HK", + StartAt: start, + EndAt: end, + }) + if err != nil { + log.Fatal(err) + } + for _, e := range resp.Trades { + fmt.Println(e.OrderId) + } +} +``` + + + + +## Response + +### Response Headers + +- Content-Type: application/json + +### Response Example + +```json +{ + "code": 0, + "message": "success", + "data": { + "has_more": false, + "trades": [ + { + "order_id": "693664675163312128", + "price": "388", + "quantity": "100", + "symbol": "700.HK", + "trade_done_at": "1648611351", + "trade_id": "693664675163312128-1648611351433741210", + "side": "Buy" + } + ] + } +} +``` + +### Response Status + +| Status | Description | Schema | +| ------ | ------------------ | ----------------------------------------------- | +| 200 | 獲取全部成交明細成功 | [all_executions_rsp](#schemaall_executions_rsp) | +| 400 | 請求參數有誤,查詢失敗 | None | + + + +## Schemas + +### all_executions_rsp + + + + +| Name | Type | Required | Description | +| --------------- | -------- | -------- | --------------------------------------------------------------------- | +| has_more | boolean | true | 是否有更多記錄。

單次查詢最多返回 1000 條記錄,若結果超過 1000 條,has_more 為 true | +| trades | object[] | false | 成交明細 | +| ∟ order_id | string | true | 訂單 ID | +| ∟ trade_id | string | true | 成交 ID | +| ∟ symbol | string | true | 股票代碼,使用 `ticker.region` 格式,例如:`AAPL.US` | +| ∟ trade_done_at | string | true | 成交時間,格式為時間戳 (秒) | +| ∟ quantity | string | true | 成交數量 | +| ∟ price | string | true | 成交價格 | +| ∟ side | string | true | 買賣方向

**可選值:**
`Buy` - 買入
`Sell` - 賣出 | diff --git a/docs/zh-HK/docs/trade/order/submit.md b/docs/zh-HK/docs/trade/order/submit.md index 89537bca3..55fac1b60 100644 --- a/docs/zh-HK/docs/trade/order/submit.md +++ b/docs/zh-HK/docs/trade/order/submit.md @@ -44,7 +44,7 @@ longbridge order sell TSLA.US 100 --price 260.00 | trailing_percent | string | NO | 跟蹤漲跌幅

`TSLPPCT` 訂單必填 | | expire_date | string | NO | 長期單過期時間,格式為 `YYYY-MM-DD`, 例如:`2022-12-05`

time_in_force 為 `GTD` 時必填 | | side | string | YES | 買賣方向

**可選值:**
`Buy` - 買入
`Sell` - 賣出 | -| outside_rth | string | NO | 是否允許盤前盤後,美股必填

**可選值:**
`RTH_ONLY` - 不允許盤前盤後
`ANY_TIME` - 允許盤前盤後
`OVERNIGHT` - 夜盤 | +| outside_rth | string | NO | 是否允許盤前盤後,美股必填

**可選值:**
`RTH_ONLY` - 不允許盤前盤後
`ANY_TIME` - 允許盤前盤後
`OVERNIGHT` - 夜盤
`OPTION_PRE_MARKET` - 夜盤期權 | | time_in_force | string | YES | 訂單有效期類型

**可選值:**
`Day` - 當日有效
`GTC` - 撤單前有效
`GTD` - 到期前有效 | | remark | string | NO | 備註 (最大 64 字符) | | limit_depth_level | int32 | NO | 指定買賣檔位,取值範圍為 -5 ~ 0 ~ 5,負數代表買盤檔位(例如 -1 表示買一),
正數代表賣盤檔位(例如 1 表示賣一),當為 0 時 limit_offset 參數生效
`TSLPAMT` / `TSLPPCT` 訂單有效 | diff --git a/docs/zh-HK/docs/trade/overview.md b/docs/zh-HK/docs/trade/overview.md index b9a084deb..3b2d12ee2 100644 --- a/docs/zh-HK/docs/trade/overview.md +++ b/docs/zh-HK/docs/trade/overview.md @@ -17,7 +17,7 @@ sidebar_position: 1 - 交易 + 交易 委托下單 @@ -38,6 +38,9 @@ sidebar_position: 1 獲取曆史成交明細 + + 獲取全部成交明細 + 資產 獲取賬戶資金信息