-
Notifications
You must be signed in to change notification settings - Fork 0
/
BitcoinMarketInfo.cpp
103 lines (81 loc) · 2.61 KB
/
BitcoinMarketInfo.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
#include "BitcoinMarketInfo.hpp"
using std::cout;
using std::endl;
using std::string;
BitcoinMarketInfo::BitcoinMarketInfo() {
high = 0.0;
low = 0.0;
vol = 0.0;
last = 0.0;
buy = 0.0;
sell = 0.0;
date = 0;
serviceURL = TICKER_LITECOIN;
}
void BitcoinMarketInfo::setHigh(double high){
this->high = high;
}
void BitcoinMarketInfo::setLow(double low){
this->low = low;
}
void BitcoinMarketInfo::setVol(double vol){
this->vol = vol;
}
void BitcoinMarketInfo::setLast(double last){
this->last = last;
}
void BitcoinMarketInfo::setBuy(double buy){
this->buy = buy;
}
void BitcoinMarketInfo::setSell(double sell){
this->sell = sell;
}
void BitcoinMarketInfo::setDate(int date){
this->date = date;
}
string BitcoinMarketInfo::toString(){
std::stringstream ss;
ss << "BitcoinMarketInfo\n";
ss << "High: " << this->high << "\n";
ss << "Low: " << this->low << "\n";
ss << "Vol: " << this->vol << "\n";
ss << "Last: " << this->last << "\n";
ss << "Buy: " << this->buy << "\n";
ss << "Sell: " << this->sell << "\n";
ss << "Date: " << this->date;
return ss.str();
}
int BitcoinMarketInfo::getBitcoinMarketInfo() {
Curly curly;
Json::Value retJSON;
if (curly.Fetch(this->serviceURL) == CURLE_OK){
if (curly.HttpStatus() != 200) {
return FAIL;
}
retJSON = curly.getContentJSON();
//std::cout << "status: " << curly.HttpStatus() << std::endl;
//std::cout << "type: " << curly.Type() << std::endl;
//std::vector<std::string> headers = curly.Headers();
//for(std::vector<std::string>::iterator it = headers.begin();
// it != headers.end(); it++)
// std::cout << "Header: " << (*it) << std::endl;
if (!retJSON.empty()) {
this->setBuy(retJSON.get("ticker", "" ).get("buy", "" ).asDouble());
this->setDate(retJSON.get("ticker", "" ).get("date", "" ).asInt());
this->setHigh(retJSON.get("ticker", "" ).get("high", "" ).asDouble());
this->setLast(retJSON.get("ticker", "" ).get("last", "" ).asDouble());
this->setLow(retJSON.get("ticker", "" ).get("low", "" ).asDouble());
this->setVol(retJSON.get("ticker", "" ).get("vol", "" ).asDouble());
this->setSell(retJSON.get("ticker", "" ).get("sell", "" ).asDouble());
return SUCCESS;
}
}
return FAIL;
}
int main(void) {
BitcoinMarketInfo bitcoinMarketInfo;
if (bitcoinMarketInfo.getBitcoinMarketInfo() == SUCCESS) {
cout << bitcoinMarketInfo.toString() << endl;
}
return 0;
}