-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathMarketSymbol.cpp
142 lines (131 loc) · 5.27 KB
/
MarketSymbol.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
/************************************************************************
* Copyright(c) 2012, 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. *
************************************************************************/
#include <TFTrading/Instrument.h>
#include "MarketSymbol.h"
#include "ParseOptionSymbol.h"
namespace ou { // One Unified
namespace tf { // TradeFrame
namespace iqfeed { // IQFeed
MarketSymbol::MarketSymbol() {
}
MarketSymbol::~MarketSymbol() {
}
// deprecating?
const std::string MarketSymbol::BuildGenericName( const std::string& sBaseName, const TableRowDef& trd ) {
std::string sName( sBaseName );
switch( trd.sc ) {
case ESecurityType::Equity:
// uses base name
break;
case ESecurityType::IEOption:
sName = ou::tf::Instrument::BuildGenericOptionName( sBaseName, trd.nYear, trd.nMonth, trd.nDay, trd.eOptionSide, trd.dblStrike );
break;
default:
assert( false );
break;
}
return sName;
}
// improved version
const std::string MarketSymbol::BuildGenericName( const std::string& sBaseName, const TableRowDef& trd, Date date ) {
std::string sName( sBaseName );
switch( trd.sc ) {
case ESecurityType::Equity:
// uses base name
break;
case ESecurityType::Future:
sName = ou::tf::Instrument::BuildGenericFutureName( sBaseName, date.year(), date.month(), date.day() );
break;
case ESecurityType::IEOption:
case ESecurityType::FOption:
sName = ou::tf::Instrument::BuildGenericOptionName( sBaseName, date.year(), date.month(), date.day(), trd.eOptionSide, trd.dblStrike );
break;
default:
assert( false );
break;
}
return sName;
}
// improved improved version
const std::string MarketSymbol::BuildGenericName( const TableRowDef& trd, const Fundamentals& fundamentals ) {
std::string sName( fundamentals.sExchangeRoot );
switch( trd.sc ) {
case ESecurityType::Equity:
// uses base name
break;
case ESecurityType::Future:
sName = ou::tf::Instrument::BuildGenericFutureName( sName, fundamentals.dateExpiration );
break;
case ESecurityType::IEOption:
case ESecurityType::FOption:
sName = ou::tf::Instrument::BuildGenericOptionName( sName, fundamentals.dateExpiration, trd.eOptionSide, fundamentals.dblStrikePrice );
break;
default:
assert( false );
break;
}
return sName;
}
// improved improved improved version
const std::string MarketSymbol::BuildGenericName( const Fundamentals& fundamentals ) {
std::string sName;
if ( 0 == fundamentals.sExchangeRoot.size() ) {
sName = fundamentals.sSymbolName;
}
else {
sName = fundamentals.sExchangeRoot;
}
switch( fundamentals.eSecurityType ) {
case ESecurityType::Equity:
// uses base name
break;
case ESecurityType::Future:
sName = ou::tf::Instrument::BuildGenericFutureName( sName, fundamentals.dateExpiration );
break;
case ESecurityType::IEOption:
sName = ou::tf::Instrument::BuildGenericOptionName( OptionBaseName( fundamentals ), fundamentals.dateExpiration, fundamentals.eOptionSide, fundamentals.dblStrikePrice );
break;
case ESecurityType::FOption:
if ( sName != fundamentals.sExchangeRoot ) {
std::cout << "MarketSymbol::BuildGenericName futures-option problem: " << sName << " vs " << fundamentals.sExchangeRoot << std::endl;
}
sName = ou::tf::Instrument::BuildGenericOptionName( sName, fundamentals.dateExpiration, fundamentals.eOptionSide, fundamentals.dblStrikePrice );
break;
case ESecurityType::MktStats:
// uses base name
break;
case ESecurityType::Forex:
// example: "USDCAD.FXCM"
assert( 11 == fundamentals.sSymbolName.size() );
assert( 16 == fundamentals.sCompanyName.size() );
assert( "FXCM" == fundamentals.sExchange );
sName = fundamentals.sSymbolName.substr( 0, 3 ) + '.' + fundamentals.sSymbolName.substr( 3, 3 );
break;
default:
assert( false );
break;
}
return sName;
}
const std::string MarketSymbol::OptionBaseName( const Fundamentals& fundamentals ) {
const std::string& sName( fundamentals.sSymbolName );
ou::tf::iqfeed::structParsedOptionSymbol1 parsed;
ou::tf::iqfeed::OptionSymbolParser1<std::string::const_iterator> parserOptionSymbol1;
bool bOk = parse( sName.cbegin(), sName.cend(), parserOptionSymbol1, parsed );
assert( bOk );
return parsed.sText;
}
} // namespace iqfeed
} // namespace tf
} // namespace ou