-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeed_csv.cpp
112 lines (97 loc) · 3.3 KB
/
feed_csv.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
#include "feed_csv.h"
#include <iostream>
#include <fstream>
#include <memory>
#include <sstream>
#include <string>
#include <vector>
#include <thread>
#include <chrono>
#include <algorithm>
#include <mutex>
#include <condition_variable>
#include <string_view>
#include <ranges>
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/classification.hpp>
#include "lob.h"
#include "strutils.h"
bool Mdl_Csv_Feed::init(const QJsonObject& settings) {
return true;
}
bool Mdl_Csv_Feed::start() {
stopped_.store(false);
thread1_ = std::thread([this]() {
std::cout << "thread1 start" << std::endl;
// std::this_thread::sleep_for(std::chrono::seconds(1));
std::string filename = config_.datadir + "/mdl_4.19.csv";
std::ifstream file(filename);
if (!file.is_open()) {
std::cerr << "Failed to open file: " << filename << std::endl;
return;
}
std::string line;
while (std::getline(file, line)) {
if (stopped_.load()) {
break;
}
if( config_.speed ){
// std::chrono::duration<double> duration(1/config_.speed);
std::this_thread::sleep_for(std::chrono::milliseconds( size_t(1000/config_.speed)));
}
symbolid_t symbolid;
lob_data_t* data = lob_data_alloc2( (char*)line.c_str(),line.size());
data->symbolid = symbolid;
data->user = (void*)"order";
onFeedRawData( data );
}
file.close();
std::cout << "thread1: mdl csv stopped" << std::endl;
});
thread2_ = std::thread([this]() {
std::cout << "thread2 start" << std::endl;
// std::this_thread::sleep_for(std::chrono::seconds(1));
std::string filename = config_.datadir + "/mdl_4.18.csv";
std::ifstream file(filename);
if (!file.is_open()) {
std::cerr << "Failed to open file: " << filename << std::endl;
return;
}
std::string line;
while (std::getline(file, line)) {
if (stopped_.load()) {
break;
}
if( config_.speed ){
// std::chrono::duration<double> duration(1/config_.speed);
std::this_thread::sleep_for(std::chrono::milliseconds( size_t(1000/config_.speed)));
}
symbolid_t symbolid;
lob_data_t* data = lob_data_alloc2( (char*)line.c_str(),line.size());
data->symbolid = symbolid;
data->user = (void*)"trade";
onFeedRawData( data );
}
file.close();
std::cout << "thread2: mdl csv stopped" << std::endl;
});
return true;
}
void Mdl_Csv_Feed::stop() {
stopped_.store(true);
thread1_.join();
thread2_.join();
}
Message* Mdl_Csv_Feed::DataDecoder::decode( lob_data_t * data)
{
Message * msg = nullptr;
if( data->user == (void*)"order"){
auto ss = lobutils::splitString( std::string(data->data, data->len),',');
auto ordmsg = new OrderMessage();
ordmsg->SecurityID = boost::lexical_cast<uint32_t>(ss[3]);
msg = ordmsg;
}
return msg ;
}