虚拟交易账户
More...
#include <account.hpp>
虚拟交易账户
用户的虚拟资金账户,包含余额、可用资金、冻结保证金等信息。 系统通过此结构追踪用户的资金状态和交易表现。
- 资金关系
- 可用资金 = 余额 + 持仓盈亏 - 冻结保证金 - 占用保证金
- 动态权益 = 余额 + 持仓盈亏
- 风险度 = 占用保证金 / 动态权益
- 使用示例
虚拟交易账户
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
◆ 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
- 新账户的可用资金等于初始余额,因为没有冻结或占用的保证金
◆ getDynamicEquity()
| double fix40::Account::getDynamicEquity |
( |
| ) |
const |
|
inline |
计算动态权益
动态权益 = 余额 + 持仓盈亏 反映账户的实时价值,包含未实现的浮动盈亏。
- Returns
- 动态权益值
◆ getRiskRatio()
| double fix40::Account::getRiskRatio |
( |
| ) |
const |
|
inline |
计算风险度
风险度 = 占用保证金 / 动态权益 用于评估账户的风险水平,值越高风险越大。
- Returns
- 风险度(0.0 ~ 1.0+),动态权益为0或负时返回0
- Note
- 当动态权益 <= 0 时返回 0,避免除零错误和负值风险度
◆ operator!=()
| bool fix40::Account::operator!= |
( |
const Account & |
other | ) |
const |
|
inline |
不等比较操作符
- Parameters
-
- Returns
- 如果任意字段不相等则返回 true
◆ operator==()
| bool fix40::Account::operator== |
( |
const Account & |
other | ) |
const |
|
inline |
相等比较操作符
比较两个账户的所有字段是否相等(不包括时间戳)。 主要用于属性测试中的 round-trip 验证。
- Parameters
-
- Returns
- 如果所有字段相等则返回 true
- Note
- 此操作符使用精确比较,适用于序列化/反序列化的 round-trip 测试。 如需比较计算结果,请使用带容差的比较方法。
◆ recalculateAvailable()
| void fix40::Account::recalculateAvailable |
( |
| ) |
|
|
inline |
重新计算可用资金
可用资金 = 余额 + 持仓盈亏 - 冻结保证金 - 占用保证金 在资金状态变化后调用此方法更新可用资金。
◆ accountId
| std::string fix40::Account::accountId |
◆ 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: