-
Notifications
You must be signed in to change notification settings - Fork 168
/
Copy pathMsgPriceLevelArrival.cpp
143 lines (115 loc) · 4.09 KB
/
MsgPriceLevelArrival.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/************************************************************************
* Copyright(c) 2021, One Unified. All rights reserved. *
* email: [email protected] *
* *
* This file is provided as is WITHOUT ANY WARRANTY *
* without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* *
* This software may not be used nor distributed without proper license *
* agreement. *
* *
* See the file LICENSE.txt for redistribution information. *
************************************************************************/
/*
* File: MsgPriceLevelArrival.cpp
* Author: [email protected]
* Project: TFIQFeed/Level2
* Created on October 16, 2021 20:02
*/
#include <string>
#include <boost/date_time/gregorian/gregorian_types.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/operator.hpp>
#include <boost/phoenix/bind.hpp>
#include "MsgOrderArrival.h"
using date_t = boost::gregorian::date;
using td_t = boost::posix_time::time_duration;
// http://www.iqfeed.net/dev/api/docs/docsBeta/MarketDepthMessages.cfm
struct decoded {
char chMsgType;
std::string sSymbolName;
char chOrderSide; // 'A' Sell, 'B' Buy
double dblPrice;
uint32_t nLevelSize;
uint32_t nOrderCount;
uint8_t nPrecision;
td_t time;
date_t date;
};
BOOST_FUSION_ADAPT_STRUCT(
decoded,
(char, chMsgType)
(std::string, sSymbolName)
(char, chOrderSide)
(double, dblPrice)
(uint32_t, nLevelSize)
(uint32_t, nOrderCount)
(uint8_t, nPrecision)
(td_t, time)
(date_t, date)
)
namespace {
namespace qi = boost::spirit::qi;
namespace ascii = boost::spirit::ascii;
template<typename Iterator>
struct parser_decoded: qi::grammar<Iterator, decoded()> {
parser_decoded(): parser_decoded::base_type( start ) {
ruleMsgType %=
qi::char_( '7' ) // Price Level Summary
| qi::char_( '8' ) // Price Level Update
;
ruleString %= *( qi::char_ - qi::char_( ',' ) );
ruleUint32 %= qi::uint_;
ruleUint8 %= qi::ushort_;
ruleOrderSide %=
qi::char_( 'A' ) // Sell
| qi::char_( 'B' ) // Buy)
;
rulePrice %= qi::double_;
ruleTime %=
qi::long_ > qi::lit( ':' ) // HH
> qi::long_ > qi::lit( ':' ) // mm
> qi::long_ > qi::lit( '.' ) // ss
> qi::long_ // fractional
;
ruleDate %=
qi::long_ > qi::lit( '-' ) // year
| qi::long_ > qi::lit( '-' ) // month
| qi::long_ // day
;
start %=
ruleMsgType > qi::lit( ',' ) // cMsgType
> ruleString > qi::lit( ',' ) // sSymbolName
> ruleOrderSide > qi::lit( ',' ) // ruleOrderSide
> rulePrice > qi::lit( ',' ) // dblPrice
> ruleUint32 > qi::lit( ',' ) // nLevelSize
> ruleUint32 > qi::lit( ',' ) // nOrderCount
> ruleUint8 > qi::lit( ',' ) // nPrecision
> ruleTime > qi::lit( ',' ) // time
> ruleDate > qi::lit( ',' ) // date
;
}
qi::rule<Iterator, char()> ruleMsgType;
qi::rule<Iterator, std::string()> ruleString;
qi::rule<Iterator, uint32_t()> ruleUint32;
qi::rule<Iterator, char()> ruleOrderSide;
qi::rule<Iterator, double()> rulePrice;
qi::rule<Iterator, uint8_t()> ruleUint8;
qi::rule<Iterator, td_t()> ruleTime;
qi::rule<Iterator, date_t()> ruleDate;
qi::rule<Iterator, decoded()> start;
};
}
namespace ou { // One Unified
namespace tf { // TradeFrame
namespace iqfeed { // IQFeed
namespace l2 { // level 2 data
namespace msg { // message
} // namespace msg
} // namespace l2
} // namesapce iqfeed
} // namespace tf
} // namespace ou