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

模拟交易应用层 More...

#include <simulation_app.hpp>

Inheritance diagram for fix40::SimulationApp:
Inheritance graph
Collaboration diagram for fix40::SimulationApp:
Collaboration graph

Classes

struct  OrderMarginInfo
 订单保证金信息 More...
 

Public Member Functions

 SimulationApp ()
 默认构造函数(不带持久化)
 
 SimulationApp (IStore *store)
 带存储接口的构造函数
 
 ~SimulationApp () override
 析构函数
 
void start ()
 启动撮合引擎
 
void stop ()
 停止撮合引擎
 
void onLogon (const SessionID &sessionID) override
 会话登录成功回调
 
void onLogout (const SessionID &sessionID) override
 会话登出回调
 
void fromApp (const FixMessage &msg, const SessionID &sessionID) override
 收到业务消息回调
 
void toApp (FixMessage &msg, const SessionID &sessionID) override
 发送业务消息前回调
 
SessionManagergetSessionManager ()
 获取会话管理器
 
IStoregetStore () const override
 获取存储接口
 
AccountManagergetAccountManager ()
 获取账户管理器
 
PositionManagergetPositionManager ()
 获取持仓管理器
 
InstrumentManagergetInstrumentManager ()
 获取合约管理器
 
RiskManagergetRiskManager ()
 获取风控管理器
 
MatchingEnginegetMatchingEngine ()
 获取撮合引擎
 
Account getOrCreateAccount (const std::string &accountId, double initialBalance=1000000.0)
 创建或获取账户
 
- Public Member Functions inherited from fix40::Application
virtual ~Application ()=default
 虚析构函数
 
virtual void fromAdmin (const FixMessage &msg, const SessionID &sessionID)
 收到管理消息回调
 
virtual void toAdmin (FixMessage &msg, const SessionID &sessionID)
 发送管理消息前回调
 

Friends

struct SimulationAppTestAccess
 单元测试访问器
 

Detailed Description

模拟交易应用层

实现 Application 接口,采用生产者-消费者模式处理业务消息:

  • fromApp() 将消息封装为事件,push 到无锁队列(生产者)
  • MatchingEngine 在独立线程中消费并处理事件(消费者)

这种设计确保:

  • Application 回调快速返回,不阻塞工作线程
  • 所有订单处理在单线程中串行执行,无需加锁
  • 异常隔离:撮合引擎的异常不会影响网络层
集成模块
支持的消息类型
  • D: NewOrderSingle (新订单)
  • F: OrderCancelRequest (撤单请求)
  • G: OrderCancelReplaceRequest (改单请求)
使用示例
IStore* store = ...; // 存储接口
SimulationApp app(store);
// 加载合约配置
app.getInstrumentManager().loadFromConfig("config/instruments.json");
app.start(); // 启动撮合引擎
session->set_application(&app);
// 关闭时
app.stop();
存储接口
Definition store.hpp:61
模拟交易应用层
Definition simulation_app.hpp:87

Constructor & Destructor Documentation

◆ SimulationApp() [1/2]

fix40::SimulationApp::SimulationApp ( )

默认构造函数(不带持久化)

◆ SimulationApp() [2/2]

fix40::SimulationApp::SimulationApp ( IStore store)
explicit

带存储接口的构造函数

Parameters
store存储接口指针,用于账户和持仓的持久化

◆ ~SimulationApp()

fix40::SimulationApp::~SimulationApp ( )
override

析构函数

自动停止撮合引擎。

Here is the call graph for this function:

Member Function Documentation

◆ fromApp()

void fix40::SimulationApp::fromApp ( const FixMessage msg,
const SessionID sessionID 
)
overridevirtual

收到业务消息回调

Parameters
msg收到的 FIX 业务消息
sessionID消息来源的会话标识符

将消息封装为事件,提交到撮合引擎队列。 此方法只做轻量的入队操作,快速返回。

Implements fix40::Application.

Here is the call graph for this function:

◆ getAccountManager()

AccountManager & fix40::SimulationApp::getAccountManager ( )
inline

获取账户管理器

Returns
AccountManager& 账户管理器引用

◆ getInstrumentManager()

InstrumentManager & fix40::SimulationApp::getInstrumentManager ( )
inline

获取合约管理器

Returns
InstrumentManager& 合约管理器引用
Here is the caller graph for this function:

◆ getMatchingEngine()

MatchingEngine & fix40::SimulationApp::getMatchingEngine ( )
inline

获取撮合引擎

Returns
MatchingEngine& 撮合引擎引用
Here is the caller graph for this function:

◆ getOrCreateAccount()

Account fix40::SimulationApp::getOrCreateAccount ( const std::string &  accountId,
double  initialBalance = 1000000.0 
)

创建或获取账户

如果账户不存在,创建一个新账户;否则返回现有账户。

Parameters
accountId账户ID
initialBalance初始余额(仅在创建时使用)
Returns
Account 账户信息
Here is the call graph for this function:

◆ getPositionManager()

PositionManager & fix40::SimulationApp::getPositionManager ( )
inline

获取持仓管理器

Returns
PositionManager& 持仓管理器引用

◆ getRiskManager()

RiskManager & fix40::SimulationApp::getRiskManager ( )
inline

获取风控管理器

Returns
RiskManager& 风控管理器引用

◆ getSessionManager()

SessionManager & fix40::SimulationApp::getSessionManager ( )
inline

获取会话管理器

Returns
SessionManager& 会话管理器引用

返回内部会话管理器的引用,调用者可通过该引用调用 registerSession()/unregisterSession() 等方法管理会话。

◆ getStore()

IStore * fix40::SimulationApp::getStore ( ) const
inlineoverridevirtual

获取存储接口

Returns
IStore* 存储接口指针,可能为 nullptr

该指针用于账户/持仓等数据的持久化与重启恢复。

Reimplemented from fix40::Application.

◆ onLogon()

void fix40::SimulationApp::onLogon ( const SessionID sessionID)
overridevirtual

会话登录成功回调

Parameters
sessionID已建立的会话标识符

将登录事件提交到撮合引擎队列。

Implements fix40::Application.

Here is the call graph for this function:

◆ onLogout()

void fix40::SimulationApp::onLogout ( const SessionID sessionID)
overridevirtual

会话登出回调

Parameters
sessionID即将断开的会话标识符

将登出事件提交到撮合引擎队列。

Implements fix40::Application.

Here is the call graph for this function:

◆ start()

void fix40::SimulationApp::start ( )

启动撮合引擎

必须在处理消息前调用。

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stop()

void fix40::SimulationApp::stop ( )

停止撮合引擎

等待当前处理完成后退出。

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toApp()

void fix40::SimulationApp::toApp ( FixMessage msg,
const SessionID sessionID 
)
overridevirtual

发送业务消息前回调

Parameters
msg即将发送的 FIX 业务消息
sessionID发送消息的会话标识符

用于记录审计日志。

Reimplemented from fix40::Application.

Here is the call graph for this function:

Friends And Related Symbol Documentation

◆ SimulationAppTestAccess

friend struct SimulationAppTestAccess
friend

单元测试访问器

仅用于单元测试访问内部实现细节(例如 pushAccountUpdate),避免在测试中使用 #define private public 破坏标准库头文件的可见性/封装并导致编译失败。


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