#pragma once
|
#include "../common_nopch/JsonUtil.h"
|
#include "DataStruct.h"
|
#include <list>
|
// Êý¾Ý½âÎö°ïÖúÀà
|
class DataParseUtil {
|
public:
|
static std::list<PositionInfo> parsePositionList(string result) {
|
std::list<PositionInfo> fresults;
|
auto doc = JsonUtil::parseUTF16(result);
|
if (doc.IsObject()) {
|
if (doc[L"code"].GetInt() == 0) {
|
auto array = doc[L"data"].GetArray();
|
for (int i = 0; i < array.Size(); i++) {
|
auto item = array[i].GetObject();
|
PositionInfo position;
|
position.id = item[L"id"].GetString();
|
position.investorID = item[L"investorID"].GetString();
|
position.tradingDay = item[L"tradingDay"].GetString();
|
position.securityName = item[L"securityName"].GetString();
|
position.securityID = item[L"securityID"].GetString();
|
position.historyPos = item[L"historyPos"].GetInt();
|
position.historyPosFrozen = item[L"historyPosFrozen"].GetInt();
|
position.todayBSPos = item[L"todayBSPos"].GetInt();
|
position.todayBSPosFrozen = item[L"todayBSPosFrozen"].GetInt();
|
position.historyPosPrice = item[L"historyPosPrice"].GetString();
|
position.totalPosCost = item[L"totalPosCost"].GetString();
|
position.prePosition = item[L"prePosition"].GetInt();
|
position.availablePosition = item[L"availablePosition"].GetInt();
|
position.currentPosition = item[L"currentPosition"].GetInt();
|
position.openPosCost = item[L"openPosCost"].GetString();
|
position.todayCommission = item[L"todayCommission"].GetString();
|
position.todayTotalBuyAmount = item[L"todayTotalBuyAmount"].GetString();
|
position.todayTotalSellAmount = item[L"todayTotalSellAmount"].GetString();
|
position.updateTime = item[L"updateTime"].GetString();
|
MarketInfo market,underlyingMarket;
|
|
if (item.HasMember(L"marketInfo")) {
|
auto marketItem = item[L"marketInfo"].GetObject();
|
market.code = marketItem[L"code"].GetString();
|
market.name = marketItem[L"name"].GetString();
|
market.rate = marketItem[L"rate"].GetString();
|
market.price = StringUtil::to_string( marketItem[L"price"].GetDouble(),2);
|
market.lastVolume = to_string(marketItem[L"lastVolume"].GetInt());
|
market.buy1Money = marketItem[L"buy1Money"].GetString();
|
market.preClosePrice = marketItem[L"preClosePrice"].GetDouble();
|
}
|
|
if (item.HasMember(L"underlyingMarketInfo")) {
|
auto marketItem = item[L"underlyingMarketInfo"].GetObject();
|
underlyingMarket.code = marketItem[L"code"].GetString();
|
underlyingMarket.name = marketItem[L"name"].GetString();
|
underlyingMarket.rate = marketItem[L"rate"].GetString();
|
underlyingMarket.price = StringUtil::to_string(marketItem[L"price"].GetDouble(), 2);
|
underlyingMarket.lastVolume = to_string(marketItem[L"lastVolume"].GetInt());
|
underlyingMarket.buy1Money = marketItem[L"buy1Money"].GetString();
|
underlyingMarket.preClosePrice = marketItem[L"preClosePrice"].GetDouble();
|
}
|
if (item.HasMember(L"underlyingDetailInfo")) {
|
auto detailInfoObj = item[L"underlyingDetailInfo"].GetObject();
|
CodeDetailInfo detailInfo;
|
if (detailInfoObj.HasMember(L"limitUpReason")) {
|
detailInfo.limitUpReason = detailInfoObj[L"limitUpReason"].GetString();
|
}
|
else {
|
detailInfo.limitUpReason = "ÎÞ";
|
}
|
|
|
detailInfo.bigOrderDealCount = detailInfoObj[L"bigOrderDealCount"].GetInt();
|
detailInfo.bigOrderDealMoney = detailInfoObj[L"bigOrderDealMoney"].GetString();
|
detailInfo.limit_up_time = detailInfoObj[L"limit_up_time"].GetString();
|
detailInfo.highDesc = detailInfoObj[L"highDesc"].GetString();
|
detailInfo.zyltgb = detailInfoObj[L"zyltgb"].GetString();
|
detailInfo.price = StringUtil::to_string( detailInfoObj[L"price"].GetDouble(),2);
|
if (detailInfoObj.HasMember(L"blocks")) {
|
detailInfo.blocks.clear();
|
auto array = detailInfoObj[L"blocks"].GetArray();
|
for (int i = 0; i < array.Size(); i++) {
|
detailInfo.blocks.push_back(array[i].GetString());
|
}
|
}
|
if (detailInfoObj.HasMember(L"blockInfos")) {
|
detailInfo.blockInfos.clear();
|
auto array = detailInfoObj[L"blockInfos"].GetArray();
|
for (int i = 0; i < array.Size(); i++) {
|
CodeBlockInfo blockInfo;
|
auto tempObj = array[i].GetObject();
|
blockInfo.name = tempObj[L"name"].GetString();
|
blockInfo.totalLimitUpCount = tempObj[L"totalLimitUpCount"].GetInt();
|
blockInfo.openLimitUpCount = tempObj[L"openLimitUpCount"].GetInt();
|
blockInfo.rank = tempObj[L"rank"].GetInt();
|
detailInfo.blockInfos.push_back(blockInfo);
|
}
|
}
|
position.underlyingDetailInfo = detailInfo;
|
}
|
|
if (item.HasMember(L"buy_list")) {
|
std::list<DealInfo> buyList;
|
auto array = item[L"buy_list"].GetArray();
|
for (int i = 0; i < array.Size(); i++) {
|
auto item = array[i].GetObject();
|
DealInfo dealInfo;
|
dealInfo.price = item[L"price"].GetString();
|
dealInfo.tradeTime = item[L"tradeTime"].GetString();
|
dealInfo.volume = item[L"volume"].GetInt();
|
buyList.push_back(dealInfo);
|
}
|
position.buyList = buyList;
|
}
|
|
if (item.HasMember(L"sell_list")) {
|
std::list<DealInfo> sellList;
|
auto array = item[L"sell_list"].GetArray();
|
for (int i = 0; i < array.Size(); i++) {
|
auto item = array[i].GetObject();
|
DealInfo dealInfo;
|
dealInfo.price = item[L"price"].GetString();
|
dealInfo.tradeTime = item[L"tradeTime"].GetString();
|
dealInfo.volume = item[L"volume"].GetInt();
|
sellList.push_back(dealInfo);
|
}
|
position.sellList = sellList;
|
}
|
|
if (item.HasMember(L"createTime")) {
|
|
position.createTime = item[L"createTime"].GetUint64();
|
|
}
|
|
|
position.marketInfo = market;
|
position.underlyingMarketInfo = underlyingMarket;
|
fresults.push_back(position);
|
}
|
return fresults;
|
}
|
else {
|
wxString msg = doc[L"msg"].GetString();
|
throw msg;
|
}
|
}
|
else {
|
throw wxString("ÍøÂçÇëÇó´íÎó");
|
}
|
|
}
|
|
static float computeCostRate(PositionInfo p) {
|
|
double totalPosCost = 0;
|
int totalVolume = 0;
|
for (std::list<DealInfo>::iterator e = p.buyList.begin(); e != p.buyList.end(); e++) {
|
DealInfo info = *e;
|
string price = info.price.ToStdString();
|
totalPosCost += stod(price.c_str()) * info.volume;
|
totalVolume += info.volume;
|
}
|
double todayCommission;
|
p.todayCommission.ToDouble(&todayCommission);
|
totalPosCost += todayCommission;
|
double cost_price = totalPosCost / totalVolume;
|
double preClosePrice= p.marketInfo.preClosePrice;
|
return (cost_price - preClosePrice) * 100 / preClosePrice;
|
}
|
};
|