## 提示

- `live-or-trading-module-only`
- `backtest-only`
- `broker-or-counter-dependent`


## 条目定义

**类型：** 账户持仓函数

**官方名称：** `Position`

本条目不是独立可调用函数，用于说明对象属性、数据字段、枚举、日志或平台约定。

## 释义

Position 是 PTrade 文档中的持仓对象参考条目。

研究：不支持；回测：支持；模拟：官方目录未明确；实盘：支持。

## 参数

本条目没有独立函数参数。字段、取值或对象属性请查看下方官方详细说明。

## 返回值

本条目不是独立可调用函数，没有单独返回值。

## 示例

```python
def initialize(context):

g.security = '600570.SS'

set_universe(g.security)

def handle_data(context, data):

order(g.security,1000)

position = get_position(g.security)

log.info(position)
```

## 详细说明

### 使用场景

该对象仅支持回测、交易模块。

对象说明

持有的某个标的的信息。

### 注意事项

期货业务持仓把单个合约的持仓分为了多头仓(long)、空头仓(short)。

交易中对象内的数据更新周期默认为6s(具体配置需咨询所在券商)，即上一次账户资金、委托、持仓查询并更新到对象中后，间隔6s发起下一次查询。数据更新时间范围为before_trading_start-after_trading_end。

交易场景下，持仓信息是每6秒与柜台同步后更新的，update_time字段记录了最近的更新时间，格式为："%Y-%m-%d %H:%M:%S"。回测场景返回None。

内容

股票账户返回

sid 标的代码

enable_amount 可用数量

amount 总持仓数量

last_sale_price 最新价格

cost_basis 持仓成本价格

today_amount 今日开仓数量

business_type 持仓类型

update_time 持仓更新时间

期货账户返回：

sid 标的代码

short_enable_amount 空头仓可用数量

long_enable_amount 多头仓可用数量

today_short_amount 空头仓今仓数量

today_long_amount 多头仓今仓数量

long_cost_basis 多头仓持仓成本

short_cost_basis 空头仓持仓成本

long_amount 多头仓总持仓量

short_amount 空头仓总持仓量

long_pnl 多头仓浮动盈亏

short_pnl 空头仓浮动盈亏

amount 总持仓数量

enable_amount 可用数量

last_sale_price 最新价格

business_type 持仓类型

delivery_date 交割日，期货使用

margin 持仓保证金

contract_multiplier 合约乘数

update_time 持仓更新时间
