| | |
| | | |
| | | //json对象转为字符串 |
| | | static std::string toJsonStr(Json::Value json) { |
| | | clock_t start_time = clock(); |
| | | Json::StreamWriterBuilder writerBuilder; |
| | | //不自动换行 |
| | | writerBuilder.settings_["indentation"] = ""; |
| | |
| | | jsonWriter->write(json, &os); |
| | | string jsonStr = os.str(); |
| | | //释放资源 |
| | | jsonWriter.reset(); |
| | | //jsonWriter.reset(); |
| | | //cout << "json转字符串耗时:"<< clock()- start_time << endl; |
| | | return jsonStr; |
| | | } |
| | | |
| | | static std::string loadL2Data(int clientID, int channel, string code, long captureTime, long processTime, std::list<TradeData*> dataList) { |
| | | Json::Value data; |
| | | data["channel"] = channel; |
| | | data["code"] = code; |
| | | data["captureTime"] = captureTime; |
| | | data["processTime"] = processTime; |
| | | data["data"] = toJson(dataList); |
| | | Json::Value root; |
| | | root["type"] = 0; |
| | | root["client"] = clientID; |
| | | root["data"] = data; |
| | | return toJsonStr(root); |
| | | //Json::Value data; |
| | | //data["channel"] = channel; |
| | | //data["code"] = code; |
| | | //data["captureTime"] = captureTime; |
| | | //data["processTime"] = processTime; |
| | | //data["data"] = toJson(dataList); |
| | | //Json::Value root; |
| | | //root["type"] = 0; |
| | | //root["client"] = clientID; |
| | | //root["data"] = data; |
| | | //return toJsonStr(root); |
| | | string st = "{"; |
| | | st.append("\"type\":0,"); |
| | | st.append("\"client\":").append(to_string(clientID)).append(","); |
| | | st.append("\"data\":{"); |
| | | st.append("\"channel\":").append(to_string(channel)).append(","); |
| | | st.append("\"code\":").append("\"").append(code).append("\"").append(","); |
| | | st.append("\"captureTime\":").append(to_string(captureTime)).append(","); |
| | | st.append("\"processTime\":").append(to_string(channel)).append(","); |
| | | st.append("\"data\":["); |
| | | int index = 0; |
| | | for (std::list<TradeData*>::iterator ele = dataList.begin(); ele != dataList.end(); ele++) { |
| | | index++; |
| | | st.append("{"); |
| | | st.append("\"time\":").append("\"").append((*ele)->time).append("\"").append(","); |
| | | st.append("\"price\":").append("\"").append((*ele)->price).append("\"").append(","); |
| | | st.append("\"num\":").append(to_string((*ele)->num)).append(","); |
| | | st.append("\"limitPrice\":").append(to_string((*ele)->limitPrice)).append(","); |
| | | st.append("\"operateType\":").append(to_string((*ele)->operateType)).append(","); |
| | | st.append("\"cancelTime\":").append(to_string((*ele)->cancelTime)).append(","); |
| | | st.append("\"cancelTimeUnit\":").append(to_string((*ele)->cancelTimeUnit)); |
| | | st.append("}"); |
| | | if (index != dataList.size()) { |
| | | st.append(","); |
| | | } |
| | | } |
| | | st.append("]"); |
| | | st.append("}}"); |
| | | return st; |
| | | } |
| | | |
| | | |
| | |
| | | _data["sellOnePrice"] = tradeQueue.sellOnePrice; |
| | | _data["sellOneVolumn"] = tradeQueue.sellOneVolumn; |
| | | _data["sellTime"] = tradeQueue.sellTime; |
| | | Json::Value buyQueue; |
| | | int index = 0; |
| | | for (list<string>::iterator ele = tradeQueue.buyQueue.begin(); ele != tradeQueue.buyQueue.end(); ++ele) { |
| | | buyQueue[index++] = atoi((*ele).c_str()); |
| | | } |
| | | _data["buyQueue"] = buyQueue; |
| | | |
| | | |
| | | data["data"] = _data; |
| | | Json::Value root; |
| | |
| | | return root; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | static string jsonValue2String(Json::Value value) { |
| | | Json::FastWriter fastWriter; |
| | | std::string output = fastWriter.write(value); |