-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathBarHistory.cpp
148 lines (125 loc) · 4.23 KB
/
BarHistory.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
143
144
145
146
147
148
/************************************************************************
* Copyright(c) 2021, 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. *
************************************************************************/
/*
* File: BarHistory.cpp
* Author: [email protected]
* Project: lib/TFIQFeed
* Created: August 7, 2021, 19:06
*/
//#include <iostream> // for test use, remove for production
#include "BarHistory.h"
namespace ou {
namespace tf {
namespace iqfeed {
BarHistory::BarHistory()
: ou::tf::iqfeed::HistoryQuery<BarHistory>()
, m_bConnected( false )
, m_fConnected( nullptr )
, m_fBar( nullptr )
, m_fDone( nullptr )
{}
BarHistory::BarHistory(
fConnected_t&& fConnected
)
: ou::tf::iqfeed::HistoryQuery<BarHistory>()
, m_bConnected( false )
, m_fConnected( std::move( fConnected ) )
, m_fBar( nullptr )
, m_fDone( nullptr )
{
assert( m_fConnected );
}
BarHistory::BarHistory(
fConnected_t&& fConnected, fBar_t&& fBar, fDone_t&& fDone
)
: ou::tf::iqfeed::HistoryQuery<BarHistory>()
, m_bConnected( false )
, m_fConnected( std::move( fConnected ) )
, m_fBar( std::move( fBar ) )
, m_fDone( std::move( fDone ) )
{
assert( m_fConnected );
assert( m_fBar );
assert( m_fDone );
}
BarHistory::~BarHistory() {
if ( m_bConnected ) {
//m_bConnected = false;
Disconnect();
}
}
void BarHistory::Set( fBar_t&& fBar, fDone_t&& fDone ) {
assert( fBar );
assert( fDone );
m_fBar = std::move( fBar );
m_fDone = std::move( fDone );
}
void BarHistory::Set( fConnected_t&& fConnected, fBar_t&& fBar, fDone_t&& fDone ) {
assert( !m_bConnected );
assert( fConnected );
assert( fBar );
assert( fDone );
m_fConnected = std::move( fConnected );
m_fBar = std::move( fBar );
m_fDone = std::move( fDone );
}
void BarHistory::Connect() {
ou::tf::iqfeed::HistoryQuery<BarHistory>::Connect();
}
void BarHistory::RequestNBars( const std::string& sSymbol, unsigned int nSeconds, unsigned int nBars ) {
RetrieveNIntervals( sSymbol, nSeconds, nBars );
}
void BarHistory::RequestNDaysOfBars( const std::string& sSymbol, unsigned int nSeconds, unsigned int nDays ) {
RetrieveNDaysOfIntervals( sSymbol, nSeconds, nDays );
}
void BarHistory::RequestNEndOfDay( const std::string& sSymbol, unsigned int nDays ) {
RetrieveNEndOfDays( sSymbol, nDays );
}
void BarHistory::OnHistoryConnected() {
//std::cout << "OnHistoryConnected" << std::endl;
m_bConnected = true;
m_fConnected();
};
void BarHistory::OnHistoryDisconnected() {
//std::cout << "OnHistoryDisconnected" << std::endl;
m_bConnected = false;
};
void BarHistory::OnHistorySendDone() {
//std::cout << "OnHistorySendDone" << std::endl;
m_fDone();
}
void BarHistory::OnHistoryIntervalData( Interval* pDP ) {
ou::tf::Bar bar( pDP->DateTime, pDP->Open, pDP->High, pDP->Low, pDP->Close, pDP->PeriodVolume );
m_fBar( bar );
ou::tf::iqfeed::HistoryQuery<BarHistory>::OnHistoryIntervalData( pDP );
}
void BarHistory::OnHistoryEndOfDayData( EndOfDay* pDP ) {
//std::cout << "OnHistoryEndOfDayData: " << pDP->Close << std::endl;
ou::tf::Bar bar( pDP->DateTime, pDP->Open, pDP->High, pDP->Low, pDP->Close, pDP->PeriodVolume );
m_fBar( bar );
ou::tf::iqfeed::HistoryQuery<BarHistory>::OnHistoryEndOfDayData( pDP );
};
void BarHistory::OnHistoryRequestDone( bool bStatus ) {
//std::cout << "OnHistoryRequestDone" << std::endl;
assert( bStatus );
m_fDone();
};
void BarHistory::OnHistoryError( size_t e ) {
std::cout << "BarHistory::OnHistoryError: " << e << std::endl;
};
void BarHistory::Disconnect() {
ou::tf::iqfeed::HistoryQuery<BarHistory>::Disconnect();
}
} // namespace iqfeed
} // namespace tf
} // namespace ou