FIX 4.0 Demo 1.0
Loading...
Searching...
No Matches
order.hpp
Go to the documentation of this file.
1
9#pragma once
10
11#include <string>
12#include <cstdint>
13#include <chrono>
14#include "fix/application.hpp"
15
16namespace fix40 {
17
18// ============================================================================
19// 枚举定义
20// ============================================================================
21
26enum class OrderSide {
27 BUY = 1,
28 SELL = 2
29};
30
35enum class OrderType {
36 MARKET = 1,
37 LIMIT = 2
38};
39
44enum class TimeInForce {
45 DAY = 0,
46 GTC = 1,
47 IOC = 3,
48 FOK = 4
49};
50
58enum class OrderStatus {
59 NEW = 0,
61 FILLED = 2,
62 CANCELED = 4,
63 REJECTED = 8,
64 PENDING_NEW = 10,
66};
67
72enum class ExecTransType {
73 NEW = 0,
74 CANCEL = 1,
75 CORRECT = 2,
76 STATUS = 3
77};
78
79// ============================================================================
80// 订单结构
81// ============================================================================
82
90struct Order {
91 // -------------------------------------------------------------------------
92 // 标识符
93 // -------------------------------------------------------------------------
94 std::string clOrdID;
95 std::string orderID;
97
98 // -------------------------------------------------------------------------
99 // 订单参数
100 // -------------------------------------------------------------------------
101 std::string symbol;
105 int64_t orderQty;
106 double price;
107
108 // -------------------------------------------------------------------------
109 // 执行状态
110 // -------------------------------------------------------------------------
112 int64_t cumQty;
113 int64_t leavesQty;
114 double avgPx;
115
116 // -------------------------------------------------------------------------
117 // 时间戳
118 // -------------------------------------------------------------------------
119 std::chrono::system_clock::time_point createTime;
120 std::chrono::system_clock::time_point updateTime;
121
122 // -------------------------------------------------------------------------
123 // 构造函数
124 // -------------------------------------------------------------------------
125
130 : side(OrderSide::BUY)
133 , orderQty(0)
134 , price(0.0)
136 , cumQty(0)
137 , leavesQty(0)
138 , avgPx(0.0)
139 , createTime(std::chrono::system_clock::now())
141 {}
142
148 }
149
153 bool isTerminal() const {
154 return status == OrderStatus::FILLED ||
157 }
158
162 bool isCancelable() const {
163 return status == OrderStatus::NEW ||
165 }
166};
167
168// ============================================================================
169// 撤单请求
170// ============================================================================
171
177 std::string clOrdID;
178 std::string origClOrdID;
179 std::string symbol;
181
182 CancelRequest() = default;
183};
184
185// ============================================================================
186// 执行报告
187// ============================================================================
188
196 // 标识符
197 std::string orderID;
198 std::string clOrdID;
199 std::string execID;
200 std::string origClOrdID;
201
202 // 订单信息
203 std::string symbol;
206 int64_t orderQty;
207 double price;
208
209 // 执行信息
212 int64_t lastShares;
213 double lastPx;
214 int64_t leavesQty;
215 int64_t cumQty;
216 double avgPx;
217
218 // 时间
219 std::chrono::system_clock::time_point transactTime;
220
221 // 拒绝信息
223 std::string text;
224
225 // 会话信息
227
232 : side(OrderSide::BUY)
234 , orderQty(0)
235 , price(0.0)
238 , lastShares(0)
239 , lastPx(0.0)
240 , leavesQty(0)
241 , cumQty(0)
242 , avgPx(0.0)
243 , transactTime(std::chrono::system_clock::now())
244 , ordRejReason(0)
245 {}
246};
247
248} // namespace fix40
FIX 应用层接口定义
Definition matching_engine.hpp:23
ExecTransType
执行事务类型 (FIX 4.0)
Definition order.hpp:72
@ CORRECT
更正之前的执行报告
@ CANCEL
取消之前的执行报告
@ STATUS
状态查询响应
OrderStatus
订单状态
Definition order.hpp:58
@ NEW
新订单(已接受)
@ PENDING_NEW
待确认(内部状态)
@ PARTIALLY_FILLED
部分成交
@ PENDING_CANCEL
待撤销(内部状态)
@ FILLED
全部成交
@ REJECTED
已拒绝
@ CANCELED
已撤销
OrderSide
买卖方向
Definition order.hpp:26
OrderType
订单类型
Definition order.hpp:35
@ LIMIT
限价单
@ MARKET
市价单
TimeInForce
订单有效期
Definition order.hpp:44
@ DAY
当日有效
@ IOC
立即成交否则取消 (Immediate Or Cancel)
@ GTC
撤销前有效 (Good Till Cancel)
@ FOK
全部成交否则取消 (Fill Or Kill)
撤单请求
Definition order.hpp:176
std::string origClOrdID
要撤销的原订单ID
Definition order.hpp:178
SessionID sessionID
来源会话
Definition order.hpp:180
std::string symbol
标的代码
Definition order.hpp:179
std::string clOrdID
本次撤单请求的ID
Definition order.hpp:177
执行报告
Definition order.hpp:195
int64_t leavesQty
剩余数量
Definition order.hpp:214
std::string clOrdID
客户端订单ID
Definition order.hpp:198
int64_t orderQty
订单数量
Definition order.hpp:206
OrderStatus ordStatus
订单状态
Definition order.hpp:211
OrderSide side
买卖方向
Definition order.hpp:204
std::string orderID
服务端订单ID
Definition order.hpp:197
OrderType ordType
订单类型
Definition order.hpp:205
std::string origClOrdID
原订单ID(撤单时使用)
Definition order.hpp:200
double avgPx
平均成交价
Definition order.hpp:216
ExecTransType execTransType
执行事务类型
Definition order.hpp:210
std::string execID
执行ID(每次报告唯一)
Definition order.hpp:199
int64_t lastShares
本次成交数量 (FIX 4.0: LastShares)
Definition order.hpp:212
std::chrono::system_clock::time_point transactTime
交易时间
Definition order.hpp:219
std::string text
文本说明
Definition order.hpp:223
SessionID sessionID
目标会话
Definition order.hpp:226
ExecutionReport()
默认构造函数
Definition order.hpp:231
double lastPx
本次成交价格
Definition order.hpp:213
int ordRejReason
拒绝原因代码
Definition order.hpp:222
double price
订单价格
Definition order.hpp:207
std::string symbol
标的代码
Definition order.hpp:203
int64_t cumQty
累计成交数量
Definition order.hpp:215
内部订单表示
Definition order.hpp:90
int64_t orderQty
订单数量
Definition order.hpp:105
double price
限价(市价单为 0)
Definition order.hpp:106
void updateLeavesQty()
计算剩余数量
Definition order.hpp:146
OrderStatus status
当前状态
Definition order.hpp:111
int64_t leavesQty
剩余数量
Definition order.hpp:113
std::chrono::system_clock::time_point updateTime
最后更新时间
Definition order.hpp:120
SessionID sessionID
来源会话
Definition order.hpp:96
int64_t cumQty
累计成交数量
Definition order.hpp:112
OrderType ordType
订单类型
Definition order.hpp:103
double avgPx
平均成交价
Definition order.hpp:114
OrderSide side
买卖方向
Definition order.hpp:102
bool isTerminal() const
检查订单是否已完成(不可再成交)
Definition order.hpp:153
std::string orderID
服务端订单ID(撮合引擎生成)
Definition order.hpp:95
std::chrono::system_clock::time_point createTime
创建时间
Definition order.hpp:119
Order()
默认构造函数
Definition order.hpp:129
TimeInForce timeInForce
有效期类型
Definition order.hpp:104
bool isCancelable() const
检查订单是否可撤销
Definition order.hpp:162
std::string clOrdID
客户端订单ID(客户端生成)
Definition order.hpp:94
std::string symbol
标的代码
Definition order.hpp:101
FIX 会话标识符
Definition application.hpp:28