-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplyhandler.cpp
More file actions
92 lines (76 loc) · 2.74 KB
/
replyhandler.cpp
File metadata and controls
92 lines (76 loc) · 2.74 KB
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
#include "replyhandler.h"
ReplyHandler::ReplyHandler(QObject *pobj): QObject(pobj)
{
reply_counter = 0;
}
void ReplyHandler::slotHandleReply()
{
QNetworkReply* reply = (QNetworkReply*)sender();
int current_timeframe = 0;
QString current_url = reply->url().toString();
current_timeframe = current_url.mid(current_url.lastIndexOf('=') + 1,
current_url.length() - current_url.lastIndexOf('=') - 1).toInt();
QString reply_data = reply->readAll();
if(reply_data.length() == 0)
{
reply->deleteLater();
if(++reply_counter == 5)
{
reply_counter = 0;
emit doItAgain();
}
qDebug() << current_url;
qDebug() << "request skipped";
return;
}
QJsonDocument jsonResponse = QJsonDocument::fromJson(reply_data.toUtf8());
QJsonObject jsonObject = jsonResponse.object();
QJsonObject quote_obj;
QString technicalSummary;
int quote = 0;
int maBuy = 0;
int maSell = 0;
int tiBuy = 0;
int tiSell = 0;
QJsonObject::iterator end = jsonObject.end();
end--;
for (QJsonObject::iterator it = jsonObject.begin(); it != end; it++)
{
quote = it.key().toInt();
quote_obj = it.value().toObject();
maBuy = quote_obj["maBuy"].toInt();
maSell = quote_obj["maSell"].toInt();
tiBuy = quote_obj["tiBuy"].toInt();
tiSell = quote_obj["tiSell"].toInt();
technicalSummary = quote_obj["technicalSummary"].toString();
QJsonObject json_obj;
json_obj.insert(QString("quote"), QJsonValue(QString::number(quote)));
json_obj.insert(QString("timeFrame"), QJsonValue(QString::number(current_timeframe)));
json_obj.insert(QString("technicalSummary"), QJsonValue(technicalSummary));
json_obj.insert(QString("maBuy"), QJsonValue(QString::number(maBuy)));
json_obj.insert(QString("maSell"), QJsonValue(QString::number(maSell)));
json_obj.insert(QString("tiBuy"), QJsonValue(QString::number(tiBuy)));
json_obj.insert(QString("tiSell"), QJsonValue(QString::number(tiSell)));
QJsonDocument doc(json_obj);
QString str_json(doc.toJson(QJsonDocument::Compact));
if(prev_data.contains(quote))
{
if(prev_data.value(quote) != str_json)
{
prev_data.insert(quote, str_json);
//Forvard data
}
}
else
{
prev_data.insert(quote, str_json);
//Forvard data
}
}
reply->deleteLater();
if(++reply_counter == 5)
{
reply_counter = 0;
emit doItAgain();
}
}