-
Notifications
You must be signed in to change notification settings - Fork 165
/
Copy pathTradingEnumerations.cpp
126 lines (95 loc) · 4.13 KB
/
TradingEnumerations.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
/************************************************************************
* Copyright(c) 2009, One Unified. All rights reserved. *
* *
* 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. *
************************************************************************/
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/qi_symbols.hpp>
#include <boost/fusion/include/std_pair.hpp>
#include <boost/phoenix/core.hpp>
#include "TradingEnumerations.h"
namespace ou { // One Unified
namespace tf { // TradeFrame
namespace InstrumentType {
const char* Name[] = { "Unknown", "Stock", "Option", "Future",
"FuturesOption", "Currency", "Index", "ETF", "Bond", "Commodity", "Metal", };
}
namespace OptionSide { // this doesn't work well with the existing enumerations
const char* Name[] = { "Unknown", "Put", "Call" };
const char* LongName[] = { "Unknown", "Put", "Call" };
const char* ShortName[] = { "U", "P", "C" };
}
namespace Currency {
namespace qi = boost::spirit::qi;
const char* Name[] = { "USD", "GBP", "CAD", "CHF", "HKD", "JPY", "EUR", "KRW", "LTL", "AUD", "CZK", "DKK", "NZD", "HUF", "ILS", "VOID" };
void FillSymbols( qi::symbols<char, ECurrency>& list ) {
list.add
( "USD", ECurrency::USD )
( "GBP", ECurrency::GBP )
( "CAD", ECurrency::CAD )
( "CHF", ECurrency::CHF )
( "HKD", ECurrency::HKD )
( "JPY", ECurrency::JPY )
( "EUR", ECurrency::EUR )
( "KRW", ECurrency::KRW )
( "LTL", ECurrency::LTL )
( "AUD", ECurrency::AUD )
( "CZK", ECurrency::CZK )
( "DKK", ECurrency::DKK )
( "NZD", ECurrency::NZD )
( "HUF", ECurrency::HUF )
( "ILS", ECurrency::ILS )
;
}
template<typename Iterator>
struct ParserCurrencyPair: qi::grammar<Iterator, pair_t()> {
ParserCurrencyPair(): ParserCurrencyPair::base_type( ruleStart ) {
FillSymbols( symCurrency );
ruleCurrency %= symCurrency;
ruleStart %= ruleCurrency
>> -( qi::lit( '.' ) | qi::lit( ':' ) | qi::lit( '-' ) )
>> ruleCurrency;
}
qi::symbols<char, ECurrency> symCurrency;
qi::rule<Iterator, ECurrency()> ruleCurrency;
qi::rule<Iterator, pair_t()> ruleStart;
};
pair_t Split( const std::string& sPair ) {
static ParserCurrencyPair<std::string::const_iterator> parserCurrencyPair;
pair_t pairCurrency( Currency::EUR, Currency::USD );
bool b = parse( sPair.begin(), sPair.end(), parserCurrencyPair, pairCurrency );
assert( b );
return pairCurrency;
}
template<typename Iterator>
struct ParserCurrencyName: qi::grammar<Iterator, ECurrency()> {
ParserCurrencyName(): ParserCurrencyName::base_type( ruleCurrency ) {
FillSymbols( symCurrency );
ruleCurrency %= symCurrency;
}
qi::symbols<char, ECurrency> symCurrency;
qi::rule<Iterator, ECurrency()> ruleCurrency;
};
ECurrency ParseName( const std::string& sName ) {
static ParserCurrencyName<std::string::const_iterator> parserCurrencyName;
ECurrency currency( Currency::USD );
bool b = parse( sName.begin(), sName.end(), parserCurrencyName, currency );
assert( b );
return currency;
}
}
namespace OrderSide {
const char* Name[] = { "UNKN", "BUY", "SELL", "SSHORT" }; // for IB
}
namespace TimeInForce {
const char* Name[] = { "UNKN", "DAY", "GTC", "ATO", "IOC", "FOK", "GTC", "GTD", "GAC", "ATC", "AUC", "OPG" };
}
} // namespace tf
} // namespace ou