-
Notifications
You must be signed in to change notification settings - Fork 156
/
ParseMktSymbolLine.h
137 lines (117 loc) · 4.64 KB
/
ParseMktSymbolLine.h
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
/************************************************************************
* Copyright(c) 2012, One Unified. All rights reserved. *
* email: info@oneunified.net *
* *
* 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. *
************************************************************************/
#pragma once
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/qi_symbols.hpp>
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/operator.hpp>
#include <boost/phoenix/stl.hpp>
namespace qi = boost::spirit::qi;
namespace ascii = boost::spirit::ascii;
#include "SecurityType.h"
#include "MarketSymbol.h"
using trd_t = ou::tf::iqfeed::MarketSymbol::TableRowDef;
using sc_t = ou::tf::iqfeed::ESecurityType;
BOOST_FUSION_ADAPT_STRUCT(
trd_t,
(std::string, sSymbol)
(std::string, sDescription)
(std::string, sExchange)
(std::string, sListedMarket)
(sc_t, sc)
(boost::uint32_t, nSIC)
(boost::uint32_t, nNAICS)
(bool, bFrontMonth)
)
namespace ou { // One Unified
namespace tf { // TradeFrame
namespace iqfeed { // IQFeed
namespace qi = boost::spirit::qi;
namespace phoenix = boost::phoenix;
namespace ascii = boost::spirit::ascii;
void doout( const std::string& s );
template<typename Iterator>
struct MktSymbolLineParser: qi::grammar<Iterator, trd_t()> {
MktSymbolLineParser( void ): MktSymbolLineParser::base_type(start) {
symTypes.add
( "BONDS", sc_t::Bonds )
( "CALC", sc_t::Calc )
( "EQUITY", sc_t::Equity )
( "FOPTION", sc_t::FOption )
( "FOREX", sc_t::Forex )
( "FORWARD", sc_t::Forward )
( "FUTURE", sc_t::Future )
( "ICSPREAD", sc_t::ICSpread )
( "IEOPTION", sc_t::IEOption )
( "INDEX", sc_t::Index )
( "MKTRPT", sc_t::MktRpt )
( "MKTSTATS", sc_t::MktStats )
( "MONEY", sc_t::Money )
( "MUTUAL", sc_t::Mutual )
( "PRECMTL", sc_t::PrecMtl )
( "SPOT", sc_t::Spot )
( "SPREAD", sc_t::Spread )
( "STRATSPREAD", sc_t::StratSpread )
( "SWAPS", sc_t::Swaps )
( "TREASURIES", sc_t::Treasuries )
;
rNotATab %= qi::lexeme[ +( qi::char_ - '\t' ) ];
//rDefaultSymType %= ( qi::eps[ qi::_val = sc_t::Unknown, qi::_pass = false ] >> qi::omit[ rNotATab ] ); // proper syntax
rDefaultSymType %= ( qi::eps[ qi::_val = sc_t::Unknown ] >> qi::omit[ rNotATab ] );
rSymbol %= rNotATab;
rDescription %= rNotATab;
rExchange %= rNotATab;
rListedMarket %= rNotATab;
rSymbolClassifier %= ( symTypes | rDefaultSymType );
rSic %= qi::lexeme[ qi::uint_ ];
//rFrontMonth %= ( qi::char_( 'Y' )[ qi::_val = qi::true_ ] | qi::eps );
rFrontMonth %= ( qi::matches[ qi::char_( 'Y' ) ] | qi::eps );
rNaics %= qi::lexeme[ qi::uint_ ];
start %= rSymbol
> qi::lit( '\t' ) > -rDescription
> qi::lit( '\t' ) > rExchange
> qi::lit( '\t' ) > rListedMarket
> qi::lit( '\t' ) > rSymbolClassifier
> qi::lit( '\t' ) > -rSic
> qi::lit( '\t' ) > -rFrontMonth
> qi::lit( '\t' ) > -rNaics
> ( qi::eol | qi::eps );
/*
qi::on_error<qi::fail>(
start,
std::cout
<< phoenix::val( "unknown symbol type: " )
<< qi::_4
<< ","
<< phoenix::construct<std::string>( qi::_1, qi::_3 )
<< std::endl
);
*/
}
qi::symbols<char, sc_t> symTypes;
qi::rule<Iterator, sc_t()> rDefaultSymType;
qi::rule<Iterator, std::string()> rNotATab;
qi::rule<Iterator, std::string()> rSymbol;
qi::rule<Iterator, std::string()> rDescription;
qi::rule<Iterator, std::string()> rExchange;
qi::rule<Iterator, std::string()> rListedMarket;
qi::rule<Iterator, sc_t()> rSymbolClassifier;
qi::rule<Iterator, boost::uint32_t()> rSic;
qi::rule<Iterator, bool> rFrontMonth;
qi::rule<Iterator, boost::uint32_t()> rNaics;
qi::rule<Iterator, trd_t()> start;
};
} // namespace iqfeed
} // namespace tf
} // namespace ou