-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransaction_types.cpp
90 lines (83 loc) · 3.7 KB
/
transaction_types.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
//
// Created by Saeid Yazdani on 10/2/2024.
//
#include <unordered_map>
#include <algorithm>
#include <stdexcept>
#include <embedonix/simplelibs/stringtools/trim.h>
#include "transaction_types.h"
namespace embedonix::trading_tax_calculator {
std::string
transactionTypeToString(TransactionType transaction) {
switch (transaction) {
case TransactionType::Unknown:
return "Unknown";
case TransactionType::Trade:
return "Trade";
case TransactionType::Correction:
return "Correction";
case TransactionType::Swap:
return "Swap";
case TransactionType::Dividend:
return "Dividend";
case TransactionType::Deposit:
return "Deposit";
case TransactionType::Transfer:
return "Transfer";
case TransactionType::Withdrawal:
return "Withdrawal";
case TransactionType::Adjustment:
return "Adjustment";
case TransactionType::Commision:
return "Commision";
case TransactionType::Settlement:
return "Settlement";
default:
throw std::invalid_argument("Invalid TransactionType");
}
}
TransactionType
stringToTransactionType(const std::string& transactionString) {
// Convert input string to lowercase
std::string lowerCaseTransaction = transactionString;
embedonix::simplelibs::stringtools::trim::both_sides(lowerCaseTransaction);
std::transform(lowerCaseTransaction.begin(), lowerCaseTransaction.end(),
lowerCaseTransaction.begin(), ::tolower);
static const std::unordered_map<std::string, TransactionType>
transactionMap = {
{"unknown", TransactionType::Unknown},
{"void", TransactionType::Unknown},
{"trade", TransactionType::Trade},
{"buy", TransactionType::Trade},
{"sell", TransactionType::Trade},
{"swap", TransactionType::Swap},
{"exchange", TransactionType::Swap},
{"overnightfee", TransactionType::Swap},
{"weekendovernightfee", TransactionType::Swap},
{"corporate_action", TransactionType::Dividend},
{"dividend", TransactionType::Dividend},
{"dividends", TransactionType::Dividend},
{"deposit", TransactionType::Deposit},
{"withdrawal", TransactionType::Withdrawal},
{"withdraw", TransactionType::Withdrawal},
{"transfer", TransactionType::Transfer},
{"move", TransactionType::Transfer},
{"send", TransactionType::Transfer},
{"receive", TransactionType::Transfer},
{"adjustment", TransactionType::Adjustment},
{"adjustments", TransactionType::Adjustment},
{"cash_adjustment_commodities", TransactionType::Adjustment},
{"trade_correction", TransactionType::Correction},
{"trade_commission_gsl", TransactionType::Correction},
{"settlement", TransactionType::Settlement},
{"complaint_settlement", TransactionType::Settlement}
};
auto it = transactionMap.find(lowerCaseTransaction);
if (it != transactionMap.end()) {
return it->second;
} else {
throw std::invalid_argument("Invalid transaction type string: "
+ transactionString);
}
}
}