# Get Positions

position_list_query(code='', pl_ratio_min=None, pl_ratio_max=None, trd_env=TrdEnv.REAL, acc_id=0, acc_index=0, refresh_cache=False)

  • Description

    Query the holding position list of a specific trading account

  • Parameters

    Parameter Type Description
    code str Security symbol.
    pl_ratio_min float The lower limit of the current gain or loss ratio filter.
    pl_ratio_max float The upper limit of the current gain or loss ratio filter.
    trd_env TrdEnv Trading environment.
    acc_id int Trading account ID.
    acc_index int The account number in the trading account list.
    refresh_cache bool Whether to refresh the cache.
  • Return

    Field Type Description
    ret RET_CODE Interface result.
    data pd.DataFrame If ret == RET_OK, list of positions is returned.
    str If ret != RET_OK, error description is returned.
    • List of positions format as follows:
      Field Type Description
      position_side PositionSide Position direction
      code str Security code.
      stock_name str Security name.
      qty float The number of holdings.
      can_sell_qty float Available quantity.
      currency Currency Transaction currency.
      nominal_price float Market price.
      cost_price float Diluted Cost (for securities account). Average opening price (for futures account).
      cost_price_valid bool Whether the cost price is valid.
      market_val float Market value.
      pl_ratio float Proportion of gain or loss.
      pl_ratio_valid bool Whether the gain or loss ratio is valid.
      pl_val float Gain or loss.
      pl_val_valid bool Whether the gain or loss is valid.
      today_pl_val float Gain or loss today.
      today_trd_val float Transaction amount today.
      today_buy_qty float Total volume purchased today.
      today_buy_val float Total amount purchased today.
      today_sell_qty float Total volume sold today.
      today_sell_val float Total amount sold today.
      unrealized_pl float Unrealized gain or loss.
      realized_pl float Realized gain or loss.
  • 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.position_list_query()
if ret == RET_OK:
    print(data)
    if data.shape[0] > 0:  # If the position list is not empty
        print(data['stock_name'][0])  # Get the first stock name of the holding position
        print(data['stock_name'].values.tolist())  # Convert to list
else:
    print('position_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      qty  can_sell_qty  cost_price  cost_price_valid  market_val  nominal_price  pl_ratio  pl_ratio_valid    pl_val  pl_val_valid  today_buy_qty  today_buy_val  today_pl_val  today_trd_val  today_sell_qty  today_sell_val position_side unrealized_pl realized_pl currency
0   HK.00943                          ZHONGZHENG INTL   8000.0        8000.0      0.0320              True      200.00         0.0250    -21.87            True  -56.0000          True            0.0            0.0        0.0000         0.0000             0.0             0.0          LONG           N/A         N/A      HKD
ZHONGZHENG INTL
['ZHONGZHENG INTL']
1
2
3
4

Interface Limitations

  • A maximum of 10 requests per 30 seconds
  • Call this interface, only when the cache is refreshed, will it be restricted by the frequency limit