-
Notifications
You must be signed in to change notification settings - Fork 164
/
Copy pathInstrumentManager.h
125 lines (98 loc) · 4.83 KB
/
InstrumentManager.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
/************************************************************************
* 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. *
************************************************************************/
#pragma once
// 2011/03/16 add persist-to-db superclass for saving/retrieving instruments
#include <map>
#include <mutex>
#include <string>
#include <OUCommon/ManagerBase.h>
#include "KeyTypes.h"
#include "Instrument.h"
namespace ou { // One Unified
namespace tf { // TradeFrame
class InstrumentManager
: public ou::db::ManagerBase<InstrumentManager> {
public:
using inherited_t = ou::db::ManagerBase<InstrumentManager>;
using pInstrument_t = Instrument::pInstrument_t;
using pInstrument_cref = Instrument::pInstrument_cref;
using idInstrument_t = Instrument::idInstrument_t;
using idInstrument_cref = Instrument::idInstrument_cref;
InstrumentManager();
virtual ~InstrumentManager();
pInstrument_t ConstructInstrument(
idInstrument_cref sInstrumentName, const std::string& sExchangeName, // generic
InstrumentType::EInstrumentType type = InstrumentType::Unknown );
pInstrument_t ConstructFuture(
idInstrument_cref sInstrumentName, const std::string& sExchangeName, // future
boost::uint16_t year, boost::uint16_t month, boost::uint16_t day );
pInstrument_t ConstructFuturesOption(
idInstrument_cref sInstrumentName, const std::string& sExchangeName, // option with yymmdd
boost::uint16_t year, boost::uint16_t month, boost::uint16_t day,
OptionSide::EOptionSide side,
double strike );
pInstrument_t ConstructOption(
idInstrument_cref sInstrumentName, const std::string& sExchangeName, // option with yymmdd
boost::uint16_t year, boost::uint16_t month, boost::uint16_t day,
OptionSide::EOptionSide side,
double strike );
pInstrument_t ConstructCurrency(
idInstrument_cref idInstrumentName,
const std::string& sExchangeName,
Currency::ECurrency base, Currency::ECurrency counter );
void Register( pInstrument_t& pInstrument );
bool Exists( idInstrument_cref );
bool Exists( idInstrument_cref, pInstrument_t& );
bool Exists( pInstrument_cref );
pInstrument_t Get( idInstrument_cref ); // for getting existing associated with id
void Delete( idInstrument_cref );
pInstrument_t LoadInstrument( keytypes::eidProvider_t, const idInstrument_t& ); // may have exeption?
template<typename F> void ScanOptions( F f, idInstrument_cref, boost::uint16_t year, boost::uint16_t month, boost::uint16_t day );
virtual void AttachToSession( ou::db::Session* pSession );
virtual void DetachFromSession( ou::db::Session* pSession );
protected:
void Assign( pInstrument_cref pInstrument );
bool LoadInstrument( idInstrument_t idInstrument, pInstrument_t& pInstrument );
void LoadAlternateInstrumentNames( pInstrument_t& pInstrument );
private:
using mapInstruments_t = std::map<idInstrument_t,pInstrument_t>;
using iterInstruments_t = mapInstruments_t::iterator;
mapInstruments_t m_mapInstruments;
using keyAltName_t = std::pair<keytypes::eidProvider_t, std::string>;
using keyAltName_ref_t = std::pair<const keytypes::eidProvider_t&, const std::string&>;
struct keyAltName_compare {
bool operator()( const keyAltName_t& key1, const keyAltName_t& key2 ) const {
if ( key1.first < key2.first ) {
return true;
}
else {
return key1.second < key2.second;
}
}
};
using mapAltNames_t = std::map<keyAltName_t, pInstrument_t, keyAltName_compare>;
mapAltNames_t m_mapAltNames;
std::mutex m_mutexLoadInstrument;
void SaveAlternateInstrumentName(
const keytypes::eidProvider_t&,
const keytypes::idInstrument_t&, const keytypes::idInstrument_t&,
pInstrument_t
);
void HandleRegisterTables( ou::db::Session& session );
void HandleRegisterRows( ou::db::Session& session );
void HandlePopulateTables( ou::db::Session& session );
void HandleAlternateNameAdded( const Instrument::AlternateNameChangeInfo_t& );
void HandleAlternateNameChanged( const Instrument::AlternateNameChangeInfo_t& );
};
} // namespace tf
} // namespace ou