# Get Positions

position_list_query(code='', position_market=TrdMarket.NONE, 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.
    position_market TrdMarket Filter positions by market.
    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.
      position_market TrdMarket Position market.
      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 Cost (for futures account).
      cost_price_valid bool Whether the cost price is valid.
      average_cost float Average cost price
      diluted_cost float Diluted cost price
      market_val float Market value.
      pl_ratio float Proportion of gain or loss(under diluted cost price)
      pl_ratio_valid bool Whether the gain or loss ratio is valid.
      pl_ratio_avg_cost float Proportion of gain or loss(under average cost price)
      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 futu 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 position_market    qty  can_sell_qty  cost_price  cost_price_valid average_cost  diluted_cost  market_val  nominal_price  pl_ratio  pl_ratio_valid pl_ratio_avg_cost  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.01810   XIAOMI-W              HK  400.0         400.0      53.975              True          53.975        53.975     19760.0           49.4 -8.476146            True            -8.476146    -1830.0          True           0.0           0.0          0.0           0.0            0.0            0.0          LONG           0.0         0.0      HKD
XIAOMI-W
['XIAOMI-W']
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