# 查询持仓

# position_list_query

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)

  • 介绍

    查询交易业务账户的持仓列表

  • 参数

    参数 类型 说明
    code str 代码过滤
    pl_ratio_min float 当前盈亏比例下限过滤,仅返回高于此比例的持仓
    pl_ratio_max float 当前盈亏比例上限过滤,低于此比例的会返回
    trd_env TrdEnv 交易环境
    acc_id int 交易业务账户 ID
    acc_index int 交易业务账户列表中的账户序号
    refresh_cache bool 是否刷新缓存
  • 返回

    参数 类型 说明
    ret RET_CODE 接口调用结果
    data pd.DataFrame 当 ret == RET_OK 时,返回持仓列表
    str 当 ret != RET_OK 时,返回错误描述
    • 持仓列表
      字段 类型 说明
      position_side PositionSide 持仓方向
      code str 股票代码
      stock_name str 股票名称
      qty float 持有数量
      can_sell_qty float 可用数量
      currency Currency 交易货币
      nominal_price float 市价
      cost_price float 摊薄成本价(证券账户),平均开仓价(期货账户)
      cost_price_valid bool 成本价是否有效
      market_val float 市值
      pl_ratio float 盈亏比例
      pl_ratio_valid bool 盈亏比例是否有效
      pl_val float 盈亏金额
      pl_val_valid bool 盈亏金额是否有效
      today_pl_val float 今日盈亏金额
      today_trd_val float 今日交易金额
      today_buy_qty float 今日买入总量
      today_buy_val float 今日买入总额
      today_sell_qty float 今日卖出总量
      today_sell_val float 今日卖出总额
      unrealized_pl float 未实现盈亏
      realized_pl float 已实现盈亏
  • 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:  # 如果持仓列表不为空
        print(data['stock_name'][0])  # 获取持仓第一个股票名称
        print(data['stock_name'].values.tolist())  # 转为 list
else:
    print('position_list_query error: ', data)
trd_ctx.close()  # 关闭当条连接
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                          中证国际   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
中证国际
['中证国际']
1
2
3
4

接口限制

  • 每 30 秒内最多请求 10 次查询持仓接口
  • 调用此接口,只有在刷新缓存时,才受到限频限制