# Get Historical Orders

history_order_list_query(status_filter_list=[], code='', start='', end='', trd_env=TrdEnv.REAL, acc_id=0, acc_index=0)

  • Description

    Query the historical order list of a specified trading account

  • Parameters

    Parameter Type Description
    status_filter_list list Order status filter conditions.
    code str Security symbol.
    start str Start time.
    end str End time
    trd_env TrdEnv Trading environment.
    acc_id int Trading account ID.
    acc_index int The account number in the trading account list.
    • The combination of start and end is as follows
      Start type End type Description
      str str start and end are the specified dates respectively.
      None str start is 90 days before end.
      str None end is 90 days after start.
      None None start is 90 days before, end is the current date.
  • Return

    Field Type Description
    ret RET_CODE Interface result.
    data pd.DataFrame If ret == RET_OK, order list is returned.
    str If ret != RET_OK, error description is returned.
    • Order list format as follows:
      Field Type Description
      trd_side TrdSide Trading direction.
      order_type OrderType Order type.
      order_status OrderStatus Order status.
      order_id str Order ID.
      code str Security code.
      stock_name str Security name.
      qty float Order quantity.
      price float Order price.
      currency Currency Transaction currency.
      create_time str Create time.
      updated_time str Last update time.
      dealt_qty float Deal quantity
      dealt_avg_price float Average deal price.
      last_err_msg str The last error description.
      remark str Identification of remarks when placing an order.
      time_in_force TimeInForce Valid period.
      fill_outside_rth bool Whether pre-market and after-hours are needed.
      aux_price float Traget price.
      trail_type TrailType Trailing type.
      trail_value float Trailing amount/ratio.
      trail_spread float Specify spread.
  • Example

from moomoo import *
trd_ctx = OpenSecTradeContext(filter_trdmarket=TrdMarket.HK, host='127.0.0.1', port=11111, security_firm=SecurityFirm.FUTUSECURITIES)
ret, data = trd_ctx.history_order_list_query()
if ret == RET_OK:
    print(data)
    if data.shape[0] > 0:  # If the order list is not empty
        print(data['order_id'][0])  # Get Order ID of the first holding position
        print(data['order_id'].values.tolist())  # Convert to list
else:
    print('history_order_list_query error: ', data)
trd_ctx.close()
1
2
3
4
5
6
7
8
9
10
11
  • Output
        code stock_name trd_side           order_type   order_status             order_id    qty  price              create_time             updated_time  dealt_qty  dealt_avg_price last_err_msg      remark time_in_force fill_outside_rth aux_price trail_type trail_value trail_spread currency
0   HK.00700                 BUY           NORMAL  CANCELLED_ALL  6644468615272262086  100.0  520.0  2021-09-06 10:17:52.465  2021-09-07 16:10:22.806        0.0              0.0               asdfg+=@@@           GTC              N/A       560        N/A         N/A          N/A      HKD
6644468615272262086
['6644468615272262086']
1
2
3
4

Interface Limitations

  • A maximum of 10 requests per 30 seconds

Tips

  • Historical orders are arranged in reverse chronological order: later orders return first, followed by earlier orders.