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

虚拟交易账户 More...

#include <account.hpp>

Collaboration diagram for fix40::Account:
Collaboration graph

Public Member Functions

 Account ()
 默认构造函数
 
 Account (const std::string &id, double initialBalance)
 带初始余额的构造函数
 
double getDynamicEquity () const
 计算动态权益
 
double getRiskRatio () const
 计算风险度
 
void recalculateAvailable ()
 重新计算可用资金
 
bool operator== (const Account &other) const
 相等比较操作符
 
bool operator!= (const Account &other) const
 不等比较操作符
 

Public Attributes

std::string accountId
 账户ID(唯一标识)
 
double balance
 账户余额(静态权益,初始资金 + 平仓盈亏)
 
double available
 可用资金(可用于开仓的资金)
 
double frozenMargin
 冻结保证金(挂单占用,尚未成交)
 
double usedMargin
 占用保证金(持仓占用,已成交)
 
double positionProfit
 持仓盈亏(浮动盈亏,根据最新价实时计算)
 
double closeProfit
 平仓盈亏(已实现盈亏,累计值)
 
std::chrono::system_clock::time_point updateTime
 最后更新时间
 

Detailed Description

虚拟交易账户

用户的虚拟资金账户,包含余额、可用资金、冻结保证金等信息。 系统通过此结构追踪用户的资金状态和交易表现。

资金关系
  • 可用资金 = 余额 + 持仓盈亏 - 冻结保证金 - 占用保证金
  • 动态权益 = 余额 + 持仓盈亏
  • 风险度 = 占用保证金 / 动态权益
使用示例
Account account;
account.accountId = "user001";
account.balance = 1000000.0;
account.available = 1000000.0;
double equity = account.getDynamicEquity();
double risk = account.getRiskRatio();
虚拟交易账户
Definition account.hpp:44
std::string accountId
账户ID(唯一标识)
Definition account.hpp:48
double available
可用资金(可用于开仓的资金)
Definition account.hpp:54
double getDynamicEquity() const
计算动态权益
Definition account.hpp:119
double getRiskRatio() const
计算风险度
Definition account.hpp:133
double balance
账户余额(静态权益,初始资金 + 平仓盈亏)
Definition account.hpp:53

Constructor & Destructor Documentation

◆ Account() [1/2]

fix40::Account::Account ( )
inline

默认构造函数

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

◆ Account() [2/2]

fix40::Account::Account ( const std::string &  id,
double  initialBalance 
)
inline

带初始余额的构造函数

Parameters
id账户ID
initialBalance初始余额(同时初始化余额和可用资金)
Note
新账户的可用资金等于初始余额,因为没有冻结或占用的保证金

Member Function Documentation

◆ getDynamicEquity()

double fix40::Account::getDynamicEquity ( ) const
inline

计算动态权益

动态权益 = 余额 + 持仓盈亏 反映账户的实时价值,包含未实现的浮动盈亏。

Returns
动态权益值
Here is the caller graph for this function:

◆ getRiskRatio()

double fix40::Account::getRiskRatio ( ) const
inline

计算风险度

风险度 = 占用保证金 / 动态权益 用于评估账户的风险水平,值越高风险越大。

Returns
风险度(0.0 ~ 1.0+),动态权益为0或负时返回0
Note
当动态权益 <= 0 时返回 0,避免除零错误和负值风险度
Here is the call graph for this function:

◆ operator!=()

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

不等比较操作符

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

◆ operator==()

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

相等比较操作符

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

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

◆ recalculateAvailable()

void fix40::Account::recalculateAvailable ( )
inline

重新计算可用资金

可用资金 = 余额 + 持仓盈亏 - 冻结保证金 - 占用保证金 在资金状态变化后调用此方法更新可用资金。

Member Data Documentation

◆ accountId

std::string fix40::Account::accountId

账户ID(唯一标识)

◆ available

double fix40::Account::available

可用资金(可用于开仓的资金)

◆ balance

double fix40::Account::balance

账户余额(静态权益,初始资金 + 平仓盈亏)

◆ closeProfit

double fix40::Account::closeProfit

平仓盈亏(已实现盈亏,累计值)

◆ frozenMargin

double fix40::Account::frozenMargin

冻结保证金(挂单占用,尚未成交)

◆ positionProfit

double fix40::Account::positionProfit

持仓盈亏(浮动盈亏,根据最新价实时计算)

◆ updateTime

std::chrono::system_clock::time_point fix40::Account::updateTime

最后更新时间

◆ usedMargin

double fix40::Account::usedMargin

占用保证金(持仓占用,已成交)


The documentation for this struct was generated from the following file: