-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathInstrumentData.cpp
134 lines (106 loc) · 4.87 KB
/
InstrumentData.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
/************************************************************************
* Copyright(c) 2012, 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 "stdafx.h"
#include <TFHDF5TimeSeries/HDF5DataManager.h>
#include <TFHDF5TimeSeries/HDF5WriteTimeSeries.h>
#include <TFHDF5TimeSeries/HDF5IterateGroups.h>
#include <TFHDF5TimeSeries/HDF5Attribute.h>
#include "InstrumentData.h"
namespace ou { // One Unified
namespace tf { // TradeFrame
InstrumentData::InstrumentData( const Instrument::pInstrument_t& pInstrument, unsigned int nSigDigits )
: m_pInstrument( pInstrument ), m_nSignificantDigits( nSigDigits )
{
Init();
}
InstrumentData::InstrumentData( Instrument* pInstrument, unsigned int nSigDigits )
: m_pInstrument( pInstrument ), m_nSignificantDigits( nSigDigits )
{
Init();
}
InstrumentData::InstrumentData( const InstrumentData& data )
: m_pInstrument( data.m_pInstrument ), m_nSignificantDigits( data.m_nSignificantDigits )
{
Init();
}
void InstrumentData::Init( void ) {
}
InstrumentData::~InstrumentData(void) {
}
void InstrumentData::HandleQuote( const Quote& quote ) {
m_quotes.Append( quote );
}
void InstrumentData::HandleTrade( const Trade& trade ) {
m_trades.Append( trade );
}
void InstrumentData::HandleGreek( const Greek& greek ) {
m_greeks.Append( greek );
}
void InstrumentData::AddQuoteHandler( ProviderManager::pProvider_t pProvider ) {
pProvider->AddQuoteHandler(m_pInstrument, MakeDelegate( this, &InstrumentData::HandleQuote ) );
}
void InstrumentData::RemoveQuoteHandler( ProviderManager::pProvider_t pProvider ) {
pProvider->RemoveQuoteHandler(m_pInstrument, MakeDelegate( this, &InstrumentData::HandleQuote ) );
}
void InstrumentData::AddTradeHandler( ProviderManager::pProvider_t pProvider ) {
pProvider->AddTradeHandler(m_pInstrument, MakeDelegate( this, &InstrumentData::HandleTrade ) );
}
void InstrumentData::RemoveTradeHandler( ProviderManager::pProvider_t pProvider ) {
pProvider->RemoveTradeHandler(m_pInstrument, MakeDelegate( this, &InstrumentData::HandleTrade ) );
}
void InstrumentData::AddGreekHandler( ProviderManager::pProvider_t pProvider ) {
pProvider->AddGreekHandler(m_pInstrument, MakeDelegate( this, &InstrumentData::HandleGreek ) );
}
void InstrumentData::RemoveGreekHandler( ProviderManager::pProvider_t pProvider ) {
pProvider->RemoveGreekHandler(m_pInstrument, MakeDelegate( this, &InstrumentData::HandleGreek ) );
}
void InstrumentData::SaveSeries( const std::string& sPrefix ) {
std::string sPathName;
// CHDF5Attributes::structFuture future( m_pInstrument->GetExpiryYear(), m_pInstrument->GetExpiryMonth(), m_pInstrument->GetExpiryDay() );
ou::tf::HDF5DataManager dm( ou::tf::HDF5DataManager::RDWR );
if ( 0 != m_quotes.Size() ) {
sPathName = sPrefix + "/quotes/" + m_pInstrument->GetInstrumentName();
HDF5WriteTimeSeries<Quotes> wtsQuotes( dm );
wtsQuotes.Write( sPathName, &m_quotes );
// CHDF5Attributes attrQuotes( sPathName, future );
//attrQuotes.SetMultiplier( 1 );
//attrQuotes.SetSignificantDigits( 2 );
//attrTrades.SetProviderType( m_pDataProvider->ID() );
}
if ( 0 != m_trades.Size() ) {
sPathName = sPrefix + "/trades/" + m_pInstrument->GetInstrumentName();
HDF5WriteTimeSeries<Trades> wtsTrades( dm );
wtsTrades.Write( sPathName, &m_trades );
// CHDF5Attributes attrTrades( sPathName, future );
//attrTrades.SetMultiplier( 1 );
//attrTrades.SetSignificantDigits( 2 );
//attrTrades.SetProviderType( m_pDataProvider->ID() );
}
if ( 0 != m_greeks.Size() ) {
sPathName = sPrefix + "/greeks/" + m_pInstrument->GetInstrumentName();
HDF5WriteTimeSeries<Greeks> wtsGreeks( dm );
wtsGreeks.Write( sPathName, &m_greeks );
// CHDF5Attributes attrTrades( sPathName, future );
//attrTrades.SetMultiplier( 1 );
//attrTrades.SetSignificantDigits( 2 );
//attrTrades.SetProviderType( m_pDataProvider->ID() );
}
}
void InstrumentData::Reset( void ) {
m_quotes.Clear();
m_trades.Clear();
m_greeks.Clear();
Init(); // takes care of m_rSummary
}
} // namespace tf
} // namespace ou