admin
2024-07-05 3ef188e6075649f4c72e3e7588d8966e1071f2ff
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#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;
    }
};