-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathHistoryCollector.cpp
123 lines (95 loc) · 3.58 KB
/
HistoryCollector.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
/************************************************************************
* Copyright(c) 2009, 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 "StdAfx.h"
#include <cassert>
#include <TFHDF5TimeSeries/HDF5WriteTimeSeries.h>
#include <TFHDF5TimeSeries/HDF5DataManager.h>
#include "IQFeedHistoryCollector.h"
namespace ou { // One Unified
namespace tf { // TradeFrame
//
// CHistoryCollector
//
CHistoryCollector::CHistoryCollector( CIQFeedProvider *pProvider, const char *szSymbol, unsigned long nCount )
: m_pProvider( pProvider )
{
m_sSymbol.assign( szSymbol );
m_nCount = nCount;
}
CHistoryCollector::~CHistoryCollector() {
}
void CHistoryCollector::Start( void ) {
// m_phistory will be assigned by sub classes
assert( NULL != m_phistory );
m_phistory->LiveRequest( m_sSymbol.c_str(), m_nCount );
}
void CHistoryCollector::OnCompletion( IQFeedHistory *pHistory ) {
if ( NULL != OnRetrievalComplete ) OnRetrievalComplete( this );
}
//
// CHistoryCollectorDaily
//
CHistoryCollectorDaily::CHistoryCollectorDaily( CIQFeedProvider *pProvider, const char *szSymbol, unsigned long nCount ) :
CHistoryCollector( pProvider, szSymbol, nCount ) {
m_phistory = new IQFeedHistoryHD( m_pProvider, &m_bars );
FinalizeCreation();
}
CHistoryCollectorDaily::~CHistoryCollectorDaily( void ) {
delete m_phistory;
}
void CHistoryCollectorDaily::Start( void ) {
m_bars.Clear();
CHistoryCollector::Start();
}
void CHistoryCollectorDaily::WriteData( void ) {
if ( 0 != m_bars.Count() ) {
assert( m_sSymbol.length() > 0 );
std::string sPathName;
CHDF5DataManager::DailyBarPath( m_sSymbol, sPathName );
CHDF5WriteTimeSeries<CBars, CBar> wts;
wts.Write( sPathName, &m_bars );
}
}
//
// CHistoryCollectorTicks
//
CHistoryCollectorTicks::CHistoryCollectorTicks( CIQFeedProvider *pProvider, const char *szSymbol, unsigned long nCount ) :
CHistoryCollector( pProvider, szSymbol, nCount ) {
m_phistory = new IQFeedHistoryHT( m_pProvider, &m_quotes, &m_trades );
FinalizeCreation();
}
CHistoryCollectorTicks::~CHistoryCollectorTicks( void ) {
delete m_phistory;
}
void CHistoryCollectorTicks::Start( void ) {
m_trades.Clear();
m_quotes.Clear();
CHistoryCollector::Start();
}
void CHistoryCollectorTicks::WriteData( void ) {
assert( m_sSymbol.length() > 0 );
string sPathName;
if ( 0 != m_trades.Count() ) {
sPathName = "/trade/" + m_sSymbol;
CHDF5WriteTimeSeries<CTrades, CTrade> wtst;
wtst.Write( sPathName, &m_trades );
}
if ( 0 != m_quotes.Count() ) {
sPathName = "/quote/" + m_sSymbol;
CHDF5WriteTimeSeries<CQuotes, CQuote> wtsq;
wtsq.Write( sPathName, &m_quotes );
}
}
} // namespace tf
} // namespace ou