-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
130 lines (119 loc) · 4.07 KB
/
main.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
#include <iterator>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
#include <map>
// #include "rapidcsv.h"
#include "csv.hpp"
#include "features.h"
using namespace csv;
using namespace std;
std::vector<int> parse_array(const string &strArray)
{
auto substr = strArray.substr(1, strArray.size() - 2);
stringstream s_stream(substr);
vector<int> res;
while (s_stream.good())
{
string valStr;
getline(s_stream, valStr, ',');
if (!valStr.empty())
res.push_back(std::stoi(valStr));
}
return res;
}
std::string secId2vtSymbol(int secId){
std::stringstream secStr;
secStr << setw(6) << setfill('0') << secId;
if(secStr.str().substr(0,1) == "0" || secStr.str().substr(0,1) == "3")
{
return secStr.str() + ".SZSE";
}else
{
return secStr.str() + ".SSE";
}
}
void parseEquityTrade(CSVRow &row, EquityTrade &trade)
{
auto trade_bs_flag = row["trade_bs_flag"].get<std::string>();
if(trade_bs_flag =="B" || trade_bs_flag == "S")
{
auto securityid = row["securityid"].get<int>();
trade.vt_symbol = secId2vtSymbol(securityid);
trade.trade_price = row["trade_price"].get<int>() / 10000.;
trade.trade_volume = row["trade_volume"].get<int>();
trade.trade_bs_flag = trade_bs_flag;
trade.date = row["date"].get<size_t>();
trade.time = row["time"].get<size_t>();
}
}
// int main(){
// CSVReader reader("d:\\temp_data\\hq-szl2-000001-tick-20201012152258606.csv");
// for (CSVRow& row: reader) { // Input iterator
// // for (CSVField& field: row) {
// // // By default, get<>() produces a std::string.
// // // A more efficient get<string_view>() is also available, where the resulting
// // // string_view is valid as long as the parent CSVRow is alive
// // std::cout << field.get<string_view>() << endl;
// // }
// auto bid_prices = row["bid_prices"].get<string>();
// auto bpArray = parse_array(bid_prices);
// std::cout << bid_prices << endl;
// std::cout << bpArray[0] << endl;
// }
// return 0;
// }
// int main(){
// auto n = minuteByFreq("5m",93143000);
// cout << n << endl;
// }
int main()
{
CSVReader reader("d:\\temp_data\\rq-szl2-000001-trade-20200720152226418.csv");
EquityFeatures ef;
FeatureParams fparams;
string vt_symbol = "000001.SZSE";
fparams.freq = "1m";
ef.setParams(fparams);
int i = 0;
for (CSVRow &row : reader)
{ // Input iterator
// for (CSVField& field: row) {
// // By default, get<>() produces a std::string.
// // A more efficient get<string_view>() is also available, where the resulting
// // string_view is valid as long as the parent CSVRow is alive
// std::cout << field.get<string_view>() << endl;
// }
i+=1;
EquityTrade trade;
parseEquityTrade(row, trade);
if(trade.trade_volume!=0)
{
//printf("|vt_symbol:%s|date:%zd|time:%zd|\n", trade.vt_symbol.c_str(),trade.date, trade.time);
ef.onTrade(trade);
}
if(i%100 == 0){
auto vec = ef.getBars(vt_symbol);
// std::cout << vec.size()<< std::endl;
// std::cout << vec.back()->date<< std::endl;
if(vec.empty()){
continue;
}
// auto bar = vec.back();
// printf("|date: %zd|time: %zd|minute: %zd|UptickVolume:%zd|DowntickVolume:%zd|RepeatUptickVolume:%zd|RepeatDowntickVolume:%zd|total:%zd|\n",
// bar->date, bar->time, bar->minute,bar->UptickVolume,bar->DowntickVolume,
// bar->RepeatUptickVolume,
// bar->RepeatDowntickVolume,
// bar->totalVolume
// );
}
}
for(EquityMinuteBarPtr ptr: ef.getBars(vt_symbol))
{
std::cout <<ptr->vt_symbol << ' ' << ptr->RepeatDowntickVolume << ' ' << std::endl;
};
return 0;
}