Skip to main content

Get History Order

This API is used to get history order

Request

HTTP MethodGET
HTTP URL/v1/trade/order/history

Parameters

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

NameTypeRequiredDescription
symbolstringNOStock symbol, use ticker.region format, example: AAPL.US
statusstring[]NOOrder status

example: status=FilledStatus&status=NewStatus
sidestringNOOrder side

Enum Value:
Buy
Sell
marketstringNOMarket

Enum Value:
US - United States of America Market
HK - Hong Kong Market
start_atstringNOStart 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_atstringNOEnd 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.

Request Example

from datetime import datetime
from longport.openapi import TradeContext, Config, OrderStatus, OrderSide, Market

config = Config.from_env()
ctx = TradeContext(config)

resp = ctx.history_orders(
symbol = "700.HK",
status = [OrderStatus.Filled, OrderStatus.New],
side = OrderSide.Buy,
market = Market.HK,
start_at = datetime(2022, 5, 9),
end_at = datetime(2022, 5, 12),
)
print(resp)

Response

Response Headers

  • Content-Type: application/json

Response Example

{
"code": 0,
"message": "success",
"data": {
"orders": [
{
"currency": "HKD",
"executed_price": "0.000",
"executed_quantity": "0",
"expire_date": "",
"last_done": "",
"limit_offset": "",
"msg": "",
"order_id": "706388312699592704",
"order_type": "ELO",
"outside_rth": "UnknownOutsideRth",
"price": "11.900",
"quantity": "200",
"side": "Buy",
"status": "RejectedStatus",
"stock_name": "Bank of East Asia Ltd/The",
"submitted_at": "1651644897",
"symbol": "23.HK",
"tag": "Normal",
"time_in_force": "Day",
"trailing_amount": "",
"trailing_percent": "",
"trigger_at": "0",
"trigger_price": "",
"trigger_status": "NOT_USED",
"updated_at": "1651644898",
"remark": ""
}
]
}
}

Response Status

StatusDescriptionSchema
200Get History Orders Successhistory_orders_rsp
400The query failed with an error in the request parameter.None

Schemas

history_orders_rsp

NameTypeRequiredDescription
has_morebooleantruehas 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
ordersobject[]falseOrder Detail
∟ order_idstringtrueOrder ID
∟ statusstringtrueOrder Status
∟ stock_namestringtrueStock Name
∟ quantitystringtrueSubmitted Quantity
∟ executed_quantitystringtrueExecuted Quantity.

when the order is not filled, value is 0
∟ pricestringtrueSubmitted Price.

when market condition order is not triggered, value is empty string
∟ executed_pricestringtrueExecuted Price.

when the order is not filled, value is 0
∟ submitted_atstringtrueSubmitted Time
∟ sidestringtrueOrder Side

Enum Value:
Buy
Sell
∟ symbolstringtrueStock symbol, use ticker.region format, example: AAPL.US
∟ order_typestringtrueOrder Type
∟ last_donestringtrueLast done.

when the order is not filled, value is empty string
∟ trigger_pricestringtrueLIT / MIT Order Trigger Price.

When the order is not LIT / MIT order, value is empty string
∟ msgstringtrueRejected message or remark, default value is empty string.
∟ tagstringtrueOrder tag

Enum Value
Normal - Normal Order
GTC - Long term Order
Grey - Grey Order
∟ time_in_forcestringtrueTime in force Type

Enum Value:
Day - Day Order
GTC - Good Til Canceled Order
GTD - Good Til Date Order
∟ expire_datestringtrueLong term order expire date, format: YYYY-MM-DD, example: 2022-12-05.

When not a long term order, default value is empty string
∟ updated_atstringtrueLast updated time, formatted as a timestamp (second)
∟ trigger_atstringtrueConditional order trigger time. formatted as a timestamp (second)
∟ trailing_amountstringtrueTSLPAMT order trailing amount.

When the order is not TSLPAMT order, value is empty string
∟ trailing_percentstringtrueTSLPPCT order trailing percent.

When the order is not TSLPPCT order, value is empty string
∟ limit_offsetstringtrueTSLPPCT order limit offset amount.

When the order is not TSLPPCT order, value is empty string
∟ trigger_statusstringtrueConditional Order Trigger Status
When an order is not a conditional order or a conditional order is not triggered, the trigger status is NOT_USED

Enum Value
NOT_USED
DEACTIVE
ACTIVE
RELEASED
∟ currencystringtrueCurrency
∟ outside_rthstringtrueEnable or disable outside regular trading hours
Default is UnknownOutsideRth when the order is not a US stock

Enum Value:
RTH_ONLY - Regular trading hour only
ANY_TIME - Any time"
∟ remarkstringtrueRemark