#pragma once
|
#include <string>
|
#include "../common/NetworkApi.h"
|
#include "../common/JsonUtil.h"
|
#include "DataStruct.h"
|
class MyApi {
|
|
public:
|
static list<SellRule> listSellRules() {
|
string result = NetworkApi::list_sell_rules();
|
auto doc = JsonUtil::parseUTF16(result);
|
if (doc.IsObject()) {
|
if (doc[L"code"].GetInt() == 0) {
|
auto array = doc[L"data"].GetArray();
|
list<SellRule> rules;
|
for (int i = 0; i < array.Size(); i++) {
|
SellRule rule;
|
rule.code = array[i][L"code"].GetString();
|
rule.id_ = array[i][L"id_"].GetString();
|
rule.buy1_volume = array[i][L"buy1_volume"].GetInt() / 100;
|
rule.buy1_price = array[i][L"buy1_price"].GetString();
|
rule.sell_volume = array[i][L"sell_volume"].GetInt();
|
rule.sell_price_type = array[i][L"sell_price_type"].GetInt();
|
rule.create_time = array[i][L"create_time"].GetString();
|
rule.excuted = array[i][L"excuted"].GetInt();
|
rule.end_time = array[i][L"end_time"].GetString();
|
rule.type = array[i][L"type"].GetInt();
|
rules.push_back(rule);
|
}
|
return rules;
|
}
|
else {
|
throw CString(doc[L"msg"].GetString());
|
}
|
}
|
else {
|
throw CString("ÍøÂçÇëÇó³ö´í");
|
}
|
}
|
|
static Buy1Info getBuy1Info(string code) {
|
string result = NetworkApi::get_buy1_info(code);
|
auto doc = JsonUtil::parseUTF16(result);
|
if (doc.IsObject()) {
|
if (doc[L"code"].GetInt() == 0) {
|
|
int volume = doc[L"data"][L"volume"].GetInt();
|
double price = doc[L"data"][L"price"].GetDouble();
|
return Buy1Info({volume, price});
|
|
}
|
else {
|
throw CString(doc[L"msg"].GetString());
|
}
|
}
|
else {
|
throw CString("ÍøÂçÇëÇó³ö´í");
|
}
|
}
|
|
|
};
|