客户端 FIX Application
More...
#include <client_app.hpp>
|
| | ClientApp (std::shared_ptr< ClientState > state, const std::string &userId) |
| | 构造函数
|
| |
| | ~ClientApp () override=default |
| |
| 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 |
| | 发送业务消息前回调
|
| |
| void | setSession (std::shared_ptr< Session > session) |
| | 设置 Session
|
| |
| std::string | sendNewOrder (const std::string &symbol, const std::string &side, int64_t qty, double price, const std::string &ordType="2") |
| | 发送新订单
|
| |
| void | sendCancelOrder (const std::string &origClOrdID, const std::string &symbol, const std::string &side) |
| | 发送撤单请求
|
| |
| void | queryBalance () |
| | 查询资金
|
| |
| void | queryPositions () |
| | 查询持仓
|
| |
| void | queryOrderHistory () |
| | 查询订单历史(服务端持久化)
|
| |
| void | searchInstruments (const std::string &pattern, int maxResults=10) |
| | 搜索合约
|
| |
| const std::string & | getUserId () const |
| | 获取用户ID
|
| |
| virtual | ~Application ()=default |
| | 虚析构函数
|
| |
| virtual void | fromAdmin (const FixMessage &msg, const SessionID &sessionID) |
| | 收到管理消息回调
|
| |
| virtual void | toAdmin (FixMessage &msg, const SessionID &sessionID) |
| | 发送管理消息前回调
|
| |
| virtual IStore * | getStore () const |
| | 获取持久化存储接口(可选)
|
| |
客户端 FIX Application
实现 Application 接口,处理:
- 登录/登出
- 执行报告 (8)
- 资金查询响应 (U2)
- 持仓查询响应 (U4)
- 账户推送 (U5)
- 持仓推送 (U6)
- 合约搜索响应 (U8)
- 订单历史查询响应 (U10)
◆ ClientApp()
| fix40::client::ClientApp::ClientApp |
( |
std::shared_ptr< ClientState > |
state, |
|
|
const std::string & |
userId |
|
) |
| |
构造函数
- Parameters
-
| state | 客户端状态管理器 |
| userId | 用户ID(作为 SenderCompID) |
◆ ~ClientApp()
| fix40::client::ClientApp::~ClientApp |
( |
| ) |
|
|
overridedefault |
◆ fromApp()
收到业务消息回调
- Parameters
-
| msg | 收到的 FIX 业务消息 |
| sessionID | 消息来源的会话标识符 |
当收到非会话层消息(MsgType 不是 A/0/1/5)时调用。 典型的业务消息包括:
- D: NewOrderSingle(新订单)
- F: OrderCancelRequest(撤单请求)
- 8: ExecutionReport(执行报告)
- Warning
- 可能被多个工作线程并发调用! 推荐实现:只做轻量操作,将消息 push 到无锁队列
Implements fix40::Application.
◆ getUserId()
| const std::string & fix40::client::ClientApp::getUserId |
( |
| ) |
const |
|
inline |
◆ onLogon()
| void fix40::client::ClientApp::onLogon |
( |
const SessionID & |
sessionID | ) |
|
|
overridevirtual |
会话登录成功回调
- Parameters
-
当 FIX 会话成功建立(收到 Logon 确认)后调用。 可用于初始化交易状态、订阅行情等。
- Note
- 可能被多个工作线程并发调用
Implements fix40::Application.
◆ onLogout()
| void fix40::client::ClientApp::onLogout |
( |
const SessionID & |
sessionID | ) |
|
|
overridevirtual |
会话登出回调
- Parameters
-
当 FIX 会话即将断开(收到 Logout 或连接关闭)时调用。 可用于清理交易状态、取消未完成订单等。
- Note
- 可能被多个工作线程并发调用
Implements fix40::Application.
◆ queryBalance()
| void fix40::client::ClientApp::queryBalance |
( |
| ) |
|
◆ queryOrderHistory()
| void fix40::client::ClientApp::queryOrderHistory |
( |
| ) |
|
查询订单历史(服务端持久化)
发送 U9 请求,服务端返回 U10 响应(Text 字段为序列化订单列表)。
◆ queryPositions()
| void fix40::client::ClientApp::queryPositions |
( |
| ) |
|
◆ searchInstruments()
| void fix40::client::ClientApp::searchInstruments |
( |
const std::string & |
pattern, |
|
|
int |
maxResults = 10 |
|
) |
| |
搜索合约
- Parameters
-
| pattern | 搜索前缀 |
| maxResults | 最大返回数量 |
◆ sendCancelOrder()
| void fix40::client::ClientApp::sendCancelOrder |
( |
const std::string & |
origClOrdID, |
|
|
const std::string & |
symbol, |
|
|
const std::string & |
side |
|
) |
| |
发送撤单请求
- Parameters
-
| origClOrdID | 原订单ID |
| symbol | 合约代码 |
| side | 买卖方向 |
◆ sendNewOrder()
| std::string fix40::client::ClientApp::sendNewOrder |
( |
const std::string & |
symbol, |
|
|
const std::string & |
side, |
|
|
int64_t |
qty, |
|
|
double |
price, |
|
|
const std::string & |
ordType = "2" |
|
) |
| |
发送新订单
- Parameters
-
| symbol | 合约代码 |
| side | "1"=买, "2"=卖 |
| qty | 数量 |
| price | 价格(限价单) |
| ordType | "1"=市价, "2"=限价 |
- Returns
- 客户端订单ID
◆ setSession()
| void fix40::client::ClientApp::setSession |
( |
std::shared_ptr< Session > |
session | ) |
|
◆ toApp()
发送业务消息前回调
- Parameters
-
| msg | 即将发送的 FIX 业务消息(可修改) |
| sessionID | 发送消息的会话标识符 |
在业务消息发送前调用,可用于:
默认实现为空,子类可选择性重写。
- Note
- 可能被多个工作线程并发调用
Reimplemented from fix40::Application.
The documentation for this class was generated from the following files: