-
Notifications
You must be signed in to change notification settings - Fork 0
/
shared.h
169 lines (146 loc) · 5.02 KB
/
shared.h
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
160
161
162
163
164
165
166
167
168
/*
Copyright (©) 2017-2017 Teus Benschop.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef INCLUDED_SHARED_H
#define INCLUDED_SHARED_H
#include "libraries.h"
#ifdef HAVE_EXECINFO
#include <execinfo.h>
#endif
extern string program_path;
void initialize_program (int argc, char *argv[]);
void finalize_program ();
int seconds_since_epoch ();
int minutes_since_epoch ();
string timestamp ();
int seconds_within_minute ();
int minutes_within_hour ();
int hours_within_day ();
int get_numerical_year (int seconds);
int get_numerical_month (int seconds);
int get_numerical_month_day (int seconds);
int get_seconds_since_epoch (int year, int month, int day);
long milliseconds_since_epoch ();
string http_call (const string & url,
string& error,
const string & proxy,
bool verbose,
bool post, const string & postdata,
const vector <pair <string, string> > & headers,
bool hurry, bool persist,
const string & interface);
string base64_encode (const string &binary);
string base64_decode (const string &ascii);
string url_encode (const string &value);
string hmac_sha512_raw (string key_in, string data_in);
string hmac_sha512_hexits (string key_in, string data_in);
string hmac_sha384_hexits (string key_in, string data_in);
string hmac_sha256_raw (string key_in, string data_in);
string md5_raw (string data);
string sha256_raw (const string& data);
string sha256_hexits (const string& data);
string str_replace (string search, string replace, string subject);
string str2lower (string value);
string str2upper (string value);
bool str2bool (string value);
bool is_float (string value);
string float2string (float value, int precision = 10);
string float2visual (float value);
float str2float (const string & s);
int str2int (const string & s);
void to_tty (vector <string> fragments);
void to_stdout (vector <string> fragments, bool lock = true);
class to_output
{
public:
to_output (string tag);
~to_output ();
void add (vector <string> fragments);
void to_stderr (bool on);
void clear ();
void failure (const string & type, const vector <string> & fragments);
private:
string mytag;
string plaintag;
vector <vector <string> > myfragments;
bool send2stderr;
bool stamp;
};
void to_stderr (vector <string> fragments, bool stamp = true);
class to_email
{
public:
to_email (string subject);
~to_email ();
void add (vector <string> fragments);
private:
string mysubject;
string mycontents;
};
void to_failures (string type, string exchange, string coin, float quantity, vector <string> fragments);
string bitcoin_id ();
string litecoin_id ();
string ethereum_id ();
string dogecoin_id ();
string usdollar_id ();
string ripple_id ();
string verge_id ();
string bitcoincash_id ();
string usdtether_id ();
string newzealanddollartoken_id ();
string euro_id ();
string waves_id ();
string russianrubble_id ();
string monero_id ();
string dirname (string path);
string basename (string path);
void file_put_contents (string filename, string contents);
string file_get_contents (string filename);
bool file_or_dir_exists (const string & path);
int filesize (const string & filename);
string implode (vector <string>& values, string delimiter);
vector <string> explode (string value, char delimiter);
string increasing_nonce ();
template <typename T>
bool in_array (const T & needle, const vector <T> & haystack)
{
return (find (haystack.begin(), haystack.end(), needle) != haystack.end());
}
template <typename T>
vector <T> array_intersect (vector <T> a, vector <T> b)
{
vector <T> result;
set <T> aset (a.begin(), a.end());
for (auto & item : b) {
if (aset.find (item) != aset.end()) {
result.push_back (item);
}
}
return result;
}
void api_call_sequencer (atomic <long> & sequencer);
string string_fill (string s, int width, char filler);
bool program_running (char *argv[]);
int satellite_port ();
string satellite_request (const string & host, string request, bool hurry, string& error);
void plot (const vector <pair <float, float> > & data1,
const vector <pair <float, float> > & data2,
const string & title1, const string & title2,
string & picturepath);
string trade_order_fulfilled ();
bool has_floats_only (const string & line);
string hostname ();
float get_percentage_change (float oldvalue, float newvalue);
bool running_within_minute ();
#endif