FIX 4.0 Demo 1.0
Loading...
Searching...
No Matches
fix40 Namespace Reference

Namespaces

namespace  client
 
namespace  tags
 

Classes

struct  Account
 虚拟交易账户 More...
 
class  AccountManager
 账户管理器 More...
 
class  Application
 FIX 应用层抽象接口 More...
 
struct  CancelRequest
 撤单请求 More...
 
struct  CheckResult
 风控检查结果 More...
 
class  Client
 FIX 协议客户端 More...
 
class  Config
 线程安全的 INI 配置文件解析器(单例模式) More...
 
class  Connection
 TCP 连接管理类 More...
 
class  DisconnectedState
 断开连接状态 More...
 
class  EstablishedState
 会话已建立状态 More...
 
struct  ExecutionReport
 执行报告 More...
 
class  FixCodec
 FIX 消息编解码器 More...
 
class  FixFrameDecoder
 FIX 消息帧解码器 More...
 
class  FixMessage
 FIX 消息的面向对象封装 More...
 
class  FixServer
 FIX 协议服务端 More...
 
struct  Instrument
 合约静态信息 More...
 
class  InstrumentManager
 合约信息管理器 More...
 
class  IStateHandler
 会话状态处理器接口(状态模式) More...
 
class  IStore
 存储接口 More...
 
class  Logger
 线程安全的日志输出器(单例模式) More...
 
class  LogonSentState
 已发送 Logon 状态(客户端) More...
 
class  LogoutSentState
 已发送 Logout 状态 More...
 
struct  MarketData
 行情数据结构体 More...
 
struct  MarketDataSnapshot
 合约行情快照 More...
 
class  MatchingEngine
 行情驱动撮合引擎 More...
 
class  MdAdapter
 行情适配器抽象接口 More...
 
class  MockMdAdapter
 模拟行情适配器 More...
 
struct  Order
 内部订单表示 More...
 
class  OrderBook
 订单簿 More...
 
struct  OrderEvent
 订单事件 More...
 
struct  Position
 合约持仓 More...
 
class  PositionManager
 持仓管理器 More...
 
struct  PriceLevel
 价格档位 More...
 
class  Reactor
 基于 Reactor 模式的事件循环 More...
 
class  RiskManager
 风险控制模块 More...
 
class  Session
 FIX 会话管理器 More...
 
struct  SessionID
 FIX 会话标识符 More...
 
struct  SessionIDHash
 SessionID 的哈希函数 More...
 
class  SessionManager
 FIX 会话管理器 More...
 
struct  SessionState
 会话状态 (用于断线恢复) More...
 
class  SimulationApp
 模拟交易应用层 More...
 
class  SqliteStore
 SQLite 存储实现 More...
 
struct  StoredMessage
 存储的消息 (用于重传) More...
 
struct  StoredTrade
 存储用成交记录 More...
 
class  ThreadPool
 支持"连接绑定线程"的线程池 More...
 
class  TimingWheel
 支持周期性任务的时间轮定时器 More...
 
struct  Trade
 成交记录 More...
 

Typedefs

using ExecutionReportCallback = std::function< void(const SessionID &, const ExecutionReport &)>
 ExecutionReport 回调类型
 
using MarketDataUpdateCallback = std::function< void(const std::string &, double)>
 行情更新回调类型
 
using TimerTask = std::function< void()>
 定时任务回调函数类型
 
using TimerTaskId = uint64_t
 定时任务唯一标识符类型
 
using StateCallback = std::function< void(MdAdapterState state, const std::string &message)>
 状态变更回调类型
 

Enumerations

enum class  OrderEventType { NEW_ORDER , CANCEL_REQUEST , SESSION_LOGON , SESSION_LOGOUT }
 订单事件类型 More...
 
enum class  RejectReason {
  NONE = 0 , INSTRUMENT_NOT_FOUND = 1 , INSUFFICIENT_FUNDS = 2 , PRICE_OUT_OF_LIMIT = 3 ,
  INSUFFICIENT_POSITION = 4 , NO_COUNTER_PARTY = 5 , ORDER_NOT_FOUND = 6
}
 订单拒绝原因代码 More...
 
enum class  OffsetFlag { OPEN = 0 , CLOSE = 1 }
 开平标志 More...
 
enum class  OrderSide { BUY = 1 , SELL = 2 }
 买卖方向 More...
 
enum class  OrderType { MARKET = 1 , LIMIT = 2 }
 订单类型 More...
 
enum class  TimeInForce { DAY = 0 , GTC = 1 , IOC = 3 , FOK = 4 }
 订单有效期 More...
 
enum class  OrderStatus {
  NEW = 0 , PARTIALLY_FILLED = 1 , FILLED = 2 , CANCELED = 4 ,
  REJECTED = 8 , PENDING_NEW = 10 , PENDING_CANCEL = 6
}
 订单状态 More...
 
enum class  ExecTransType { NEW = 0 , CANCEL = 1 , CORRECT = 2 , STATUS = 3 }
 执行事务类型 (FIX 4.0) More...
 
enum class  EventType : uint32_t { READ = 1 , WRITE = 2 }
 I/O 事件类型 More...
 
enum class  MdAdapterState {
  DISCONNECTED , CONNECTING , CONNECTED , LOGGING_IN ,
  READY , ERROR
}
 行情适配器状态 More...
 

Functions

std::string formatTransactTime (std::chrono::system_clock::time_point tp)
 格式化 UTC 时间为 FIX 格式
 
std::string sideToFix (OrderSide side)
 将 OrderSide 转换为 FIX 字符串
 
std::string ordTypeToFix (OrderType type)
 将 OrderType 转换为 FIX 字符串
 
std::string ordStatusToFix (OrderStatus status)
 将 OrderStatus 转换为 FIX 字符串
 
std::string execTransTypeToFix (ExecTransType type)
 将 ExecTransType 转换为 FIX 字符串
 
FixMessage buildExecutionReport (const ExecutionReport &report)
 ExecutionReport 转换为 FIX 消息
 
FixMessage create_logon_message (const std::string &sender, const std::string &target, int seq_num=1, int heart_bt=Config::instance().get_int("fix_session", "default_heartbeat_interval", 30), bool reset_seq_num=false)
 创建 Logon 消息
 
FixMessage create_heartbeat_message (const std::string &sender, const std::string &target, int seq_num, const std::string &test_req_id="")
 创建 Heartbeat 消息
 
FixMessage create_test_request_message (const std::string &sender, const std::string &target, int seq_num, const std::string &test_req_id)
 创建 TestRequest 消息
 
FixMessage create_logout_message (const std::string &sender, const std::string &target, int seq_num, const std::string &text="")
 创建 Logout 消息
 
FixMessage create_resend_request_message (const std::string &sender, const std::string &target, int seq_num, int begin_seq_no, int end_seq_no)
 创建 ResendRequest 消息
 
FixMessage create_sequence_reset_message (const std::string &sender, const std::string &target, int seq_num, int new_seq_no, bool gap_fill=true)
 创建 SequenceReset 消息
 
bool is_admin_message (const std::string &msg_type)
 判断消息类型是否为管理消息
 
ExecutionReport buildRejectReport (const Order &order, RejectReason reason, const std::string &text)
 

Variables

constexpr int MAX_SAFE_DELAY_MS = INT_MAX / 1000
 最大安全延迟时间(毫秒),防止整数溢出
 
constexpr TimerTaskId INVALID_TIMER_ID = 0
 无效的定时任务 ID
 
constexpr char SOH = '\x01'
 FIX 字段分隔符:ASCII SOH (0x01)
 
constexpr size_t INSTRUMENT_ID_LEN = 32
 合约代码最大长度
 
constexpr size_t EXCHANGE_ID_LEN = 16
 交易所代码最大长度
 
constexpr size_t DATE_LEN = 9
 日期字符串长度 (YYYYMMDD)
 
constexpr size_t TIME_LEN = 9
 时间字符串长度 (HH:MM:SS)
 

Typedef Documentation

◆ ExecutionReportCallback

using fix40::ExecutionReportCallback = typedef std::function<void(const SessionID&, const ExecutionReport&)>

ExecutionReport 回调类型

当撮合引擎产生执行报告时调用此回调。 参数:sessionID - 目标会话,report - 执行报告

◆ MarketDataUpdateCallback

using fix40::MarketDataUpdateCallback = typedef std::function<void(const std::string&, double)>

行情更新回调类型

当行情数据更新时调用此回调,用于触发账户价值重算。 参数:instrumentId - 合约代码,lastPrice - 最新价

◆ StateCallback

using fix40::StateCallback = typedef std::function<void(MdAdapterState state, const std::string& message)>

状态变更回调类型

Parameters
state新状态
message状态描述信息

◆ TimerTask

using fix40::TimerTask = typedef std::function<void()>

定时任务回调函数类型

◆ TimerTaskId

using fix40::TimerTaskId = typedef uint64_t

定时任务唯一标识符类型

Enumeration Type Documentation

◆ EventType

enum class fix40::EventType : uint32_t
strong

I/O 事件类型

Enumerator
READ 

可读事件

WRITE 

可写事件

◆ ExecTransType

enum class fix40::ExecTransType
strong

执行事务类型 (FIX 4.0)

Enumerator
NEW 

新执行报告

CANCEL 

取消之前的执行报告

CORRECT 

更正之前的执行报告

STATUS 

状态查询响应

◆ MdAdapterState

enum class fix40::MdAdapterState
strong

行情适配器状态

Enumerator
DISCONNECTED 

未连接

CONNECTING 

连接中

CONNECTED 

已连接(未登录)

LOGGING_IN 

登录中

READY 

就绪(已登录,可订阅)

ERROR 

错误状态

◆ OffsetFlag

enum class fix40::OffsetFlag
strong

开平标志

用于区分开仓和平仓订单。

Enumerator
OPEN 

开仓

CLOSE 

平仓

◆ OrderEventType

enum class fix40::OrderEventType
strong

订单事件类型

Enumerator
NEW_ORDER 

新订单

CANCEL_REQUEST 

撤单请求

SESSION_LOGON 

会话登录

SESSION_LOGOUT 

会话登出

◆ OrderSide

enum class fix40::OrderSide
strong

买卖方向

Enumerator
BUY 

买入

SELL 

卖出

◆ OrderStatus

enum class fix40::OrderStatus
strong

订单状态

Note
枚举值与 FIX 协议 OrdStatus(39) 标准定义保持一致, 数值不连续是故意的,便于与协议对照和日志分析。
Enumerator
NEW 

新订单(已接受)

PARTIALLY_FILLED 

部分成交

FILLED 

全部成交

CANCELED 

已撤销

REJECTED 

已拒绝

PENDING_NEW 

待确认(内部状态)

PENDING_CANCEL 

待撤销(内部状态)

◆ OrderType

enum class fix40::OrderType
strong

订单类型

Enumerator
MARKET 

市价单

LIMIT 

限价单

◆ RejectReason

enum class fix40::RejectReason
strong

订单拒绝原因代码

定义风控检查失败时的拒绝原因代码,与设计文档中的错误处理表对应。

Enumerator
NONE 

无错误(检查通过)

INSTRUMENT_NOT_FOUND 

合约不存在

INSUFFICIENT_FUNDS 

资金不足

PRICE_OUT_OF_LIMIT 

价格超限(超出涨跌停)

INSUFFICIENT_POSITION 

持仓不足(平仓数量超过持仓)

NO_COUNTER_PARTY 

无对手盘(市价单)

ORDER_NOT_FOUND 

订单不存在(撤单时)

◆ TimeInForce

enum class fix40::TimeInForce
strong

订单有效期

Enumerator
DAY 

当日有效

GTC 

撤销前有效 (Good Till Cancel)

IOC 

立即成交否则取消 (Immediate Or Cancel)

FOK 

全部成交否则取消 (Fill Or Kill)

Function Documentation

◆ buildExecutionReport()

FixMessage fix40::buildExecutionReport ( const ExecutionReport report)
inline

ExecutionReport 转换为 FIX 消息

Parameters
reportExecutionReport 结构
Returns
FixMessage FIX 消息对象

构建 FIX 4.0 ExecutionReport (MsgType=8) 消息。

Here is the call graph for this function:

◆ buildRejectReport()

ExecutionReport fix40::buildRejectReport ( const Order order,
RejectReason  reason,
const std::string &  text 
)

◆ create_heartbeat_message()

FixMessage fix40::create_heartbeat_message ( const std::string &  sender,
const std::string &  target,
int  seq_num,
const std::string &  test_req_id = "" 
)
inline

创建 Heartbeat 消息

Parameters
sender发送方 CompID
target接收方 CompID
seq_num消息序列号
test_req_idTestReqID(响应 TestRequest 时填写,否则为空)
Returns
FixMessage Heartbeat 消息对象

Heartbeat 消息用于:

  1. 定期发送以维持连接活跃
  2. 响应 TestRequest(此时需包含对应的 TestReqID)
  • MsgType (35) = "0"
  • TestReqID (112) = 可选
Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_logon_message()

FixMessage fix40::create_logon_message ( const std::string &  sender,
const std::string &  target,
int  seq_num = 1,
int  heart_bt = Config::instance().get_int("fix_session", "default_heartbeat_interval", 30),
bool  reset_seq_num = false 
)
inline

创建 Logon 消息

Parameters
sender发送方 CompID
target接收方 CompID
seq_num消息序列号(默认为 1)
heart_bt心跳间隔秒数(默认从配置读取)
Returns
FixMessage Logon 消息对象

Logon 消息用于建立 FIX 会话,包含:

  • MsgType (35) = "A"
  • EncryptMethod (98) = "0" (无加密)
  • HeartBtInt (108) = 心跳间隔
Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_logout_message()

FixMessage fix40::create_logout_message ( const std::string &  sender,
const std::string &  target,
int  seq_num,
const std::string &  text = "" 
)
inline

创建 Logout 消息

Parameters
sender发送方 CompID
target接收方 CompID
seq_num消息序列号
text登出原因(可选)
Returns
FixMessage Logout 消息对象

Logout 消息用于优雅地终止 FIX 会话。 发起方发送 Logout 后等待对方确认,然后关闭连接。

  • MsgType (35) = "5"
  • Text (58) = 可选,说明登出原因
Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_resend_request_message()

FixMessage fix40::create_resend_request_message ( const std::string &  sender,
const std::string &  target,
int  seq_num,
int  begin_seq_no,
int  end_seq_no 
)
inline

创建 ResendRequest 消息

Parameters
sender发送方 CompID
target接收方 CompID
seq_num消息序列号
begin_seq_no请求重传的起始序列号
end_seq_no请求重传的结束序列号(0 表示到最新)
Returns
FixMessage ResendRequest 消息对象

ResendRequest 消息用于请求对方重传指定范围的消息。 当检测到序列号 gap 时发送此消息。

  • MsgType (35) = "2"
  • BeginSeqNo (7) = 起始序列号
  • EndSeqNo (16) = 结束序列号(0 表示无限)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_sequence_reset_message()

FixMessage fix40::create_sequence_reset_message ( const std::string &  sender,
const std::string &  target,
int  seq_num,
int  new_seq_no,
bool  gap_fill = true 
)
inline

创建 SequenceReset 消息

Parameters
sender发送方 CompID
target接收方 CompID
seq_num消息序列号
new_seq_no新的序列号
gap_fill是否为 GapFill 模式
Returns
FixMessage SequenceReset 消息对象

SequenceReset 消息用于:

  1. GapFill 模式:跳过管理消息(如 Heartbeat、TestRequest)
  2. Reset 模式:重置序列号(通常在会话重置时使用)
  • MsgType (35) = "4"
  • NewSeqNo (36) = 新序列号
  • GapFillFlag (123) = Y/N
Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_test_request_message()

FixMessage fix40::create_test_request_message ( const std::string &  sender,
const std::string &  target,
int  seq_num,
const std::string &  test_req_id 
)
inline

创建 TestRequest 消息

Parameters
sender发送方 CompID
target接收方 CompID
seq_num消息序列号
test_req_id测试请求标识符(必填,对方需在 Heartbeat 中回传)
Returns
FixMessage TestRequest 消息对象

TestRequest 消息用于检测对端是否存活。 对端收到后应回复包含相同 TestReqID 的 Heartbeat。

  • MsgType (35) = "1"
  • TestReqID (112) = 必填
Here is the call graph for this function:
Here is the caller graph for this function:

◆ execTransTypeToFix()

std::string fix40::execTransTypeToFix ( ExecTransType  type)
inline

将 ExecTransType 转换为 FIX 字符串

Here is the caller graph for this function:

◆ formatTransactTime()

std::string fix40::formatTransactTime ( std::chrono::system_clock::time_point  tp)
inline

格式化 UTC 时间为 FIX 格式

Parameters
tp时间点
Returns
std::string FIX 格式时间字符串 (YYYYMMDD-HH:MM:SS)
Here is the caller graph for this function:

◆ is_admin_message()

bool fix40::is_admin_message ( const std::string &  msg_type)
inline

判断消息类型是否为管理消息

Parameters
msg_type消息类型
Returns
true 如果是管理消息(Heartbeat、TestRequest、ResendRequest、SequenceReset、Logout、Logon)

管理消息在重传时应使用 SequenceReset-GapFill 跳过,而不是重新发送。

◆ ordStatusToFix()

std::string fix40::ordStatusToFix ( OrderStatus  status)
inline

将 OrderStatus 转换为 FIX 字符串

Here is the caller graph for this function:

◆ ordTypeToFix()

std::string fix40::ordTypeToFix ( OrderType  type)
inline

将 OrderType 转换为 FIX 字符串

Here is the caller graph for this function:

◆ sideToFix()

std::string fix40::sideToFix ( OrderSide  side)
inline

将 OrderSide 转换为 FIX 字符串

Here is the caller graph for this function:

Variable Documentation

◆ DATE_LEN

constexpr size_t fix40::DATE_LEN = 9
constexpr

日期字符串长度 (YYYYMMDD)

◆ EXCHANGE_ID_LEN

constexpr size_t fix40::EXCHANGE_ID_LEN = 16
constexpr

交易所代码最大长度

◆ INSTRUMENT_ID_LEN

constexpr size_t fix40::INSTRUMENT_ID_LEN = 32
constexpr

合约代码最大长度

◆ INVALID_TIMER_ID

constexpr TimerTaskId fix40::INVALID_TIMER_ID = 0
constexpr

无效的定时任务 ID

◆ MAX_SAFE_DELAY_MS

constexpr int fix40::MAX_SAFE_DELAY_MS = INT_MAX / 1000
constexpr

最大安全延迟时间(毫秒),防止整数溢出

◆ SOH

constexpr char fix40::SOH = '\x01'
constexpr

FIX 字段分隔符:ASCII SOH (0x01)

◆ TIME_LEN

constexpr size_t fix40::TIME_LEN = 9
constexpr

时间字符串长度 (HH:MM:SS)