跳到正文
PTrade
PTrade账户、持仓与对账

get_all_positions

该接口用于获取当前账户的持仓信息详情。

原型

get_all_positions()

适用环境

该函数仅在交易模块可用

释义

该接口用于获取当前账户的持仓信息详情。

注意事项

因不同柜台返回的字段存在差异,当该接口返回的字段不在返回字段描述中时请咨询券商人员。

不同柜台返回的字段值类型不一致,比如不同柜台返回的enable_amount类型有可能为str/float/int,需要策略中对此做兼容。

该接口返回当前账户所有的持仓信息,包含国债逆回购产生的新标准券、打新中签尚未上市等量化不支持标的的持仓。

为减小对柜台压力,该函数返回的是缓存的账户定时同步持仓查询数据。

参数

无。

返回值

返回一个列表,包含不同标的字典类型的持仓信息。不同交易类型返回不同字段的持仓信息。

[{'position_str': '0111900000000001926516100010000000000A027483621600010', 'fund_account': '19265161', 'exchange_type': '1', 'stock_account': 'A027483621', 'stock_code': '600010', 'stock_name': '包钢股份', 'stock_type': '0', 'current_amount': 8300.0, 'enable_amount': 0.0, 'last_price': 1.86, 'cost_price': 1.862, 'keep_cost_price': 1.862, 'income_balance': -18.22, 'hand_flag': '0', 'market_value': 15438.0, 'av_buy_price': 0.0, 'av_income_balance': 0.0, 'client_id': '19265161', 'cost_balance': 15443.25, 'hold_amount': 0.0, 'uncome_buy_amount': 0.0, 'uncome_sell_amount': 0.0, 'entrust_sell_amount': 0.0, 'real_buy_amount': 8300.0, 'real_sell_amount': 0.0, 'asset_price': 1.86, 'delist_flag': '0', 'delist_date': 0, 'par_value': 1.0, 'income_balance_nofare': -5.25, 'frozen_amount': 0.0, 'profit_ratio': -0.11, 'sub_stock_type': '!', 'stbtrans_type': ' ', 'stb_layer_flag': ' ', 'av_cost_price': 1.861, 'income_flag': ' ', 'real_sell_balance': 0.0, 'real_buy_balance': 15443.25, 'sum_buy_amount': 0.0, 'sum_buy_balance': 0.0, 'sum_sell_amount': 0.0, 'sum_sell_balance': 0.0, 'correct_amount': 0.0, 'stbtrans_flag': ' ', 'stock_name_long': '包钢股份', 'pre_dr_price': 1.86, 'close_price': 1.86, 'hold_cost_price': 1.861, 'comb_hold_flag': '0', 'store_unit': 1},]

股票

exchange_type  交易类别

stock_code  证券代码

stock_name  证券名称

stock_type  证券类别

hold_amount  持有数量

current_amount  当前数量

enable_amount  可用数量

real_buy_amount  回报买入数量

real_sell_amount  回报卖出数量

uncome_buy_amount  未回买入数量

uncome_sell_amount  未回卖出数量

entrust_sell_amount  委托卖出数量

last_price  最新价

cost_price  成本价

keep_cost_price  保本价

income_balance  盈亏金额

market_value  证券市值

av_buy_price  买入均价

av_income_balance  实现盈亏

cost_balance  持仓成本

delist_flag  退市标志

delist_date  退市日期

income_balance_nofare  无费用盈亏

frozen_amount  冻结数量

profit_ratio  盈亏比例(%)

asset_price  市值价

av_cost_price  摊薄成本价

融资融券

exchange_type  交易类别

stock_code  证券代码

stock_name  证券名称

current_amount  当前数量

hold_amount  持有数量

enable_amount  可用数量

last_price  最新价

cost_price  成本价

income_balance  盈亏金额

income_balance_nofare  无费用盈亏

market_value  证券市值

av_buy_price  买入均价

av_income_balance  实现盈亏

cost_balance  持仓成本

uncome_buy_amount  未回买入数量

uncome_sell_amount  未回卖出数量

entrust_sell_amount  委托卖出数量

real_buy_amount  回报买入数量

real_sell_amount  回报卖出数量

asset_price  市值价

assure_ratio  担保折算率

profit_ratio  盈亏比例(%)

sum_buy_amount  累计买入数量

sum_buy_balance  累计买入金额

sum_sell_amount  累计卖出数量

sum_sell_balance  累计卖出金额

real_buy_balance  回报买入金额

real_sell_balance  回报卖出金额

av_cost_price  摊薄成本价

期货

futu_exch_type  交易类别

futu_code  合约代码

entrust_bs  委托方向

begin_amount  期初数量

enable_amount  可用数量

real_enable_amount  当日开仓可用数量

hold_income_float  持仓浮动盈亏

hold_income  期货盯市盈亏

hold_margin  持仓保证金

average_price  平均价

average_hold_price  持仓均价

tas_average_hold_price  TAS持仓均价

futu_last_price  最新价格

hedge_type  投机/套保类型

real_amount  成交数量

real_open_balance  回报开仓金额

old_open_balance  老仓持仓成交额

real_current_amount  今总持仓

old_current_amount  老仓持仓数量

tas_current_amount  TAS持仓数量

combinable_amount  可组合持仓数量

字段备注

delist_date:默认为0。

示例

def initialize(context):
    g.security = "600570.SS"
    set_universe(g.security)

def before_trading_start(context, data):
    g.flag = False

def handle_data(context, data):
    if not g.flag:
        # 打印当前账户全部持仓
        log.info(get_all_positions())
        g.flag = True

本页目录