-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignalClass.cpp
109 lines (75 loc) · 1.95 KB
/
signalClass.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
#include <string.h>
#include <iostream>
#include <string>
#include <boost/bind.hpp>
#include <boost/signals2.hpp>
#include <vector>
#include <curl/curl.h>
#include "httpClass.cpp"
#include <boost/algorithm/string.hpp>
std::string JSONParser(std::string Val);
class Subject
{
public:
CURLplusplus client;
std::string BTC = "";
std::string ETH = "";
std::string DOGE = "";
void init()
{
BTC = client.Get("https://api.binance.com/api/v3/ticker/price?symbol=BTCUSDT");
ETH = client.Get("https://api.binance.com/api/v3/ticker/price?symbol=ETHUSDT");
DOGE = client.Get("https://api.binance.com/api/v3/ticker/price?symbol=DOGEUSDT");
}
std::string getBTC() const
{
return JSONParser(BTC);
}
std::string getETH() const
{
return JSONParser(ETH);
}
std::string getDOGE() const
{
return JSONParser(DOGE);
}
void setBTC()
{
std::string newBTC = client.Get("https://api.binance.com/api/v3/ticker/price?symbol=BTCUSDT");
if (BTC != newBTC)
{
BTC = newBTC;
sleep(0.5);
BTCsignal(newBTC);
}
}
void setETH()
{
std::string newETH = client.Get("https://api.binance.com/api/v3/ticker/price?symbol=ETHUSDT");
if (ETH != newETH)
{
ETH = newETH;
sleep(1);
ETHsignal(ETH);
}
}
void setDOGE()
{
std::string newDOGE = client.Get("https://api.binance.com/api/v3/ticker/price?symbol=DOGEUSDT");
if (DOGE != newDOGE)
{
DOGE = newDOGE;
sleep(0.5);
DOGEsignal(newDOGE);
}
}
boost::signals2::signal<void(const std::string &btcVal)> BTCsignal;
boost::signals2::signal<void(const std::string ðVal)> ETHsignal;
boost::signals2::signal<void(const std::string &dogeVal)> DOGEsignal;
};
std::string JSONParser(std::string Val){
std::vector<std::string> results;
boost::algorithm::split(results, Val, boost::is_any_of("\""));
std::string body = results[3]+ " " + results[7];
return body;
}