# Get Historical Deals

history_deal_list_query(code='', start='', end='', trd_env=TrdEnv.REAL, acc_id=0, acc_index=0)

  • Description

    Query historical deal list of a specific trading account.
    This feature is only available for live trading and not for paper trading.

  • Parameters

    Parameter Type Description
    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, transaction list is returned.
    str If ret != RET_OK, error description is returned.
    • Transaction list format as follows:
      Field Type Description
      trd_side TrdSide Trading direction.
      deal_id str Deal number.
      order_id str Order ID.
      code str Security code.
      stock_name str Security name.
      qty float Quantity of shares bought/sold on this fill.
      price float Fill price.
      create_time str Create time.
      counter_broker_id int Counter broker ID.
      counter_broker_name str Counter broker name.
      status DealStatus Deal status.
  • 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_deal_list_query()
if ret == RET_OK:
    print(data)
    if data.shape[0] > 0:  # If the order fill list is not empty
        print(data['deal_id'][0])  # Get the first deal ID of the history order fill list
        print(data['deal_id'].values.tolist())  # Convert to list
else:
    print('history_deal_list_query error: ', data)
trd_ctx.close()  # Close the current connection
1
2
3
4
5
6
7
8
9
10
11
  • Output
    code stock_name              deal_id             order_id    qty  price trd_side              create_time  counter_broker_id counter_broker_name status
0  HK.00388      Hong Kong Exchanges and Clearing  5056208452274069375  4665291631090960915  100.0  370.0      BUY  2020-09-17 21:15:59.979                  5                         OK)    
5056208452274069375
['5056208452274069375']
1
2
3
4

Interface Limitations

  • A maximum of 10 requests per 30 seconds

Tips

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