-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
160 lines (149 loc) · 2.82 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//
// main.cpp
// itch4Parser
//
// Created by Dylan Hurd on 11/3/13.
// Copyright (c) 2013 Dylan Hurd. All rights reserved.
//
#include <iostream>
#include <fstream>
#include <vector>
#include "Message.cpp"
using namespace std;
int main(int argc, const char * argv[])
{
std::ios_base::sync_with_stdio(false);
if(argc != 3) {
cerr << "Incorrect number of args\n";
cerr << "Correct usage: ./itch4parser [input file] [output file]";
return 1;
}
// Opening input file in binary mode
ifstream input(argv[1], ios::in );
if(!input.is_open()){
cerr << "Error opening input file";
return 1;
}
ofstream output(argv[2], ios::out | ios::trunc);
if(!output.is_open()){
cerr << "Error opening output file";
return 1;
}
char c;
TimeStamp ts;
while(input.good()){
input >> c;
//determine message type, add to vector
if(c == 'T') {
input >> ts;
}
else if(c == 'S'){
Message o;
o.ts = ts;
input >> o;
output << o;
}
else if(c == 'R'){
StockDirectory o;
o.ts = ts;
input >> o;
output << o;
}
else if(c == 'H'){
StockTradingAction o;
o.ts = ts;
input >> o;
output << o;
}
else if(c == 'Y'){
ShortSalePriceTest o;
o.ts = ts;
input >> o;
output << o;
}
else if(c == 'L'){
MarketParticipantPosition o;
o.ts = ts;
input >> o;
output << o;
}
else if(c == 'A'){
AddOrder o;
o.ts = ts;
input >> o;
output << o;
}
else if(c == 'F'){
AddMPIDOrder o;
o.ts = ts;
input >> o;
output << o;
}
else if(c == 'E'){
ExecutedOrder o;
o.ts = ts;
input >> o;
output << o;
}
else if(c == 'C'){
ExecutedPriceOrder o;
o.ts = ts;
input >> o;
output << o;
}
else if(c == 'X'){
CancelOrder o;
o.ts = ts;
input >> o;
output << o;
}
else if(c == 'D'){
DeleteOrder o;
o.ts = ts;
input >> o;
output << o;
}
else if(c == 'U'){
ReplaceOrder o;
o.ts = ts;
input >> o;
output << o;
}
else if(c == 'P'){
TradeMessage o;
o.ts = ts;
input >> o;
output << o;
}
else if(c == 'Q'){
CrossTradeMessage o;
o.ts = ts;
input >> o;
output << o;
}
else if(c == 'B'){
BrokenTrade o;
o.ts = ts;
input >> o;
output << o;
}
else if(c == 'I'){
NetOrderImbalance o;
o.ts = ts;
input >> o;
output << o;
}
else if(c == 'N'){
RetailPriceImprovement o;
o.ts = ts;
input >> o;
output << o;
}
else {
//cerr << "Error in reading input\n";
continue;
}
}
cerr << "Finished reading\n";
return 0;
}