-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathHistoryRequest.cpp
87 lines (77 loc) · 2.7 KB
/
HistoryRequest.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
/************************************************************************
* 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.cpp
* Author: [email protected]
* Project: lib/TFIQFeed
* Created 2021/09/06 21:09
*/
#include "BarHistory.h"
#include "HistoryRequest.h"
namespace ou {
namespace tf {
namespace iqfeed {
HistoryRequest::HistoryRequest(
fConnected_t&& fConnected
)
: m_bInProcess( false ),
m_fConnected( std::move( fConnected ) )
{
m_pHistory = std::make_unique<BarHistory>(
[this](){ // fConnected_t
m_fConnected();
},
[this]( const ou::tf::Bar& bar ){ // fBar_t
m_entryCurrent.fBar( bar );
},
[this](){ // fDone_t
m_entryCurrent.fDone();
std::scoped_lock lock( m_mutexHistorySlots );
if ( 0 != m_vEntry.size() ) {
NextRequest( std::move( m_vEntry.back() ) );
m_vEntry.pop_back();
}
else {
m_bInProcess = false;
m_entryCurrent.Clear();
}
}
);
//m_pHistory->Connect(); // start the process // commented out as it turns around faster than it is constructed
}
HistoryRequest::~HistoryRequest() {
m_pHistory->Disconnect();
}
void HistoryRequest::Connect() {
m_pHistory->Connect();
}
void HistoryRequest::Request( const std::string& sSymbol_, uint16_t nBar, fBar_t&& fBar, fDone_t&& fDone ) {
const std::string sSymbol( sSymbol_ );
Entry entry( std::move( sSymbol ), nBar, std::move( fBar ), std::move( fDone ) );
std::scoped_lock lock( m_mutexHistorySlots );
if ( m_bInProcess ) {
m_vEntry.emplace_back( std::move( entry ) );
}
else {
m_bInProcess = true;
NextRequest( std::move( entry ) );
}
}
void HistoryRequest::NextRequest( Entry&& entry ) {
m_entryCurrent = std::move( entry );
m_pHistory->RequestNEndOfDay( m_entryCurrent.sSymbol, m_entryCurrent.nBar );
}
} // namespace iqfeed
} // namespace tf
} // namespace ou