-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathBuildSymbolName.cpp
122 lines (111 loc) · 4.95 KB
/
BuildSymbolName.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
/************************************************************************
* Copyright(c) 2015, 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. *
************************************************************************/
// started 2015/11/15
#include <boost/lexical_cast.hpp>
#include <TFTrading/TradingEnumerations.h>
#include "BuildSymbolName.h"
namespace ou { // One Unified
namespace tf { // TradeFrame
namespace iqfeed { // IQFeed
// month is 1 - 12
// day is 1 - 31
const std::string BuildName( const NameParts& parts ) {
std::string sBuiltName;
switch ( parts.it ) {
case ou::tf::InstrumentType::Stock:
sBuiltName = parts.sRootName;
break;
case ou::tf::InstrumentType::Option:
if ( 0 != parts.day ) std::runtime_error( "ou::tf::iqfeed::BuildName: 0 == parts.day" );
sBuiltName
= ou::tf::iqfeed::BuildOptionName( parts.sRootName, parts.year, parts.month, parts.day, parts.strike, parts.side );
break;
case ou::tf::InstrumentType::Future:
sBuiltName
= ou::tf::iqfeed::BuildFuturesName( parts.sRootName, parts.year, parts.month );
break;
case ou::tf::InstrumentType::FuturesOption:
sBuiltName
= ou::tf::iqfeed::BuildFuturesOptionName( parts.sRootName, parts.year, parts.month, parts.strike, parts.side );
break;
default:
throw std::runtime_error( "ou::tf::iqfeed::BuildName: unknown instrument type" );
break;
}
return sBuiltName;
}
// something similar in Option.cpp
// need to deal with x10 type options
// http://www.iqfeed.net/symbolguide/index.cfm?symbolguide=guide&displayaction=support§ion=guide&web=iqfeed&guide=options&web=IQFeed&type=stock
const std::string BuildOptionName( const std::string& sUnderlying, uint16_t year, uint16_t month, uint16_t day, double strike, ou::tf::OptionSide::EOptionSide side ) {
std::string sName = sUnderlying;
if ( 0 != year ) {
sName += boost::lexical_cast<std::string>( year ).substr( 2, 2 ); // last two digits only
sName += ( ( 9 < day ) ? "" : "0" ) + boost::lexical_cast<std::string>( day );
//std::string sDay( '0' + boost::lexical_cast<std::string>( day ) );
//sName += sDay.substr( sDay.length() - 2 , 2 ); // two digits
switch ( side ) {
case 'C':
sName += 'A' - 1 + month;
break;
case 'P':
sName += 'M' - 1 + month;
break;
default:
assert( 0 );
break;
}
sName += boost::lexical_cast<std::string>( strike );
}
return sName;
}
const std::string BuildFuturesName( const std::string& sUnderlying, uint16_t year, uint16_t month ) {
static const char* code = { "FGHJKMNQUVXZ" };
std::string sName = sUnderlying;
if ( 0 != year ) {
sName += code[ month - 1 ];
sName += boost::lexical_cast<std::string>( year ).substr( 2, 2 ); // last two digits only
}
return sName;
}
const std::string BuildFuturesOptionName( const std::string& sUnderlying, uint16_t year, uint16_t month, double strike, ou::tf::OptionSide::EOptionSide side ) {
assert( 1 <= month );
assert( 12 >= month );
static const char* code = { "-FGHJKMNQUVXZ" }; // hyphen to make as 1 index
std::string sName = sUnderlying;
if ( 0 != year ) {
sName += ( 12 == month ? code[ 1 ] : code[ month + 1 ] ); // need code of next month
sName += boost::lexical_cast<std::string>( year ).substr( 2, 2 ); // last two digits only
sName += (char) side;
sName += boost::lexical_cast<std::string>( strike );
}
return sName;
}
const std::string BuildFuturesOptionName( const std::string& sUnderlying, uint16_t year, uint16_t month, uint16_t day, double strike, ou::tf::OptionSide::EOptionSide side ) {
std::runtime_error( "ou::tf::iqfeed::BuildFuturesOptionName: day not used yet" ); // day isn't used yet, need to fix
assert( 1 <= month );
assert( 12 >= month );
static const char* code = { "-FGHJKMNQUVXZ" }; // hyphen to make as 1 index
std::string sName = sUnderlying;
if ( 0 != year ) {
sName += ( 12 == month ? code[ 1 ] : code[ month + 1 ] ); // need code of next month
sName += boost::lexical_cast<std::string>( year ).substr( 2, 2 ); // last two digits only
sName += (char) side;
}
sName += boost::lexical_cast<std::string>( strike );
return sName;
}
} // namespace iqfeed
} // namespace tf
} // namespace ou