-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientReportGenerator.java
More file actions
44 lines (38 loc) · 1.71 KB
/
Copy pathClientReportGenerator.java
File metadata and controls
44 lines (38 loc) · 1.71 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
import java.io.FileWriter;
import java.io.IOException;
import java.util.*;
public class ClientReportGenerator {
public static HashMap<String, HashMap<String, Double>> rows = new HashMap<String, HashMap<String, Double>>();
public static void addClientPosition(String clientID, String instrumentId, double netPosition) {
HashMap<String, Double> inner;
if (!ClientReportGenerator.rows.containsKey(clientID)) {
inner = new HashMap<String, Double> ();
ClientReportGenerator.rows.put(clientID, inner);
} else {
inner = ClientReportGenerator.rows.get(clientID);
}
inner.put(instrumentId, netPosition);
}
public static void generateCSVFile() {
try (FileWriter csvWriter = new FileWriter("C:\\Users\\USER\\Documents\\BOFA\\CodeToConnect2024\\output_client_report.csv")) {
// Write header row
csvWriter.append("Client Id,Instrument ID,Net Position\n");
// Write data row
for (HashMap.Entry<String, HashMap<String, Double>> outer : rows.entrySet()) {
for (HashMap.Entry<String, Double> inner : outer.getValue().entrySet()) {
csvWriter.append(outer.getKey()).append(",").append(inner.getKey()).append(",").append(String.valueOf(inner.getValue())).append("\n");
}
}
// Close the csvWriter to save the data
csvWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
// ExchangeReportGenerator.addFailedPolicy("D1" ,"REJECTED – MISMATCH CURRENCY");
// ExchangeReportGenerator.addFailedPolicy("B2" ,"REJECTED – INVALID LOT SIZE");
// ExchangeReportGenerator.addFailedPolicy("C2" ,"REJECTED – POSITION CHECK FAILED");
// ExchangeReportGenerator.generateCSVFile();
}
}