-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathHistoryRequest.h
111 lines (84 loc) · 2.96 KB
/
HistoryRequest.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
/************************************************************************
* Copyright(c) 2021, 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. *
************************************************************************/
/*
* File: HistoryRequest.h
* Author: [email protected]
* Project: lib/TFIQFeed
* Created 2021/09/06 21:09
*/
#include <mutex>
#include <string>
#include <functional>
#include <TFTimeSeries/TimeSeries.h>
// HistoryRequest allows queuing up multiple DailyHistory requests
namespace ou {
namespace tf {
namespace iqfeed {
class BarHistory;
class HistoryRequest {
public:
using pHistoryRequest_t = std::unique_ptr<HistoryRequest>;
using fConnected_t = std::function<void()>;
using fBar_t = std::function<void(const ou::tf::Bar&)>;
using fDone_t = std::function<void()>;
HistoryRequest( fConnected_t&& fConnected );
~HistoryRequest();
static pHistoryRequest_t Construct( fConnected_t&& fConnected ) {
return std::make_unique<HistoryRequest>(
std::move( fConnected )
);
}
void Connect();
void Request( const std::string& sSymbol_, uint16_t nBar, fBar_t&& fBar, fDone_t&& fDone );
protected:
private:
fConnected_t m_fConnected;
std::mutex m_mutexHistorySlots;
std::unique_ptr<BarHistory> m_pHistory;
bool m_bInProcess;
struct Entry {
std::string sSymbol;
uint16_t nBar;
fBar_t fBar;
fDone_t fDone;
Entry() {}
Entry( Entry&& rhs )
: fBar( std::move( rhs.fBar ) ), fDone( std::move( rhs.fDone ) )
, sSymbol( std::move( rhs.sSymbol ) ), nBar( rhs.nBar )
{}
Entry& operator=( Entry&& rhs ) {
sSymbol = std::move( rhs.sSymbol );
nBar = rhs.nBar;
fBar = std::move( rhs.fBar );
fDone = std::move( rhs.fDone );
return *this;
}
Entry( const std::string&& sSymbol_, uint16_t nBar_, fBar_t&& fBar_, fDone_t&& fDone_ )
: sSymbol( std::move( sSymbol_ ) ), nBar( nBar_ )
, fBar( std::move( fBar_ ) ), fDone( std::move( fDone_ ) )
{}
void Clear() {
sSymbol.clear();
fBar = nullptr;
fDone = nullptr;
}
};
using vEntry_t = std::vector<Entry>;
vEntry_t m_vEntry;
Entry m_entryCurrent;
void NextRequest( Entry&& entry );
};
} // namespace iqfeed
} // namespace tf
} // namespace ou