-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathbitcoin.cpp
139 lines (112 loc) · 2.35 KB
/
bitcoin.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
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
#include "bitcoin.h"
#include <math.h>
Bitcoin::Bitcoin(unsigned i, std::string n, double f, bool h) {
id = i;
exchName = n;
fees = f;
hasShort = h;
std::vector<time_t> *d = new std::vector<time_t>;
std::vector<double> *b = new std::vector<double>;
std::vector<double> *a = new std::vector<double>;
std::vector<double> *v = new std::vector<double>;
datetime = d;
bid = b;
ask = a;
volume = v;
}
Bitcoin::Bitcoin(unsigned i, std::string n, double f, bool h, std::vector<time_t> *dt, std::vector<double> *b, std::vector<double> *a, std::vector<double> *v) {
id = i;
exchName = n;
fees = f;
hasShort = h;
datetime = dt;
bid = b;
ask = a;
volume = v;
}
Bitcoin::~Bitcoin() {
delete(datetime);
delete(bid);
delete(ask);
delete(volume);
}
void Bitcoin::addData(time_t d, double b, double a, double v) {
datetime->push_back(d);
bid->push_back(b);
ask->push_back(a);
volume->push_back(v);
}
void Bitcoin::removeLastData() {
bid->pop_back();
ask->pop_back();
volume->pop_back();
}
unsigned Bitcoin::getId() const {
return id;
}
time_t Bitcoin::getLastTime_t() const {
return datetime->back();
}
time_t Bitcoin::getTime_t(int i) const {
return (*datetime)[i];
}
std::vector<time_t> Bitcoin::getDatetime() const {
return *datetime;
}
int Bitcoin::getDatetimeSize() const {
return datetime->size();
}
double Bitcoin::getBid(int i) const {
return (*bid)[i];
}
std::vector<double> Bitcoin::getBid() const {
return *bid;
}
double Bitcoin::getLastBid() const {
if (bid->empty()) {
return 0;
}
else {
return bid->back();
}
}
double Bitcoin::getAsk(int i) const {
return (*ask)[i];
}
std::vector<double> Bitcoin::getAsk() const {
return *ask;
}
double Bitcoin::getLastAsk() const {
if (ask->empty()) {
return 0;
}
else {
return ask->back();
}
}
double Bitcoin::getPrice(int i) const {
return ((*bid)[i] + (*ask)[i]) / 2;
}
double Bitcoin::getLastPrice() const {
if (bid->empty() || ask->empty()) {
return 0;
}
else {
return (bid->back() + ask->back()) / 2;
}
}
double Bitcoin::getVolume(int i) const {
return (*volume)[i];
}
std::vector<double> Bitcoin::getVolume() const {
return *volume;
}
std::string Bitcoin::getExchName() const {
return exchName;
}
double Bitcoin::getFees() const {
return fees;
}
bool Bitcoin::getHasShort() const {
return hasShort;
}