FIX 4.0 Demo 1.0
Loading...
Searching...
No Matches
account.hpp
Go to the documentation of this file.
1
9#pragma once
10
11#include <string>
12#include <cstdint>
13#include <chrono>
14
15namespace fix40 {
16
17// ============================================================================
18// 账户结构
19// ============================================================================
20
44struct Account {
45 // -------------------------------------------------------------------------
46 // 标识符
47 // -------------------------------------------------------------------------
48 std::string accountId;
49
50 // -------------------------------------------------------------------------
51 // 资金信息
52 // -------------------------------------------------------------------------
53 double balance;
54 double available;
55 double frozenMargin;
56 double usedMargin;
57
58 // -------------------------------------------------------------------------
59 // 盈亏信息
60 // -------------------------------------------------------------------------
62 double closeProfit;
63
64 // -------------------------------------------------------------------------
65 // 时间戳
66 // -------------------------------------------------------------------------
67 std::chrono::system_clock::time_point updateTime;
68
69 // -------------------------------------------------------------------------
70 // 构造函数
71 // -------------------------------------------------------------------------
72
79 : balance(0.0)
80 , available(0.0)
81 , frozenMargin(0.0)
82 , usedMargin(0.0)
83 , positionProfit(0.0)
84 , closeProfit(0.0)
85 , updateTime(std::chrono::system_clock::now())
86 {}
87
96 Account(const std::string& id, double initialBalance)
97 : accountId(id)
98 , balance(initialBalance)
99 , available(initialBalance)
100 , frozenMargin(0.0)
101 , usedMargin(0.0)
102 , positionProfit(0.0)
103 , closeProfit(0.0)
104 , updateTime(std::chrono::system_clock::now())
105 {}
106
107 // -------------------------------------------------------------------------
108 // 计算方法
109 // -------------------------------------------------------------------------
110
119 double getDynamicEquity() const {
120 return balance + positionProfit;
121 }
122
133 double getRiskRatio() const {
134 double equity = getDynamicEquity();
135 return equity > 0 ? usedMargin / equity : 0.0;
136 }
137
147
148 // -------------------------------------------------------------------------
149 // 比较操作符(用于测试)
150 // -------------------------------------------------------------------------
151
164 bool operator==(const Account& other) const {
165 return accountId == other.accountId &&
166 balance == other.balance &&
167 available == other.available &&
168 frozenMargin == other.frozenMargin &&
169 usedMargin == other.usedMargin &&
171 closeProfit == other.closeProfit;
172 }
173
180 bool operator!=(const Account& other) const {
181 return !(*this == other);
182 }
183};
184
185} // namespace fix40
Definition matching_engine.hpp:23
虚拟交易账户
Definition account.hpp:44
bool operator==(const Account &other) const
相等比较操作符
Definition account.hpp:164
std::string accountId
账户ID(唯一标识)
Definition account.hpp:48
double closeProfit
平仓盈亏(已实现盈亏,累计值)
Definition account.hpp:62
double available
可用资金(可用于开仓的资金)
Definition account.hpp:54
double positionProfit
持仓盈亏(浮动盈亏,根据最新价实时计算)
Definition account.hpp:61
double getDynamicEquity() const
计算动态权益
Definition account.hpp:119
Account()
默认构造函数
Definition account.hpp:78
void recalculateAvailable()
重新计算可用资金
Definition account.hpp:144
bool operator!=(const Account &other) const
不等比较操作符
Definition account.hpp:180
double frozenMargin
冻结保证金(挂单占用,尚未成交)
Definition account.hpp:55
double usedMargin
占用保证金(持仓占用,已成交)
Definition account.hpp:56
std::chrono::system_clock::time_point updateTime
最后更新时间
Definition account.hpp:67
double getRiskRatio() const
计算风险度
Definition account.hpp:133
double balance
账户余额(静态权益,初始资金 + 平仓盈亏)
Definition account.hpp:53
Account(const std::string &id, double initialBalance)
带初始余额的构造函数
Definition account.hpp:96