合约持仓
More...
#include <position.hpp>
合约持仓
用户在某个合约上的持仓信息,分为多头和空头两个方向。 系统通过此结构追踪用户的头寸和盈亏状态。
- 盈亏计算
- 多头浮动盈亏 = (最新价 - 多头均价) × 多头持仓量 × 合约乘数
- 空头浮动盈亏 = (空头均价 - 最新价) × 空头持仓量 × 合约乘数
- 使用示例
合约持仓
Definition position.hpp:45
void updateProfit(double lastPrice, int volumeMultiple)
更新浮动盈亏
Definition position.hpp:130
std::string instrumentId
合约代码(如 "IF2601")
Definition position.hpp:50
int64_t longPosition
多头持仓量(手数)
Definition position.hpp:55
double longAvgPrice
多头持仓均价
Definition position.hpp:56
std::string accountId
账户ID
Definition position.hpp:49
◆ Position() [1/2]
| fix40::Position::Position |
( |
| ) |
|
|
inline |
默认构造函数
初始化所有数值字段为 0,时间戳为当前时间。
◆ Position() [2/2]
| fix40::Position::Position |
( |
const std::string & |
accId, |
|
|
const std::string & |
instId |
|
) |
| |
|
inline |
◆ getNetPosition()
| int64_t fix40::Position::getNetPosition |
( |
| ) |
const |
|
inline |
获取净持仓
- Returns
- 多头持仓 - 空头持仓(正数表示净多,负数表示净空)
◆ getTotalMargin()
| double fix40::Position::getTotalMargin |
( |
| ) |
const |
|
inline |
获取总占用保证金
- Returns
- 多头保证金 + 空头保证金
◆ getTotalPosition()
| int64_t fix40::Position::getTotalPosition |
( |
| ) |
const |
|
inline |
获取总持仓量
- Returns
- 多头持仓 + 空头持仓
◆ getTotalProfit()
| double fix40::Position::getTotalProfit |
( |
| ) |
const |
|
inline |
获取总浮动盈亏
- Returns
- 多头盈亏 + 空头盈亏
◆ hasPosition()
| bool fix40::Position::hasPosition |
( |
| ) |
const |
|
inline |
检查是否有持仓
- Returns
- 如果有任意方向的持仓返回 true
◆ operator!=()
| bool fix40::Position::operator!= |
( |
const Position & |
other | ) |
const |
|
inline |
不等比较操作符
- Parameters
-
- Returns
- 如果任意字段不相等则返回 true
◆ operator==()
| bool fix40::Position::operator== |
( |
const Position & |
other | ) |
const |
|
inline |
相等比较操作符
比较两个持仓的所有字段是否相等(不包括时间戳)。 主要用于属性测试中的 round-trip 验证。
- Parameters
-
- Returns
- 如果所有字段相等则返回 true
- Note
- 此操作符使用精确比较,适用于序列化/反序列化的 round-trip 测试。 如需比较计算结果,请使用带容差的比较方法。
◆ updateProfit()
| void fix40::Position::updateProfit |
( |
double |
lastPrice, |
|
|
int |
volumeMultiple |
|
) |
| |
|
inline |
更新浮动盈亏
根据最新价格重新计算多头和空头的浮动盈亏。
- Parameters
-
| lastPrice | 最新价格 |
| volumeMultiple | 合约乘数 |
- 计算公式
- 多头盈亏 = (最新价 - 多头均价) × 多头持仓量 × 合约乘数
- 空头盈亏 = (空头均价 - 最新价) × 空头持仓量 × 合约乘数
◆ accountId
| std::string fix40::Position::accountId |
◆ instrumentId
| std::string fix40::Position::instrumentId |
◆ longAvgPrice
| double fix40::Position::longAvgPrice |
◆ longMargin
| double fix40::Position::longMargin |
◆ longPosition
| int64_t fix40::Position::longPosition |
◆ longProfit
| double fix40::Position::longProfit |
◆ shortAvgPrice
| double fix40::Position::shortAvgPrice |
◆ shortMargin
| double fix40::Position::shortMargin |
◆ shortPosition
| int64_t fix40::Position::shortPosition |
◆ shortProfit
| double fix40::Position::shortProfit |
◆ updateTime
| std::chrono::system_clock::time_point fix40::Position::updateTime |
The documentation for this struct was generated from the following file: