admin
2024-07-05 3ef188e6075649f4c72e3e7588d8966e1071f2ff
DelegateQueue/MainFrame.cpp
@@ -31,6 +31,10 @@
   CLICK_TYPE_QUEUE,
};
struct ViewDetailData {
   string code;
};
// 委托信息数据
class DelegateInfoRenderer : public wxDataViewCustomRenderer
@@ -88,7 +92,15 @@
      
      delegateInfoStr.Append("/").Append("封单").Append(delegateInfo.buy1_money);
      delegateInfoStr.Append(" 【比例: ").Append(floatToString(delegateInfo.trade_progress_percent)).Append("%").Append("】,");
      delegateInfoStr.Append(" 【比例: ");
      ColorIndexInfo colorInfo2;
      colorInfo2.start_index = delegateInfoStr.Length();
      delegateInfoStr.Append(floatToString(delegateInfo.trade_progress_percent)).Append("%");
      colorInfo2.end_index = delegateInfoStr.Length() - 1;
      colorInfo2.color = wxColor(206, 14, 95);
      delegateColors.push_back(colorInfo2);
      delegateInfoStr.Append("】,");
      delegateInfoStr.Append("已成大单").Append(to_string(delegateInfo.big_num_count)).Append("笔").Append(delegateInfo.big_num_money).Append("  ");
@@ -108,8 +120,20 @@
      delegateInfoStr.Append("笔").Append(delegateInfo.not_deal_big_num_money_after).Append(",");
      delegateInfoStr.Append("涨停价:").Append(floatToString(delegateInfo.limit_up_price)).Append("元").Append(",");
      delegateInfoStr.Append(delegateInfo.block);
      delegateInfoStr.Append("涨停价:");
      ColorIndexInfo colorInfo3;
      colorInfo3.start_index = delegateInfoStr.Length();
      delegateInfoStr.Append(floatToString(delegateInfo.limit_up_price)).Append("Ԫ");
      colorInfo3.end_index = delegateInfoStr.Length();
      if (delegateInfo.limit_up_price < 3) {
         colorInfo3.color = *wxRED;
         delegateColors.push_back(colorInfo3);
      }
      delegateInfoStr.Append(",");
      delegateInfoStr.Append(delegateInfo.block).Append(",");
      delegateInfoStr.Append(" 涨停时间:").Append(delegateInfo.limit_up_time);
   }
   float parseMoneyAsW(wxString st) {
@@ -141,15 +165,19 @@
      // 绘制名字
      wxString codeName = "";
      codeName.Append(delegateInfo.code).Append("(").Append(delegateInfo.codeName).Append(")");
      wxString codeInfo = "";
      codeInfo.Append(delegateInfo.code).Append("(").Append(delegateInfo.codeName).Append(")");
      WidgetsRenderUtil::drawText(dc, codeName, wxPoint(startx, starty + 3),line_width, TEXT_LINE_HEIGHT);
      codeInfo.Append("  ").Append(delegateInfo.zyltgb);
      if (delegateInfo.pay_attention) {
         wxSize textSize = dc->GetTextExtent(codeName);
         WidgetsRenderUtil::drawText(dc, codeInfo, wxPoint(startx, starty + 3), line_width, TEXT_LINE_HEIGHT, std::list<ColorIndexInfo>(), *wxRED);
         wxSize textSize = dc->GetTextExtent(codeInfo);
         WidgetsRenderUtil::drawText(dc, "****", wxPoint(startx + textSize.GetWidth() + 5*DPI/100, starty + 5*DPI/100), line_width, TEXT_LINE_HEIGHT, std::list<ColorIndexInfo>(), *wxRED);
      }
      else {
         WidgetsRenderUtil::drawText(dc, codeInfo, wxPoint(startx, starty + 3), line_width, TEXT_LINE_HEIGHT);
      }
      // 绘制按钮
      dc->SetPen(wxColour(225, 225, 225));
@@ -353,6 +381,27 @@
      }
   }
   /// <summary>
   /// 查看详情
   /// </summary>
   /// <param name="code"></param>
   static void viewDetail(wxString code) {
      try {
         Win32Util::addToTHS(code.ToStdString());
         list<HWND> hwnds = Win32Util::searchWindow("看盘副屏");
         if (hwnds.size() > 0) {
            for (list<HWND>::iterator e = hwnds.begin(); e != hwnds.end(); ++e) {
               HWND hwnd = *e;
               ViewDetailData* data = new ViewDetailData();
               data->code = code.ToStdString();
               SendMessage(hwnd, WM_USER + 1024, 0, reinterpret_cast<LPARAM>(&data));
            }
         }
      }
      catch (...) {
      }
   }
   // 点击事件处理方法
   bool ActivateCell(const wxRect& WXUNUSED(cell), wxDataViewModel* WXUNUSED(model), const wxDataViewItem& WXUNUSED(item), unsigned int WXUNUSED(col), const wxMouseEvent* mouseEvent) override {
@@ -366,9 +415,9 @@
            cancelOrder(delegateInfo.code.ToStdString());
            break;
         case CLICK_TYPE_VIEW_DETAIL:
            try {
               Win32Util::addToTHS(delegateInfo.code.ToStdString());
               thread t(viewDetail, delegateInfo.code);
               t.detach();
            }
            catch (string msg) {
               wxMessageBox(msg.c_str());
@@ -435,7 +484,8 @@
MainFrame::MainFrame(const wxString& title, wxPoint position, wxSize size) :wxFrame(NULL, wxID_ANY, title, position, size) {
   // 置顶
   SetWindowStyle(GetWindowStyle() | wxSTAY_ON_TOP);
   // 初始化
   killed = false;
   Bind(wxEVT_CLOSE_WINDOW, &MainFrame::OnClose, this);
@@ -445,7 +495,6 @@
   SetTransparent(225);
   SetWindowStyle(GetWindowStyle() | wxSTAY_ON_TOP);
   wxPanel* panel = new wxPanel(this, wxID_ANY);
@@ -472,9 +521,13 @@
   wxButton *openTradeQueueBtn =new wxButton(panel, wxID_ANY,"查看全部");
   avaiableMoneyLabel = new wxStaticText(panel, wxID_ANY, "0.00", wxDefaultPosition, wxSize(80 * DPI / 100, -1));
   wxBoxSizer *topSizer=new wxBoxSizer(wxHORIZONTAL);
   topSizer->Add(msgCtrl, 1, wxEXPAND);
   topSizer->Add(avaiableMoneyLabel, 0, wxEXPAND | wxALL, 3);
   topSizer->Add(openTradeQueueBtn, 0);
@@ -533,6 +586,7 @@
void MainFrame::refresh()
{
   cout << "刷新时间:" << TimeUtil::getNowTimeStamp() << " 数量:" << delegateList.size() << endl;
   m_listCtrl->DeleteAllItems();
   for (list<DelegateInfo>::iterator e = delegateList.begin(); e != delegateList.end(); ++e) {
      DelegateInfo info = *e;
@@ -541,17 +595,19 @@
      data.push_back(info.id);
      m_listCtrl->AppendItem(data);
   }
   m_listCtrl->Refresh();
}
list<DelegateInfo> MainFrame::parseDelegates(string result)
DelegateResult MainFrame::parseDelegates(string result)
{
   list<DelegateInfo> fresults;
   wxString available_money = "";
   auto doc = JsonUtil::parseUTF16(result);
   if (doc.IsObject() && doc[L"code"].GetInt() == 0) {
      auto root = doc[L"data"].GetObject();
      auto delegates = root[L"delegates"].GetArray();
      auto money = root[L"account_available_money"].GetString();
      double money = root[L"account_available_money"].GetDouble();
      available_money = StringUtil::to_string(money);
      for (int i = 0; i < delegates.Size(); i++) {
         auto doc = delegates[i].GetObject();
@@ -582,6 +638,9 @@
         delegateInfo.limit_up_price = doc[L"limit_up_price"].GetFloat();
         delegateInfo.is_near_big_order = doc[L"is_near_big_order"].GetString();
         delegateInfo.block = doc[L"block"].GetString();
         if (doc.HasMember(L"limit_up_time")) {
            delegateInfo.limit_up_time = doc[L"limit_up_time"].GetString();
         }
         array=doc[L"trade_queue"].GetArray();
         list<TradeQueue> queueList;
@@ -592,19 +651,23 @@
         }
         delegateInfo.tradeQueueList = queueList;
         if (doc.HasMember(L"zyltgb"))
            delegateInfo.zyltgb = doc[L"zyltgb"].GetString();
         fresults.push_back(delegateInfo);
      }
   }
   else {
      throw string("网络请求出错");
   }
   return fresults;
   return DelegateResult({ fresults ,available_money });
}
void MainFrame::startRequestDelegatedInfoListTask(MainFrame* context)
{
   while (TRUE) {
      try {
         while (TRUE) {
      if (context->killed) {
         break;
      }
@@ -615,28 +678,38 @@
      }
      catch (...) {
      }
      Sleep(2000);
         }
      }
      catch (...) {
      }
   }
}
void MainFrame::requestDelegatedInfoList()
{
   try {
      cout <<"请求委托列表"<< endl;
      auto start_time = TimeUtil::getNowTimeStamp();
      string result = MyNetworkApi::get_delegated_buy_code_infos();
      if (killed) {
         return;
      }
      cout << "请求委托列表耗时:" << TimeUtil::getNowTimeStamp() - start_time << endl;
      start_time = TimeUtil::getNowTimeStamp();
      auto doc = JsonUtil::parseUTF8(result);
      auto delegateList = parseDelegates(result);
      auto delegateResult = parseDelegates(result);
      cout << "解析数据耗时:" << TimeUtil::getNowTimeStamp() - start_time << endl;
      start_time = TimeUtil::getNowTimeStamp();
      // 根据ID
      if (this != nullptr) {
         this->delegateList = delegateList;
         this->delegateList = delegateResult.delegates;
         this->avaiableMoneyLabel->SetLabelText(delegateResult.money);
         this->refresh();
         cout << "刷新UI耗时:" << TimeUtil::getNowTimeStamp() - start_time << endl;
      }
   }
   catch (string st) {
@@ -653,7 +726,6 @@
void MainFrame::OnButtonOpenTradeQueueClick(wxCommandEvent& event)
{
   if (delegateList.size()>0) {
      WindowPosSize r = MyConfigUtil::getTradeQueueWindowPos();
      if (r.x == -1 && r.y == -1) {