模拟交易应用层
More...
#include <simulation_app.hpp>
模拟交易应用层
实现 Application 接口,采用生产者-消费者模式处理业务消息:
这种设计确保:
- Application 回调快速返回,不阻塞工作线程
- 所有订单处理在单线程中串行执行,无需加锁
- 异常隔离:撮合引擎的异常不会影响网络层
- 集成模块
-
- 支持的消息类型
- D: NewOrderSingle (新订单)
- F: OrderCancelRequest (撤单请求)
- G: OrderCancelReplaceRequest (改单请求)
- 使用示例
app.getInstrumentManager().loadFromConfig("config/instruments.json");
app.start();
session->set_application(&app);
app.stop();
存储接口
Definition store.hpp:61
模拟交易应用层
Definition simulation_app.hpp:87
◆ SimulationApp() [1/2]
| fix40::SimulationApp::SimulationApp |
( |
| ) |
|
◆ SimulationApp() [2/2]
| fix40::SimulationApp::SimulationApp |
( |
IStore * |
store | ) |
|
|
explicit |
◆ ~SimulationApp()
| fix40::SimulationApp::~SimulationApp |
( |
| ) |
|
|
override |
◆ fromApp()
收到业务消息回调
- Parameters
-
| msg | 收到的 FIX 业务消息 |
| sessionID | 消息来源的会话标识符 |
将消息封装为事件,提交到撮合引擎队列。 此方法只做轻量的入队操作,快速返回。
Implements fix40::Application.
◆ getAccountManager()
◆ getInstrumentManager()
◆ getMatchingEngine()
◆ getOrCreateAccount()
| Account fix40::SimulationApp::getOrCreateAccount |
( |
const std::string & |
accountId, |
|
|
double |
initialBalance = 1000000.0 |
|
) |
| |
创建或获取账户
如果账户不存在,创建一个新账户;否则返回现有账户。
- Parameters
-
| accountId | 账户ID |
| initialBalance | 初始余额(仅在创建时使用) |
- Returns
- Account 账户信息
◆ getPositionManager()
◆ getRiskManager()
◆ getSessionManager()
获取会话管理器
- 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 |
◆ onLogout()
| void fix40::SimulationApp::onLogout |
( |
const SessionID & |
sessionID | ) |
|
|
overridevirtual |
◆ start()
| void fix40::SimulationApp::start |
( |
| ) |
|
◆ stop()
| void fix40::SimulationApp::stop |
( |
| ) |
|
◆ toApp()
发送业务消息前回调
- Parameters
-
| msg | 即将发送的 FIX 业务消息 |
| sessionID | 发送消息的会话标识符 |
用于记录审计日志。
Reimplemented from fix40::Application.
◆ SimulationAppTestAccess
| friend struct SimulationAppTestAccess |
|
friend |
单元测试访问器
仅用于单元测试访问内部实现细节(例如 pushAccountUpdate),避免在测试中使用 #define private public 破坏标准库头文件的可见性/封装并导致编译失败。
The documentation for this class was generated from the following files: