FIX 4.0 Demo 1.0
Loading...
Searching...
No Matches
fix40::RiskManager Class Reference

风险控制模块 More...

#include <risk_manager.hpp>

Collaboration diagram for fix40::RiskManager:
Collaboration graph

Public Member Functions

 RiskManager ()=default
 默认构造函数
 
CheckResult checkOrder (const Order &order, const Account &account, const Position &position, const Instrument &instrument, const MarketDataSnapshot &snapshot, OffsetFlag offsetFlag) const
 订单风控检查
 
CheckResult checkMargin (const Order &order, const Account &account, const Instrument &instrument) const
 检查可用资金是否足够
 
CheckResult checkPrice (const Order &order, const Instrument &instrument) const
 检查价格是否在涨跌停范围内
 
CheckResult checkPosition (const Order &order, const Position &position) const
 检查平仓数量是否超过持仓
 
CheckResult checkCounterParty (const Order &order, const MarketDataSnapshot &snapshot) const
 检查市价单是否有对手盘
 
double calculateRequiredMargin (const Order &order, const Instrument &instrument) const
 计算订单所需保证金
 

Detailed Description

风险控制模块

负责订单提交前的风险检查,包括:

  • 资金检查:验证可用资金是否足够支付保证金
  • 价格检查:验证限价单价格是否在涨跌停范围内
  • 持仓检查:验证平仓数量是否超过持仓
使用示例
RiskManager riskMgr;
order.symbol = "IF2601";
order.price = 4000.0;
order.orderQty = 2;
Account account("user001", 1000000.0);
Position position("user001", "IF2601");
Instrument instrument("IF2601", "CFFEX", "IF", 0.2, 300, 0.12);
instrument.updateLimitPrices(4200.0, 3800.0);
MarketDataSnapshot snapshot("IF2601");
snapshot.askPrice1 = 4000.2;
CheckResult result = riskMgr.checkOrder(order, account, position, instrument, snapshot, OffsetFlag::OPEN);
if (result.passed) {
// 提交到撮合引擎
} else {
// 拒绝订单,返回 result.rejectText
}
风险控制模块
Definition risk_manager.hpp:154
CheckResult checkOrder(const Order &order, const Account &account, const Position &position, const Instrument &instrument, const MarketDataSnapshot &snapshot, OffsetFlag offsetFlag) const
订单风控检查
Definition risk_manager.cpp:17
@ LIMIT
限价单
Order order
Definition simulation_app.cpp:46
虚拟交易账户
Definition account.hpp:44
风控检查结果
Definition risk_manager.hpp:51
bool passed
检查是否通过
Definition risk_manager.hpp:52
合约静态信息
Definition instrument.hpp:48
合约行情快照
Definition market_data_snapshot.hpp:47
内部订单表示
Definition order.hpp:90
std::string symbol
标的代码
Definition order.hpp:101
合约持仓
Definition position.hpp:45
线程安全
所有公共方法都是线程安全的(无状态类)。

Constructor & Destructor Documentation

◆ RiskManager()

fix40::RiskManager::RiskManager ( )
default

默认构造函数

Member Function Documentation

◆ calculateRequiredMargin()

double fix40::RiskManager::calculateRequiredMargin ( const Order order,
const Instrument instrument 
) const

计算订单所需保证金

Parameters
order订单信息
instrument合约信息
Returns
所需保证金金额
Note
市价单使用涨停价(买单)或跌停价(卖单)计算
Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkCounterParty()

CheckResult fix40::RiskManager::checkCounterParty ( const Order order,
const MarketDataSnapshot snapshot 
) const

检查市价单是否有对手盘

验证市价单是否有可成交的对手盘。

Parameters
order订单信息
snapshot行情快照
Returns
检查结果
Note
买单需要有卖盘,卖单需要有买盘
Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkMargin()

CheckResult fix40::RiskManager::checkMargin ( const Order order,
const Account account,
const Instrument instrument 
) const

检查可用资金是否足够

验证账户可用资金是否足够支付开仓所需的保证金。

Parameters
order订单信息
account账户信息
instrument合约信息
Returns
检查结果
计算公式
所需保证金 = 价格 × 数量 × 合约乘数 × 保证金率
Note
市价单使用涨停价(买单)或跌停价(卖单)计算保证金
Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkOrder()

CheckResult fix40::RiskManager::checkOrder ( const Order order,
const Account account,
const Position position,
const Instrument instrument,
const MarketDataSnapshot snapshot,
OffsetFlag  offsetFlag 
) const

订单风控检查

对订单进行完整的风控检查,包括资金、价格、持仓等。

Parameters
order待检查的订单
account账户信息
position持仓信息
instrument合约信息
snapshot行情快照
offsetFlag开平标志
Returns
检查结果
检查顺序
  1. 价格检查(限价单)
  2. 资金检查(开仓)
  3. 持仓检查(平仓)
  4. 对手盘检查(市价单)
Here is the call graph for this function:

◆ checkPosition()

CheckResult fix40::RiskManager::checkPosition ( const Order order,
const Position position 
) const

检查平仓数量是否超过持仓

验证平仓订单的数量是否超过当前持仓数量。

Parameters
order订单信息
position持仓信息
Returns
检查结果
Note
买单平空头持仓,卖单平多头持仓
Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkPrice()

CheckResult fix40::RiskManager::checkPrice ( const Order order,
const Instrument instrument 
) const

检查价格是否在涨跌停范围内

验证限价单的价格是否在当日涨跌停价格范围内。

Parameters
order订单信息
instrument合约信息
Returns
检查结果
Note
市价单不进行价格检查
Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following files: