委托下單
該接口用於港美股,窩輪,期權的委托下單。
SDK Links
Python | longport.openapi.TradeContext.submit_order |
Rust | longport::trade::TradeContext#submit_order |
Go | TradeContext.SubmitOrder |
Node.js | TradeContext#submitOrder |
Request
| HTTP Method | POST |
| HTTP URL | /v1/trade/order |
Parameters
Content-Type: application/json; charset=utf-8
| Name | Type | Required | Description |
|---|---|---|---|
| symbol | string | YES | 股票代碼,使用 ticker.region 格式,例如:AAPL.US |
| order_type | string | YES | 訂單類型 |
| submitted_price | string | NO | 下單價格,例如:388.5LO / ELO / ALO / ODD / LIT 訂單必填 |
| submitted_quantity | string | YES | 下單數量,例如:100 |
| trigger_price | string | NO | 觸發價格,例如:388.5LIT / MIT 訂單必填 |
| limit_offset | string | NO | 指定價差TSLPAMT / TSLPPCT 訂單必填 |
| trailing_amount | string | NO | 跟蹤金額TSLPAMT 訂單必填 |
| trailing_percent | string | NO | 跟蹤漲跌幅TSLPPCT 訂單必填 |
| expire_date | string | NO | 長期單過期時間,格式為 YYYY-MM-DD, 例如:2022-12-05time_in_force 為 GTD 時必填 |
| side | string | YES | 買賣方向 可選值: Buy - 買入Sell - 賣出 |
| outside_rth | string | NO | 是否允許盤前盤後,美股必填 可選值: RTH_ONLY - 不允許盤前盤後ANY_TIME - 允許盤前盤後OVERNIGHT - 夜盤 |
| time_in_force | string | YES | 訂單有效期類型 可選值: Day - 當日有效GTC - 撤單前有效GTD - 到期前有效 |
| remark | string | NO | 備註 (最大 64 字符) |
Request Example
python
from decimal import Decimal
from longport.openapi import TradeContext, Config, OrderType, OrderSide, TimeInForceType
# Load configuration from environment variables
config = Config.from_env()
# Create a context for trade APIs
ctx = TradeContext(config)
# Submit order
resp = ctx.submit_order("700.HK", OrderType.LO, OrderSide.Buy, Decimal(500), TimeInForceType.Day, submitted_price=Decimal(50), remark="Hello from Python SDK")
print(resp)Response
Response Headers
- Content-Type: application/json
Response Example
json
{
"code": 0,
"message": "success",
"data": {
"order_id": 683615454870679600
}
}Response Status
| Status | Description | Schema |
|---|---|---|
| 200 | 提交成功,訂單已委托。 | None |
| 400 | 下單被拒絕,請求參數錯誤。 | None |