admin
2024-05-17 56092db23f41123e2d24c7a1d79608d663297733
bug修复
5个文件已修改
203 ■■■■■ 已修改文件
common/NetworkApi.cpp 132 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
common/NetworkApi.h 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
common/SocketManager.cpp 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
common/StringUtil.h 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
common/TimeUtil.h 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
common/NetworkApi.cpp
@@ -719,6 +719,36 @@
    return SubscriptCodesResult({ fresults ,updateTime });
}
SubscriptCodesResult NetworkApi::get_huaxin_position_subscript_codes()
{
    rapidjson::StringBuffer buf;
    rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buf);
    writer.StartObject();
    writer.Key("type");
    writer.String("get_huaxin_position_subscript_codes");
    writer.Key("data");
    writer.StartObject();
    writer.EndObject();
    writer.EndObject();
    const char* json_content = buf.GetString();
    string result = base_trade_request(std::string(json_content));
    rapidjson::GenericDocument<rapidjson::UTF16<>> doc = JsonUtil::parseUTF16(result);
    std::list<CodeInfo> fresults;
    CString updateTime = L"";
    if (doc.IsObject() && doc[L"code"].GetInt() == 0) {
        for (int i = 0; i < doc[L"data"][L"list"].GetArray().Size(); i++) {
            auto arr = doc[L"data"][L"list"].GetArray()[i].GetArray();
            CString code = arr[0].GetString();
            CString codeName = arr[1].IsNull() ? L"δ֪" : arr[1].GetString();
            CodeInfo ci = CodeInfo({ code ,codeName });
            fresults.push_back(ci);
        }
        updateTime = doc[L"data"][L"update_time"].GetString();
    }
    return SubscriptCodesResult({ fresults ,updateTime });
}
string NetworkApi::export_l2_data(CString code)
{
@@ -1009,11 +1039,9 @@
    rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buf);
    writer.StartObject();
    writer.Key("type");
    writer.String("common");
    writer.String("get_buy1_info");
    writer.Key("data");
    writer.StartObject();
    writer.Key("ctype");
    writer.String("get_buy1_info");
    writer.Key("code");
    writer.String(code.c_str());
    writer.EndObject();
@@ -1023,6 +1051,104 @@
    return result;
}
void NetworkApi::set_per_code_buy_money(int money)
{
    rapidjson::StringBuffer buf;
    rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buf);
    writer.StartObject();
    writer.Key("type");
    writer.String("common");
    writer.Key("data");
    writer.StartObject();
    writer.Key("ctype");
    writer.String("set_per_code_buy_money");
    writer.Key("money");
    writer.Int(money);
    writer.EndObject();
    writer.EndObject();
    const char* json_content = buf.GetString();
    string result = base_request(std::string(json_content));
    auto root =    JsonUtil::parseUTF16(result);
    if (root.IsObject()) {
        if (root[L"code"] != 0) {
            throw wstring(root[L"msg"].GetString());
        }
    }
    else {
        throw wstring(L"网络请求错误");
    }
}
int NetworkApi::get_per_code_buy_money()
{
    rapidjson::StringBuffer buf;
    rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buf);
    writer.StartObject();
    writer.Key("type");
    writer.String("common");
    writer.Key("data");
    writer.StartObject();
    writer.Key("ctype");
    writer.String("get_per_code_buy_money");
    writer.EndObject();
    writer.EndObject();
    const char* json_content = buf.GetString();
    string result = base_request(std::string(json_content));
     auto root=JsonUtil::parseUTF16(result);
     if (root.IsObject()) {
         if (root[L"code"].GetInt() == 0) {
             return root[L"data"][L"money"].GetInt();
         }
         else {
             throw wstring(root[L"msg"].GetString());
         }
     }
     else {
         throw wstring(L"网络请求出错");
     }
}
string NetworkApi::get_l2_deal_price(string code)
{
    rapidjson::StringBuffer buf;
    rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buf);
    writer.StartObject();
    writer.Key("type");
    writer.String("common");
    writer.Key("data");
    writer.StartObject();
    writer.Key("ctype");
    writer.String("get_l2_deal_price");
    writer.Key("code");
    writer.String(code.c_str());
    writer.EndObject();
    writer.EndObject();
    const char* json_content = buf.GetString();
    string result = base_request(std::string(json_content));
    return result;
}
string NetworkApi::repaire_task()
{
    rapidjson::StringBuffer buf;
    rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buf);
    writer.StartObject();
    writer.Key("type");
    writer.String("common");
    writer.Key("data");
    writer.StartObject();
    writer.Key("ctype");
    writer.String("repaire_task");
    writer.EndObject();
    writer.EndObject();
    const char* json_content = buf.GetString();
    string result = base_request(std::string(json_content));
    return result;
}
string NetworkApi::list_delegate_records(CString updateTime,bool canCancel)
{
    rapidjson::StringBuffer buf;
common/NetworkApi.h
@@ -156,6 +156,9 @@
    //获取华兴订阅代码
    static SubscriptCodesResult get_huaxin_subscript_codes();
    //获取华兴持仓订阅代码
    static SubscriptCodesResult get_huaxin_position_subscript_codes();
    //导出L2数据
    static string export_l2_data(CString code);
@@ -201,8 +204,22 @@
    static string get_buy1_info(string code);
    // 设置每个代码可买的金额
    static void set_per_code_buy_money(int money);
    // 获取单票买入金额
    static int get_per_code_buy_money();
    // 获取L2成交现价
    static string get_l2_deal_price(string code);
    static string repaire_task();
};
common/SocketManager.cpp
@@ -16,6 +16,7 @@
string SocketManager::sendMsg(const char* msg) {
    ADDR = "43.138.167.68";
    //ADDR = "192.168.3.122";
    return SocketManager::sendMsg(ADDR, PORT, msg);
}
common/StringUtil.h
@@ -6,6 +6,7 @@
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
using namespace std;
class StringUtil {
@@ -65,4 +66,22 @@
        oss << std::fixed << std::setprecision(precision) << value;
        return oss.str();
    }
    static std::vector<std::string> split(std::string str, std::string pattern) {
        std::string::size_type pos;
        std::vector<std::string> result;
        str += pattern;//扩展字符串以方便操作
        int size = str.size();
        for (int i = 0; i < size; i++)
        {
            pos = str.find(pattern, i);
            if (pos < size)
            {
                std::string s = str.substr(i, pos - i);
                result.push_back(s);
                i = pos + pattern.size() - 1;
            }
        }
        return result;
    }
};
common/TimeUtil.h
@@ -2,6 +2,8 @@
#include <iostream>
#include <ctime>
#include <string>
#include <sstream>
#include <vector>
class TimeUtil {
public:
@@ -56,4 +58,34 @@
        return timestamp;
    }
    // 时间相减,返回相差的s
    static int trade_time_sub(string time_str_1, string time_str_2) {
        int time_1[3], time_2[3];
        // 切割时间
        std::string token;
        std::vector<std::string> results = StringUtil::split(time_str_1,":");
        int index = 0;
        for (std::vector<std::string>::iterator e = results.begin(); e != results.end(); e++) {
            time_1[index] = stoi(*e);
            index++;
        }
        results = StringUtil::split(time_str_2, ":");
        index = 0;
        for (std::vector<std::string>::iterator e = results.begin(); e != results.end(); e++) {
            time_2[index] = stoi(*e);
            index++;
        }
        int split_time = 11 * 3600 + 30 * 60 + 0;
        int time_1_int = time_1[0] * 3600 + time_1[1] * 60 + time_1[2];
        int time_2_int = time_2[0] * 3600 + time_2[1] * 60 + time_2[2];
        if (split_time > time_1_int && split_time < time_2_int) {
            time_2_int = time_2_int - 90 * 60;
        }
        else if (split_time > time_2_int && split_time < time_1_int) {
            time_2_int = time_2_int + 90 * 60;
        }
        return time_1_int - time_2_int;
    }
};