# 订单详情

该接口用于订单详情查询。

<CliCommand>
# 将下方订单 ID 替换为实际的订单 ID
longbridge order detail 693664675163312128
</CliCommand>

## SDK Links

SDK 方法：`order_detail`

- Python: [longbridge.openapi.TradeContext.order_detail](https://longbridge.github.io/openapi/python/reference_all/#longbridge.openapi.TradeContext.order_detail)
- Rust: [longbridge::trade::TradeContext#order_detail](https://longbridge.github.io/openapi/rust/longbridge/trade/struct.TradeContext.html#method.order_detail)
- Go: [TradeContext.OrderDetail](https://pkg.go.dev/github.com/longbridge/openapi-go/trade#TradeContext.OrderDetail)
- Node.js: [TradeContext#orderDetail](https://longbridge.github.io/openapi/nodejs/classes/TradeContext.html#orderdetail)
- Java: [TradeContext.getOrderDetail](https://longbridge.github.io/openapi/java/com/longbridge/trade/TradeContext.html#getOrderDetail(java.lang.String))
- C++: [longbridge::trade::TradeContext::order_detail](https://longbridge.github.io/openapi/cpp/classlongbridge_1_1trade_1_1_trade_context.html#aedb3d207a04d2a4bcde41e351b5c4f60)

## Request

<table className="http-basic">
<tbody>
<tr><td className="http-basic-key">HTTP Method</td><td>GET</td></tr>
<tr><td className="http-basic-key">HTTP URL</td><td>/v1/trade/order </td></tr>
</tbody>
</table>

### Parameters

> Content-Type: application/json; charset=utf-8

| Name     | Type   | Required | Description                                               |
| -------- | ------ | -------- | --------------------------------------------------------- |
| order_id | string | YES      | 订单 ID，用于指定订单 ID 查询，例如：`701276261045858304` |
| is_attached | bool   | NO       | order_id 是否为附加单  |

### Request Example

<Tabs groupId="request-example">
  <TabItem value="python" label="Python" default>

```python
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.order_detail(
    order_id = "701276261045858304",
    is_attached = False,
)
print(resp)
```

  </TabItem>
  <TabItem value="python-async" label="Python (async)">

```python
import asyncio
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.order_detail(
        order_id = "701276261045858304",
        is_attached = False,
    )
    print(resp)

if __name__ == "__main__":
    asyncio.run(main())
```

  </TabItem>
  <TabItem value="nodejs" label="Node.js">

```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.orderDetail("701276261045858304")
  console.log(resp)
}
main().catch(console.error)
```

  </TabItem>
  <TabItem value="java" label="Java">

```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)) {
            OrderDetail resp = ctx.getOrderDetail("701276261045858304").get();
            System.out.println(resp);
        }
    }
}
```

  </TabItem>
  <TabItem value="rust" label="Rust">

```rust
use std::sync::Arc;
use longbridge::{oauth::OAuthBuilder, trade::TradeContext, Config};

#[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, _) = TradeContext::new(config);
    let resp = ctx.order_detail("701276261045858304").await?;
    println!("{:?}", resp);
    Ok(())
}
```

  </TabItem>
  <TabItem value="cpp" label="C++">

```cpp
#include <iostream>
#include <longbridge.hpp>

#ifdef WIN32
#include <windows.h>
#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.order_detail("701276261045858304", [](auto res) {
        if (!res) { std::cout << "failed" << std::endl; return; }
        std::cout << res->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;
}
```

  </TabItem>
  <TabItem value="go" label="Go">

```go
package main

import (
	"context"
	"fmt"
	"log"

	"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()
	detail, err := tctx.OrderDetail(context.Background(), "701276261045858304")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", detail)
}
```

  </TabItem>
</Tabs>


## Response

### Response Headers

- Content-Type: application/json

### Response Example

```json
{
  "code": 0,
  "message": "success",
  "data": {
    "order_id": "828940451093708800",
    "status": "FilledStatus",
    "stock_name": "苹果",
    "quantity": "10",
    "executed_quantity": "10",
    "price": "200.000",
    "executed_price": "164.660",
    "submitted_at": "1680863604",
    "side": "Buy",
    "symbol": "AAPL.US",
    "order_type": "LO",
    "last_done": "164.660",
    "trigger_price": "0.0000",
    "msg": "",
    "tag": "Normal",
    "time_in_force": "Day",
    "expire_date": "2023-04-10",
    "updated_at": "1681113000",
    "trigger_at": "0",
    "trailing_amount": "",
    "trailing_percent": "",
    "limit_offset": "",
    "limit_depth_level": 0,
    "monitor_price": "",
    "trigger_count": 1,
    "trigger_status": "NOT_USED",
    "outside_rth": "ANY_TIME",
    "currency": "USD",
    "remark": "1680863603.927165",
    "free_status": "None",
    "free_amount": "",
    "free_currency": "",
    "deductions_status": "NONE",
    "deductions_amount": "",
    "deductions_currency": "",
    "platform_deducted_status": "NONE",
    "platform_deducted_amount": "",
    "platform_deducted_currency": "",
    "history": [
      {
        "price": "164.6600",
        "quantity": "10",
        "status": "FilledStatus",
        "msg": "Execution of 10",
        "time": "1681113000"
      },
      {
        "price": "200.0000",
        "quantity": "10",
        "status": "NewStatus",
        "msg": "",
        "time": "1681113000"
      }
    ],
    "charge_detail": {
      "items": [
        {
          "code": "BROKER_FEES",
          "name": "收费明细",
          "fees": []
        },
        {
          "code": "THIRD_FEES",
          "name": "第三方收费明细",
          "fees": []
        }
      ],
      "total_amount": "0",
      "currency": "USD"
    },
    "attached_orders": [
      {
        "order_id": "706388312699592705",
        "attached_type_display": 2,
        "trigger_price": "10.500",
        "quantity": "200",
        "executed_qty": "0",
        "status": "NewStatus",
        "updated_at": "1651644898",
        "withdrawn": false,
        "gtd": "",
        "time_in_force": "Day",
        "counter_id": "",
        "trigger_status": 0,
        "executed_amount": "0",
        "tag": 0,
        "submitted_at": "1651644897",
        "executed_price": "0.000",
        "force_only_rth": "RTH_ONLY",
        "reviewed": false,
        "activate_order_type": "MIT",
        "activate_rth": "RTH_ONLY",
        "submit_price": "",
        "limit_depth_level": 0
      }
    ],
    "multi_leg": {
      "strategy": "2",
      "strategy_name": "垂直策略",
      "multileg_id": "Spread_QQQ20260731C764/767",
      "code": "QQQ 260731 764/767 垂直策略",
      "legs": [
        {
          "symbol": "QQQ260731C764000.US",
          "side": "Buy",
          "position": "LONG",
          "ratio_quantity": "1",
          "strike_price": "764",
          "expire_date": "20260731",
          "contract_direction": "C"
        },
        {
          "symbol": "QQQ260731C767000.US",
          "side": "Sell",
          "position": "SHORT",
          "ratio_quantity": "1",
          "strike_price": "767",
          "expire_date": "20260731",
          "contract_direction": "C"
        }
      ]
    }
  }
}
```

### Response Status

| Status | Description              | Schema                                      |
| ------ | ------------------------ | ------------------------------------------- |
| 200    | 订单详情查询成功         | [order_detail_rsp](#schemaorder_detail_rsp) |
| 400    | 查询失败，请求参数错误。 | None                                        |

<aside className="success">
</aside>

## Schemas

### order_detail_rsp

<a id="schemaorder_detail_rsp"></a>
<a id="schemaorder_detail_rsp"></a>

订单信息

| Name                       | Type     | Required | Description                                                                                                                                                                                        |
| -------------------------- | -------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| order_id                   | string   | true     | 订单 ID                                                                                                                                                                                            |
| status                     | string   | true     | [订单状态](../trade-definition#orderstatus)                                                                                                                                                        |
| stock_name                 | string   | true     | 股票名称                                                                                                                                                                                           |
| quantity                   | string   | true     | 下单数量                                                                                                                                                                                           |
| executed_quantity          | string   | true     | 成交数量。<br/><br/>当订单未成交时为 0                                                                                                                                                             |
| price                      | string   | true     | 下单价格。<br/><br/>当市价条件单未触发时为空字符串                                                                                                                                                 |
| executed_price             | string   | true     | 成交价。<br/><br/>当订单未成交时为 0                                                                                                                                                               |
| submitted_at               | string   | true     | 下单时间                                                                                                                                                                                           |
| side                       | string   | true     | 买卖方向<br/><br/> **可选值：**<br/> `Buy` - 买入<br/> `Sell` - 卖出                                                                                                                               |
| symbol                     | string   | true     | 股票代码，使用 `ticker.region` 格式，例如：`AAPL.US`                                                                                                                                               |
| order_type                 | string   | true     | [订单类型](../trade-definition#ordertype)                                                                                                                                                          |
| last_done                  | string   | true     | 最近成交价格。<br/><br/>当订单未成交时为空字符串                                                                                                                                                   |
| trigger_price              | string   | true     | `LIT` / `MIT` 订单触发价格。<br/><br/>当订单不是 `LIT` / `MIT` 订单为空字符串                                                                                                                      |
| msg                        | string   | true     | 拒绝信息或备注，默认为空字符串。                                                                                                                                                                   |
| tag                        | string   | true     | 订单标记<br/><br/> **可选值：**<br/> `Normal` - 普通订单<br/> `Gtc` - 长期单<br/> `Grey` - 暗盘单                                                                                                  |
| time_in_force              | string   | true     | 订单有效期类型<br/><br/> **可选值：**<br/> `Day` - 当日有效<br/> `GTC` - 撤单前有效<br/> `GTD` - 到期前有效                                                                                        |
| expire_date                | string   | true     | 长期单过期时间，格式为 `YYYY-MM-DD`, 例如：`2022-12-05。<br/><br/> 不是长期单时，默认为空字符串。                                                                                                  |
| updated_at                 | string   | true     | 最近更新时间，格式为时间戳 (秒)，默认为 0。                                                                                                                                                        |
| trigger_at                 | string   | true     | 条件单触发时间，格式为时间戳 (秒)，默认为 0。                                                                                                                                                      |
| trailing_amount            | string   | true     | `TSLPAMT` 订单跟踪金额。<br/><br/>当订单不是 `TSLPAMT` 订单时为空字符串。                                                                                                                          |
| trailing_percent           | string   | true     | `TSLPPCT` 订单跟踪涨跌幅。<br/><br/>当订单不是 `TSLPPCT` 订单时为空字符串。                                                                                                                        |
| limit_offset               | string   | true     | `TSLPAMT` / `TSLPPCT` 订单指定价差。<br/><br/>当订单不是 `TSLPAMT` / `TSLPPCT` 订单时为空字符串。                                                                                                  |
| trigger_status             | string   | true     | 条件单触发状态<br/> 当订单不是条件单或条件单未触发时，触发状态为 NOT_USED<br/><br/> **可选值：**<br/> `NOT_USED` - 未激活<br/> `DEACTIVE` - 已失效<br/> `ACTIVE` - 已激活<br/> `RELEASED` - 已触发 |
| currency                   | string   | true     | 结算货币                                                                                                                                                                                           |
| outside_rth                | string   | true     | 是否允许盘前盘后<br/> 当订单不是美股时，默认为 UnknownOutsideRth<br/><br/> **可选值：**<br/> `RTH_ONLY` - 不允许盘前盘后<br/> `ANY_TIME` - 允许盘前盘后<br/> `OVERNIGHT` - 夜盘"                   |
| remark                     | string   | true     | 备注                                                                                                                                                                                               |
| free_status                | string   | true     | 免佣状态，默认为 None<br/><br/> **可选值：**<br/> `None` - 无<br/> `Calculated` - 免佣额待计算<br/> `Pending` - 待免佣<br/> `Ready` - 已免佣                                                       |
| free_amount                | string   | true     | 免佣金额，默认为空字符串                                                                                                                                                                           |
| free_currency              | string   | true     | 免佣货币，默认为空字符串                                                                                                                                                                           |
| deductions_status          | string   | true     | 抵扣状态/返现状态，默认为 NONE<br/><br/> **可选值：**<br/> `NONE` - 待结算 <br/> `NO_DATA` - 已结算无数据<br/> `PENDING` - 已结算待发放<br/> `DONE` - 已结算已发放                                 |
| deductions_amount          | string   | true     | 抵扣金额，默认为空字符串                                                                                                                                                                           |
| deductions_currency        | string   | true     | 抵扣货币，默认为空字符串                                                                                                                                                                           |
| platform_deducted_status   | string   | true     | 平台费抵扣状态/返现状态，默认为 NONE<br/><br/> **可选值：**<br/> `NONE` - 待结算 <br/> `NO_DATA` - 已结算无数据<br/> `PENDING` - 已结算待发放<br/> `DONE` - 已结算已发放                           |
| platform_deducted_amount   | string   | true     | 平台费抵扣金额，默认为空字符串                                                                                                                                                                     |
| platform_deducted_currency | string   | true     | 平台费抵扣货币，默认为空字符串                                                                                                                                                                     |
| history                    | object[] | true     | 订单历史明细                                                                                                                                                                                       |
| ∟ price                    | string   | true     | 成交展示成交价格，过期、撤单、拒绝等状态展示提交价格                                                                                                                                               |
| ∟ quantity                 | string   | true     | 成交展示成交数量，过期、撤单、拒绝等状态展示剩余数量                                                                                                                                               |
| ∟ status                   | string   | true     | 订单状态                                                                                                                                                                                           |
| ∟ msg                      | string   | true     | 成交或错误信息                                                                                                                                                                                     |
| ∟ time                     | string   | true     | 发生时间                                                                                                                                                                                           |
| charge_detail              | object   | true     | 订单费用                                                                                                                                                                                           |
| ∟ total_amount             | string   | true     | 全部费用                                                                                                                                                                                           |
| ∟ currency                 | string   | true     | 结算货币                                                                                                                                                                                           |
| ∟ items                    | object[] | true     | 订单费用明细                                                                                                                                                                                       |
| ∟∟ code                    | string   | true     | 收费类别代码<br/><br/> **可选值：**<br/> `UNKNOWN`<br/> `BROKER_FEES`<br/> `THIRD_FEES`                                                                                                            |
| ∟∟ name                    | string   | true     | 收费类别名称                                                                                                                                                                                       |
| ∟∟ fees                    | object[] | true     | 收费明细                                                                                                                                                                                           |
| ∟∟∟ code                   | string   | true     | 收费代码                                                                                                                                                                                           |
| ∟∟∟ name                   | string   | true     | 收费名称                                                                                                                                                                                           |
| ∟∟∟ amount                 | string   | true     | 单项收费金额                                                                                                                                                                                       |
| ∟∟∟ currency               | string   | true     | 收费货币                                                                                                                                                                                           |
| ∟ limit_depth_level        | int32    | true     | 指定买卖档位 |
| ∟ monitor_price            | string   | true     | 监控价格 |
| ∟ trigger_count            | int32    | true     | 触发次数 |
| ∟ attached_orders          | object[] | false    | 附加订单详情列表 |
| ∟∟ order_id                | string   | true     | 附加订单 ID |
| ∟∟ attached_type_display   | int32    | true     | 附加订单类型。**可选值：** `1` - 止盈 `2` - 止损 |
| ∟∟ trigger_price           | string   | true     | 触发价格 |
| ∟∟ quantity                | string   | true     | 下单数量 |
| ∟∟ executed_qty            | string   | true     | 成交数量 |
| ∟∟ status                  | string   | true     | 订单状态 |
| ∟∟ updated_at              | string   | true     | 最近更新时间，格式为时间戳 (秒) |
| ∟∟ withdrawn               | boolean  | true     | 是否已撤销 |
| ∟∟ gtd                     | string   | true     | GTD 到期日期，格式为 `YYYY-MM-DD` |
| ∟∟ time_in_force           | string   | true     | 订单有效期类型<br/><br/> **可选值：**<br/> `Day` - 当日有效<br/> `GTC` - 撤单前有效<br/> `GTD` - 到期前有效 |
| ∟∟ counter_id              | string   | true     | 对应单 ID |
| ∟∟ trigger_status          | int32    | true     | 附加单激活后的条件单触发状态。<br/>`0` - 未激活 <br/>`1` - 监控中 <br/>`2` - 已撤单 <br/>`4` - 已触发 |
| ∟∟ executed_amount         | string   | true     | 成交金额 |
| ∟∟ tag                     | int32    | true     | 订单标记 |
| ∟∟ submitted_at            | string   | true     | 下单时间，格式为时间戳 (秒) |
| ∟∟ executed_price          | string   | true     | 成交价格 |
| ∟∟ force_only_rth          | string   | true     | 是否仅正常交易时段执行。 |
| ∟∟ reviewed                | boolean  | true     | 是否已审核 |
| ∟∟ activate_order_type     | string   | true     | 触发后提交的订单类型，例如 `LIT`（限价单）或 `MIT`（市价单） |
| ∟∟ activate_rth            | string   | true     | 触发后提交订单是否允许盘前盘后。 |
| ∟∟ submit_price            | string   | true     | 委托价格 |
| ∟∟ limit_depth_level       | int32    | true     | 指定买卖档位 |
| multi_leg                  | object   | false    | 多腿策略信息，仅多腿期权组合订单返回，非组合订单不返回。 |
| ∟ strategy                 | string   | false    | 多腿策略<br/><br/> **可选值：**<br/> `0` - CoveredCall（股票担保）<br/> `1` - CoveredPut（股票担保）<br/> `2` - VerticalCallSpread（垂直策略）<br/> `3` - VerticalPutSpread（垂直策略）<br/> `4` - Collar（领式策略）<br/> `5` - Straddle（跨式策略）<br/> `6` - Strangle（宽跨式策略）<br/> `7` - CalendarCallSpread（日历策略）<br/> `8` - CalendarPutSpread（日历策略） |
| ∟ strategy_name            | string   | false    | 策略名称 |
| ∟ multileg_id              | string   | false    | 多腿组合 ID |
| ∟ code                     | string   | false    | 多腿组合代码 |
| ∟ legs                     | object[] | false    | 组合订单的各腿 |
| ∟∟ symbol                  | string   | false    | 期权 symbol，使用 `ticker.region` 格式，例如：`QQQ260731C764000.US` |
| ∟∟ side                    | string   | false    | 买卖方向<br/><br/> **可选值：**<br/> `Buy`<br/> `Sell` |
| ∟∟ position                | string   | false    | 持仓方向<br/><br/> **可选值：**<br/> `LONG`<br/> `SHORT` |
| ∟∟ ratio_quantity          | string   | false    | 该腿比例数量 |
| ∟∟ strike_price            | string   | false    | 行权价 |
| ∟∟ expire_date             | string   | false    | 期权到期日，格式：`YYYYMMDD` |
| ∟∟ contract_direction      | string   | false    | 合约类型<br/><br/> **可选值：**<br/> `C` - 看涨（Call）<br/> `P` - 看跌（Put） |