-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwritefile.cpp
More file actions
95 lines (72 loc) · 2.52 KB
/
Copy pathwritefile.cpp
File metadata and controls
95 lines (72 loc) · 2.52 KB
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
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
#include <chrono>
#include <ctime>
#include <iomanip>
#include <Windows.h>
#include "headers/writefile.h"
using namespace std;
fstream fout("reportcard.csv", ios::out | ios::app);
string getCurrentDateTime() {
// Get the current time
auto now = chrono::system_clock::now();
// Convert the current time to a time_t object
time_t time = chrono::system_clock::to_time_t(now);
// Convert the time_t object to a tm struct
tm* tm = localtime(&time);
// Format the date and time
ostringstream oss;
oss << put_time(tm, "%Y%m%d-%H%M%S");
// Get the milliseconds part of the current time
auto ms = chrono::duration_cast<chrono::milliseconds>(now.time_since_epoch()) % 1000;
// Append the milliseconds to the formatted date and time
oss << "." << setfill('0') << setw(3) << ms.count();
// Return the formatted date and time as a string
return oss.str();
}
string getCurrentDateTime_win()
{
SYSTEMTIME st;
GetLocalTime(&st);
char dateTime[20];
sprintf_s(dateTime, "%04d%02d%02d-%02d%02d%02d.%03d", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
return string(dateTime);
}
void writeLine(string orderId, string &clientId, int &instrument, int &side, int status, int &qty, double &price)
{
static const vector<string> state = { "New", "Rejected", "Fill", "Pfill" };
static const vector<string> instruments = { "Rose", "Lavender", "Lotus", "Tulip", "Orchid" };
// Insert the data to file
fout << orderId << ","
<< clientId << ","
<< instruments[instrument] << ","
<< side << ","
<< state[status] << ","
<< qty << ","
<< price << ","
<< getCurrentDateTime()
<< "\n";
}
void writeInvalidLine(string orderId, string &clientId, string &instrument, int &side, int &qty, double &price, vector<string>& invalidReasons)
{
static string state = "Rejected";
string reasons;
for (const string& reason : invalidReasons) {
reasons += reason + " | ";
}
reasons = reasons.substr(0, reasons.size() - 3);
// Insert the data to file
fout << orderId << ","
<< clientId << ","
<< instrument << ","
<< side << ","
<< state << ","
<< qty << ","
<< price << ","
<< reasons << ","
<< getCurrentDateTime()
<< "\n";
}