-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
send_email.cpp
69 lines (59 loc) · 3.1 KB
/
send_email.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
#include "send_email.h"
#include "time_fun.h"
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <math.h>
#include <iomanip>
#include <unistd.h>
void sendEmail(Result res, Parameters params) {
char tdStyle[] = "font-family:Georgia;font-size:11px;border-color:#A1A1A1;border-width:1px;border-style:solid;padding:2px;";
char captionStyle[] = "font-family:Georgia;font-size:13px;font-weight:normal;color:#0021BF;padding-bottom:6px;text-align:left;";
char tableTitleStyle[] = "font-family:Georgia;font-variant:small-caps;font-size:13px;text-align:center;border-color:#A1A1A1;border-width:1px;border-style:solid;background-color:#EAEAEA;";
std::ostringstream oss;
oss.precision(2);
oss << std::fixed;
oss << "sendemail -f " << params.senderAddress << " -t " << params.receiverAddress << " -u \"Blackbird Bitcoin Arbitrage - Trade " << res.id <<" (";
if (res.totPerf() >= 0) {
oss << "+" << res.totPerf() * 100;
}
else {
oss << res.totPerf() * 100;
}
oss << "%)\" -m \"";
oss << "<html>";
oss << " <div>";
oss << " <br/><br/>";
oss << " <table style=\\\"border-width:0px;border-collapse:collapse;text-align:center;\\\">";
oss << " <caption style=\\\"" << captionStyle << "\\\">Blackbird Bitcoin Arbitrage - Trade " << res.id << "</caption>";
oss << " <tr style=\\\"" << tableTitleStyle << "\\\">";
oss << " <td style=\\\"" << tdStyle << "width:120px;\\\">Entry Date</td>";
oss << " <td style=\\\"" << tdStyle << "width:120px;\\\">Exit Date</td>";
oss << " <td style=\\\"" << tdStyle << "width:70px;\\\">Long</td>";
oss << " <td style=\\\"" << tdStyle << "width:70px;\\\">Short</td>";
oss << " <td style=\\\"" << tdStyle << "width:70px;\\\">Exposure</td>";
oss << " <td style=\\\"" << tdStyle << "width:70px;\\\">Profit</td>";
oss << " <td style=\\\"" << tdStyle << "width:70px;\\\">Return</td>";
oss << " </tr>";
oss << " <tr>";
oss << " <td style=\\\"" << tdStyle << "\\\">" << printDateTime(res.entryTime) << "</td>";
oss << " <td style=\\\"" << tdStyle << "\\\">" << printDateTime(res.exitTime) << "</td>";
oss << " <td style=\\\"" << tdStyle << "\\\">" << res.exchNameLong << "</td>";
oss << " <td style=\\\"" << tdStyle << "\\\">" << res.exchNameShort << "</td>";
oss << " <td style=\\\"" << tdStyle << "\\\">\\$" << res.exposure * 2.0 << "</td>";
oss << " <td style=\\\"" << tdStyle << "\\\">\\$" << res.aftBalUsd - res.befBalUsd << "</td>";
if (res.totPerf() >= 0) {
oss << "<td style=\\\"" << tdStyle << "color:#000092;\\\">+";
}
else {
oss << "<td style=\\\"" << tdStyle << "color:#920000;\\\">";
}
oss << res.totPerf() * 100 << "%</td></tr>";
oss << " </table>";
oss << " </div>";
oss << "</html>\" -s " << params.smtpServerAddress << " -xu " << params.senderUsername << " -xp " << params.senderPassword << " -o tls=yes -o message-content-type=html >/dev/null" << std::endl;
oss.flush();
if (system(oss.str().c_str()) == -1) {
std::cout << "Error with system call" << std::endl;
}
}