-
Notifications
You must be signed in to change notification settings - Fork 0
/
orderapi.cpp
55 lines (45 loc) · 1.17 KB
/
orderapi.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
#include "orderapi.h"
OrderApi::OrderApi(QObject *parent) :
HashTockApi("http://hashtock.appspot.com/api/order/", parent)
{
}
void OrderApi::buy(QString hashtag, float quantity, bool from_bank)
{
QJsonObject post_data;
post_data["action"] = "buy";
post_data["bank_order"] = from_bank;
post_data["hashtag"] = hashtag;
post_data["quantity"] = quantity;
sendData(QJsonDocument(post_data));
}
void OrderApi::cancel(QString uuid)
{
deleteData(uuid);
}
QJsonDocument OrderApi::deletedResource(QUrl req)
{
QJsonObject obj;
QString url = req.url();
url = url.remove(endpoint());
QStringList parts = url.split("/", QString::SkipEmptyParts);
if (parts.size() == 1) {
obj["id"] = parts.first();
}
return QJsonDocument(obj);
}
void OrderApi::dataSent(QJsonDocument data)
{
setUpToDate(false);
m_msg->consumeEvent(Messenger::OrderAdded, data);
}
void OrderApi::dataDeleted(QJsonDocument data)
{
setUpToDate(false);
m_msg->consumeEvent(Messenger::OrderCanceled, data);
}
void OrderApi::msgEvent(Messenger::MessageType msg, QJsonDocument data)
{
if (msg == Messenger::OrderAdded) {
emit dataReady(data);
}
}