FIX 4.0 Demo 1.0
Loading...
Searching...
No Matches
fix40::Position Struct Reference

合约持仓 More...

#include <position.hpp>

Collaboration diagram for fix40::Position:
Collaboration graph

Public Member Functions

 Position ()
 默认构造函数
 
 Position (const std::string &accId, const std::string &instId)
 带标识符的构造函数
 
void updateProfit (double lastPrice, int volumeMultiple)
 更新浮动盈亏
 
double getTotalProfit () const
 获取总浮动盈亏
 
int64_t getTotalPosition () const
 获取总持仓量
 
double getTotalMargin () const
 获取总占用保证金
 
bool hasPosition () const
 检查是否有持仓
 
int64_t getNetPosition () const
 获取净持仓
 
bool operator== (const Position &other) const
 相等比较操作符
 
bool operator!= (const Position &other) const
 不等比较操作符
 

Public Attributes

std::string accountId
 账户ID
 
std::string instrumentId
 合约代码(如 "IF2601")
 
int64_t longPosition
 多头持仓量(手数)
 
double longAvgPrice
 多头持仓均价
 
double longProfit
 多头浮动盈亏
 
double longMargin
 多头占用保证金
 
int64_t shortPosition
 空头持仓量(手数)
 
double shortAvgPrice
 空头持仓均价
 
double shortProfit
 空头浮动盈亏
 
double shortMargin
 空头占用保证金
 
std::chrono::system_clock::time_point updateTime
 最后更新时间
 

Detailed Description

合约持仓

用户在某个合约上的持仓信息,分为多头和空头两个方向。 系统通过此结构追踪用户的头寸和盈亏状态。

盈亏计算
  • 多头浮动盈亏 = (最新价 - 多头均价) × 多头持仓量 × 合约乘数
  • 空头浮动盈亏 = (空头均价 - 最新价) × 空头持仓量 × 合约乘数
使用示例
pos.accountId = "user001";
pos.instrumentId = "IF2601";
pos.longPosition = 2;
pos.longAvgPrice = 4000.0;
// 更新浮动盈亏(假设最新价4050,合约乘数300)
pos.updateProfit(4050.0, 300);
// 多头盈亏 = (4050 - 4000) * 2 * 300 = 30000
合约持仓
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

Constructor & Destructor Documentation

◆ Position() [1/2]

fix40::Position::Position ( )
inline

默认构造函数

初始化所有数值字段为 0,时间戳为当前时间。

◆ Position() [2/2]

fix40::Position::Position ( const std::string &  accId,
const std::string &  instId 
)
inline

带标识符的构造函数

Parameters
accId账户ID
instId合约代码

Member Function Documentation

◆ 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
多头盈亏 + 空头盈亏
Here is the caller graph for this function:

◆ hasPosition()

bool fix40::Position::hasPosition ( ) const
inline

检查是否有持仓

Returns
如果有任意方向的持仓返回 true

◆ operator!=()

bool fix40::Position::operator!= ( const Position other) const
inline

不等比较操作符

Parameters
other另一个持仓
Returns
如果任意字段不相等则返回 true

◆ operator==()

bool fix40::Position::operator== ( const Position other) const
inline

相等比较操作符

比较两个持仓的所有字段是否相等(不包括时间戳)。 主要用于属性测试中的 round-trip 验证。

Parameters
other另一个持仓
Returns
如果所有字段相等则返回 true
Note
此操作符使用精确比较,适用于序列化/反序列化的 round-trip 测试。 如需比较计算结果,请使用带容差的比较方法。

◆ updateProfit()

void fix40::Position::updateProfit ( double  lastPrice,
int  volumeMultiple 
)
inline

更新浮动盈亏

根据最新价格重新计算多头和空头的浮动盈亏。

Parameters
lastPrice最新价格
volumeMultiple合约乘数
计算公式
  • 多头盈亏 = (最新价 - 多头均价) × 多头持仓量 × 合约乘数
  • 空头盈亏 = (空头均价 - 最新价) × 空头持仓量 × 合约乘数
Here is the caller graph for this function:

Member Data Documentation

◆ accountId

std::string fix40::Position::accountId

账户ID

◆ instrumentId

std::string fix40::Position::instrumentId

合约代码(如 "IF2601")

◆ 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: