FIX 4.0 Demo 1.0
Loading...
Searching...
No Matches
market_data_snapshot.hpp
Go to the documentation of this file.
1
9#pragma once
10
11#include <string>
12#include <cstdint>
13#include <chrono>
14
15namespace fix40 {
16
17// ============================================================================
18// 行情快照结构
19// ============================================================================
20
48 // -------------------------------------------------------------------------
49 // 标识符
50 // -------------------------------------------------------------------------
51 std::string instrumentId;
52
53 // -------------------------------------------------------------------------
54 // 价格信息
55 // -------------------------------------------------------------------------
56 double lastPrice;
57 double bidPrice1;
58 int32_t bidVolume1;
59 double askPrice1;
60 int32_t askVolume1;
61
62 // -------------------------------------------------------------------------
63 // 涨跌停价格
64 // -------------------------------------------------------------------------
67
68 // -------------------------------------------------------------------------
69 // 时间戳
70 // -------------------------------------------------------------------------
71 std::chrono::system_clock::time_point updateTime;
72
73 // -------------------------------------------------------------------------
74 // 构造函数
75 // -------------------------------------------------------------------------
76
83 : lastPrice(0.0)
84 , bidPrice1(0.0)
85 , bidVolume1(0)
86 , askPrice1(0.0)
87 , askVolume1(0)
88 , upperLimitPrice(0.0)
89 , lowerLimitPrice(0.0)
90 , updateTime(std::chrono::system_clock::now())
91 {}
92
98 explicit MarketDataSnapshot(const std::string& instId)
99 : instrumentId(instId)
100 , lastPrice(0.0)
101 , bidPrice1(0.0)
102 , bidVolume1(0)
103 , askPrice1(0.0)
104 , askVolume1(0)
105 , upperLimitPrice(0.0)
106 , lowerLimitPrice(0.0)
107 , updateTime(std::chrono::system_clock::now())
108 {}
109
110 // -------------------------------------------------------------------------
111 // 验证方法
112 // -------------------------------------------------------------------------
113
124 bool isValid() const {
125 return bidPrice1 > 0 || askPrice1 > 0;
126 }
127
133 bool hasBid() const {
134 return bidPrice1 > 0 && bidVolume1 > 0;
135 }
136
142 bool hasAsk() const {
143 return askPrice1 > 0 && askVolume1 > 0;
144 }
145
155 double getSpread() const {
156 if (bidPrice1 > 0 && askPrice1 > 0) {
157 return askPrice1 - bidPrice1;
158 }
159 return 0.0;
160 }
161
167 double getMidPrice() const {
168 if (bidPrice1 > 0 && askPrice1 > 0) {
169 return (bidPrice1 + askPrice1) / 2.0;
170 }
171 return lastPrice;
172 }
173
174 // -------------------------------------------------------------------------
175 // 比较操作符(用于测试)
176 // -------------------------------------------------------------------------
177
189 bool operator==(const MarketDataSnapshot& other) const {
190 return instrumentId == other.instrumentId &&
191 lastPrice == other.lastPrice &&
192 bidPrice1 == other.bidPrice1 &&
193 bidVolume1 == other.bidVolume1 &&
194 askPrice1 == other.askPrice1 &&
195 askVolume1 == other.askVolume1 &&
198 }
199
206 bool operator!=(const MarketDataSnapshot& other) const {
207 return !(*this == other);
208 }
209};
210
211} // namespace fix40
Definition matching_engine.hpp:23
合约行情快照
Definition market_data_snapshot.hpp:47
int32_t askVolume1
卖一量
Definition market_data_snapshot.hpp:60
double askPrice1
卖一价(最低卖价)
Definition market_data_snapshot.hpp:59
bool operator==(const MarketDataSnapshot &other) const
相等比较操作符
Definition market_data_snapshot.hpp:189
MarketDataSnapshot(const std::string &instId)
带合约代码的构造函数
Definition market_data_snapshot.hpp:98
std::chrono::system_clock::time_point updateTime
行情更新时间
Definition market_data_snapshot.hpp:71
double upperLimitPrice
涨停价
Definition market_data_snapshot.hpp:65
int32_t bidVolume1
买一量
Definition market_data_snapshot.hpp:58
double lowerLimitPrice
跌停价
Definition market_data_snapshot.hpp:66
bool hasAsk() const
检查是否有卖盘
Definition market_data_snapshot.hpp:142
bool isValid() const
检查行情是否有效
Definition market_data_snapshot.hpp:124
std::string instrumentId
合约代码(如 "IF2601")
Definition market_data_snapshot.hpp:51
double getSpread() const
获取买卖价差
Definition market_data_snapshot.hpp:155
double bidPrice1
买一价(最高买价)
Definition market_data_snapshot.hpp:57
double lastPrice
最新价
Definition market_data_snapshot.hpp:56
MarketDataSnapshot()
默认构造函数
Definition market_data_snapshot.hpp:82
double getMidPrice() const
获取中间价
Definition market_data_snapshot.hpp:167
bool hasBid() const
检查是否有买盘
Definition market_data_snapshot.hpp:133
bool operator!=(const MarketDataSnapshot &other) const
不等比较操作符
Definition market_data_snapshot.hpp:206