// MonitorDlg.cpp: 实现文件
|
//
|
|
#include "common/pch.h"
|
#include "Monitor.h"
|
#include "MonitorDlg.h"
|
#include "afxdialogex.h"
|
#include "../common/NetworkApi.h"
|
#include <map>
|
#include "../common/JsonUtil.h"
|
|
|
std::list<CodeInfo> MonitorDlg::l2CodesList;
|
list<TradeDelegateRecord> MonitorDlg::delegateList;
|
list<TradeDealRecord> MonitorDlg::dealList;
|
bool MonitorDlg::kill;
|
CString MonitorDlg::getOrderStatusDesc(int orderStatus)
|
{
|
switch (orderStatus)
|
{
|
case 0:
|
return L"预埋";
|
case 1:
|
return L"未知";
|
case 2:
|
return L"交易所已接收";
|
case 3:
|
return L"部分成交";
|
case 4:
|
return L"全部成交";
|
case 5:
|
return L"部成部撤";
|
case 6:
|
return L"全部撤单";
|
case 7:
|
return L"交易所已拒绝";
|
default:
|
return L"发往交易核心";
|
}
|
}
|
|
CString MonitorDlg::getDirectionDesc(int direction)
|
{
|
switch (direction)
|
{
|
case 0:
|
return L"买入";
|
case 1:
|
return L"卖出";
|
}
|
return CString();
|
}
|
|
|
|
// MonitorDlg 对话框
|
|
IMPLEMENT_DYNAMIC(MonitorDlg, CDialogEx)
|
|
void MonitorDlg::requestL2CodeList(MonitorDlg* dlg)
|
{
|
|
while (TRUE) {
|
if (kill) {
|
break;
|
}
|
try {
|
SubscriptCodesResult result = NetworkApi::get_huaxin_subscript_codes();
|
if (result.codeInfos.size() > 0) {
|
//将原来的数据映射为map
|
|
dlg->listL2Codes.SetRedraw(false);
|
|
// 先删除/增加多余的行,然后修改行中内容
|
int add_line_count = result.codeInfos.size() - l2CodesList.size();
|
if (add_line_count > 0) {
|
//增加行
|
int start_index = l2CodesList.size();
|
for (int i = 0; i < add_line_count; i++) {
|
dlg->listL2Codes.InsertItem(start_index + i, L"");
|
}
|
}
|
else if (add_line_count < 0) {
|
int start_index = l2CodesList.size() - 1;
|
//删除行
|
for (int i = 0; i > add_line_count; i--) {
|
dlg->listL2Codes.DeleteItem(start_index + i);
|
}
|
}
|
|
|
|
|
//更改数据
|
int index = -1;
|
bool hasChanged = FALSE;
|
for (list<CodeInfo>::iterator el = result.codeInfos.begin(); el != result.codeInfos.end(); ++el) {
|
CodeInfo r = *el;
|
index++;
|
// 如果原数据的主键和本行主键一致就不用修改
|
if (l2CodesList.size() > index) {
|
list<CodeInfo>::iterator or = l2CodesList.begin();
|
std::advance(or , index);
|
if (r.code == (*or ).code) {
|
continue;
|
}
|
}
|
hasChanged = TRUE;
|
CString desc = CString(r.code);
|
desc.Append(L"(");
|
desc.Append(r.name);
|
desc.Append(L")");
|
dlg->listL2Codes.SetItemText(index, 0, desc);
|
|
}
|
if (hasChanged || add_line_count != 0) {
|
l2CodesList.clear();
|
for (list<CodeInfo>::iterator el = result.codeInfos.begin(); el != result.codeInfos.end(); ++el) {
|
CodeInfo r = *el;
|
l2CodesList.push_back(r);
|
}
|
}
|
dlg->listL2Codes.SetRedraw(true);
|
}
|
dlg->labelL2SubscriptCodesUpdateTime.SetWindowTextW(result.updateTime);
|
}
|
|
catch (...) {
|
|
|
}
|
// 每1s请求一次
|
Sleep(2000);
|
}
|
|
|
}
|
|
void MonitorDlg::requestDelegateList(MonitorDlg* dlg)
|
{
|
while (TRUE) {
|
if (kill) {
|
break;
|
}
|
try {
|
string result = NetworkApi::list_delegate_records(L"", TRUE);
|
cout << result << endl;
|
rapidjson::GenericDocument<rapidjson::UTF16<>> doc = JsonUtil::parseUTF16(result);
|
|
if (doc.IsObject() && doc[L"code"].GetInt() == 0) {
|
list<TradeDelegateRecord> tempRecordList;
|
//解析结果
|
auto dataList = doc[L"data"][L"list"].GetArray();
|
for (int i = 0; i < dataList.Size(); i++) {
|
TradeDelegateRecord record;
|
record.accountID = dataList[i][L"accountID"].GetString();
|
record.orderLocalID = dataList[i][L"orderLocalID"].GetString();
|
record.securityID = dataList[i][L"securityID"].GetString();
|
record.securityName = dataList[i][L"securityName"].GetString();
|
record.direction = dataList[i][L"direction"].GetInt();
|
record.orderSysID = dataList[i][L"orderSysID"].GetString();
|
record.insertTime = dataList[i][L"insertTime"].GetString();
|
record.acceptTime = dataList[i][L"acceptTime"].GetString();
|
record.cancelTime = dataList[i][L"cancelTime"].GetString();
|
record.limitPrice = dataList[i][L"limitPrice"].GetString();
|
record.volume = dataList[i][L"volume"].GetInt();
|
record.volumeTraded = dataList[i][L"volumeTraded"].GetInt();
|
record.orderStatus = dataList[i][L"orderStatus"].GetInt();
|
record.orderSubmitStatus = dataList[i][L"orderSubmitStatus"].GetInt();
|
record.statusMsg = dataList[i][L"statusMsg"].GetString();
|
record.updateTime = dataList[i][L"updateTime"].GetString();
|
tempRecordList.push_back(record);
|
}
|
|
|
// 先删除/增加多余的行,然后修改行中内容
|
int add_line_count = tempRecordList.size() - delegateList.size();
|
if (add_line_count > 0) {
|
//增加行
|
int start_index = delegateList.size();
|
for (int i = 0; i < add_line_count; i++) {
|
dlg->listDelegate.InsertItem(start_index + i, L"");
|
}
|
}
|
else if (add_line_count < 0) {
|
int start_index = delegateList.size() - 1;
|
//删除行
|
for (int i = 0; i > add_line_count; i--) {
|
dlg->listDelegate.DeleteItem(start_index + i);
|
}
|
}
|
|
|
|
dlg->listDelegate.SetRedraw(false);
|
int index = -1;
|
bool hasChanged = FALSE;
|
//更改数据
|
for (list<TradeDelegateRecord>::iterator el = tempRecordList.begin(); el != tempRecordList.end(); ++el) {
|
TradeDelegateRecord r = *el;
|
|
index++;
|
// 如果原数据的主键和本行主键一致就不用修改
|
if (delegateList.size() > index) {
|
list<TradeDelegateRecord>::iterator or = delegateList.begin();
|
std::advance(or , index);
|
if (r.orderLocalID == (*or ).orderLocalID) {
|
continue;
|
}
|
}
|
hasChanged = TRUE;
|
dlg->listDelegate.SetItemText(index, 0, r.acceptTime.GetLength() > 0 ? r.acceptTime : r.insertTime);
|
dlg->listDelegate.SetItemText(index, 1, r.securityID);
|
dlg->listDelegate.SetItemText(index, 2, r.securityName);
|
dlg->listDelegate.SetItemText(index, 3, dlg->getDirectionDesc(r.direction));
|
dlg->listDelegate.SetItemText(index, 4, dlg->getOrderStatusDesc(r.orderStatus));
|
dlg->listDelegate.SetItemText(index, 5, CString(std::to_string(r.volume).c_str()));
|
|
}
|
if (hasChanged || add_line_count != 0) {
|
delegateList.clear();
|
for (list<TradeDelegateRecord>::iterator el = tempRecordList.begin(); el != tempRecordList.end(); ++el) {
|
TradeDelegateRecord r = *el;
|
delegateList.push_back(r);
|
}
|
}
|
|
|
dlg->listDelegate.SetRedraw(true);
|
|
}
|
|
}
|
catch (...) {
|
|
|
}
|
// 每1s请求一次
|
Sleep(1000);
|
}
|
}
|
|
void MonitorDlg::requestDealList(MonitorDlg* dlg)
|
{
|
while (TRUE) {
|
if (kill) {
|
break;
|
}
|
try {
|
string result = NetworkApi::list_deal_records();
|
cout << result << endl;
|
rapidjson::GenericDocument<rapidjson::UTF16<>> doc = JsonUtil::parseUTF16(result);
|
|
if (doc.IsObject() && doc[L"code"].GetInt() == 0) {
|
list<TradeDealRecord> tempRecordList;
|
//解析结果
|
auto dataList = doc[L"data"][L"list"].GetArray();
|
for (int i = 0; i < dataList.Size(); i++) {
|
TradeDealRecord record;
|
record.tradeID = dataList[i][L"tradeID"].GetString();
|
record.direction = dataList[i][L"direction"].GetString();
|
record.orderSysID = dataList[i][L"orderSysID"].GetString();
|
record.price = dataList[i][L"price"].GetString();
|
record.securityID = dataList[i][L"securityID"].GetString();
|
record.tradeTime = dataList[i][L"tradeTime"].GetString();
|
record.volume = dataList[i][L"volume"].GetInt();
|
|
tempRecordList.push_back(record);
|
}
|
|
|
// 先删除/增加多余的行,然后修改行中内容
|
int add_line_count = tempRecordList.size() - dealList.size();
|
if (add_line_count > 0) {
|
//增加行
|
int start_index = dealList.size();
|
for (int i = 0; i < add_line_count; i++) {
|
dlg->listDeal.InsertItem(start_index + i, L"");
|
}
|
}
|
else if (add_line_count < 0) {
|
int start_index = dealList.size() - 1;
|
//删除行
|
for (int i = 0; i > add_line_count; i--) {
|
dlg->listDeal.DeleteItem(start_index + i);
|
}
|
}
|
|
dlg->listDeal.SetRedraw(false);
|
|
int index = -1;
|
bool hasChanged = FALSE;
|
//更改数据
|
for (list<TradeDealRecord>::iterator el = tempRecordList.begin(); el != tempRecordList.end(); ++el) {
|
TradeDealRecord r = *el;
|
|
index++;
|
|
if (dealList.size() > index) {
|
list<TradeDealRecord>::iterator or = dealList.begin();
|
std::advance(or , index);
|
if (r.tradeID == (*or ).tradeID) {
|
continue;
|
}
|
}
|
hasChanged = TRUE;
|
dlg->listDeal.SetItemText(index, 0, CString(to_string( index+1).c_str()));
|
dlg->listDeal.SetItemText(index, 1, r.tradeID);
|
dlg->listDeal.SetItemText(index, 2, r.securityID);
|
dlg->listDeal.SetItemText(index, 3, dlg->getDirectionDesc(stoi(StringUtil::cstring2String(r.direction))));
|
dlg->listDeal.SetItemText(index, 4, r.tradeTime);
|
dlg->listDeal.SetItemText(index, 5, r.price);
|
dlg->listDeal.SetItemText(index, 6, CString(std::to_string(r.volume).c_str()));
|
}
|
|
if (hasChanged || add_line_count != 0) {
|
dealList.clear();
|
for (list<TradeDealRecord>::iterator el = tempRecordList.begin(); el != tempRecordList.end(); ++el) {
|
TradeDealRecord r = *el;
|
dealList.push_back(r);
|
}
|
}
|
dlg->listDeal.SetRedraw(true);
|
}
|
}
|
catch (...) {
|
|
|
}
|
// 每1s请求一次
|
Sleep(1000);
|
}
|
}
|
|
void MonitorDlg::autoRefresh(MonitorDlg* dlg)
|
{
|
|
while (TRUE) {
|
if (kill) {
|
break;
|
}
|
try {
|
dlg->labelColors[IDC_STATIC_HUAXIN_TRADE_CHANNEL] = RGB(0, 0, 0);
|
string result = NetworkApi::huaxin_channel_states();
|
CString st = L"";
|
auto doc = JsonUtil::parseUTF16(result);
|
if (doc.IsObject()) {
|
if (doc[L"code"] == 0&& doc[L"data"].IsObject()) {
|
|
auto data = doc[L"data"].GetObject();
|
if (data.HasMember(L"common")) {
|
st.Append(L"一般通道:");
|
st.Append(L"总数-");
|
st.Append(std::to_wstring( data[L"common"][0].GetInt()).c_str());
|
st.Append(L" ");
|
st.Append(L"可用数-");
|
st.Append(std::to_wstring(data[L"common"][1].GetInt()).c_str());
|
st.Append(L" ");
|
st.Append(L"活跃数-");
|
st.Append(std::to_wstring(data[L"common"][2].GetInt()).c_str());
|
st.Append(L" ");
|
st.Append(L"\r\n");
|
}
|
|
if (data.HasMember(L"trade")) {
|
st.Append(L"交易通道:");
|
st.Append(L"总数-");
|
st.Append(std::to_wstring(data[L"trade"][0].GetInt()).c_str());
|
st.Append(L" ");
|
st.Append(L"可用数-");
|
st.Append(std::to_wstring(data[L"trade"][1].GetInt()).c_str());
|
st.Append(L" ");
|
st.Append(L"活跃数-");
|
st.Append(std::to_wstring(data[L"trade"][2].GetInt()).c_str());
|
st.Append(L" ");
|
st.Append(L"\r\n");
|
}
|
}
|
dlg->labelHXTradeChannel.SetWindowTextW(st);
|
}
|
|
else {
|
dlg->labelHXTradeChannel.SetWindowTextW(L"-1");
|
}
|
}
|
catch (CString st) {
|
dlg->labelColors[IDC_STATIC_HUAXIN_TRADE_CHANNEL] = RGB(255, 0, 0);
|
dlg->labelHXTradeChannel.SetWindowTextW(st);
|
}
|
|
|
if (kill) {
|
break;
|
}
|
|
try {
|
|
string result = NetworkApi::get_env_status();
|
CString st = L"";
|
auto doc = JsonUtil::parseUTF16(result);
|
if (doc.IsObject()) {
|
if (doc[L"code"] == 0) {
|
auto data = doc[L"data"].GetObjectW();
|
if (data[L"juejin"].GetInt() == 1) {
|
dlg->labelColors[IDC_STATIC_JUEJIN_STATE] = RGB(0, 0, 0);
|
dlg->labelJueJinState.SetWindowTextW(L"正常");
|
}
|
else {
|
dlg->labelColors[IDC_STATIC_JUEJIN_STATE] = RGB(255, 0, 0);
|
dlg->labelJueJinState.SetWindowTextW(L"异常");
|
}
|
CString kplInfo;
|
auto kplObject = data[L"kpl"].GetObjectW();
|
if (kplObject.HasMember(L"limit_up")) {
|
kplInfo.Append(L"涨停列表-");
|
kplInfo.Append(L"【");
|
kplInfo.Append(data[L"kpl"][L"limit_up"].GetArray()[0].GetString());
|
kplInfo.Append(L"】");
|
kplInfo.Append(L"【");
|
kplInfo.Append(CString(std::to_string(data[L"kpl"][L"limit_up"].GetArray()[1].GetInt()).c_str()));
|
kplInfo.Append(L"】");
|
|
kplInfo.Append(L"\t");
|
}
|
|
if (kplObject.HasMember(L"jingxuan_rank")) {
|
kplInfo.Append(L"精选排行-");
|
kplInfo.Append(L"【");
|
kplInfo.Append(data[L"kpl"][L"jingxuan_rank"].GetArray()[0].GetString());
|
kplInfo.Append(L"】");
|
kplInfo.Append(L"【");
|
kplInfo.Append(CString(std::to_string(data[L"kpl"][L"jingxuan_rank"].GetArray()[1].GetInt()).c_str()));
|
kplInfo.Append(L"】");
|
kplInfo.Append(L"\t");
|
}
|
|
if (kplObject.HasMember(L"industry_rank")) {
|
kplInfo.Append(L"行业排行-");
|
kplInfo.Append(L"【");
|
kplInfo.Append(data[L"kpl"][L"industry_rank"].GetArray()[0].GetString());
|
kplInfo.Append(L"】");
|
kplInfo.Append(L"【");
|
kplInfo.Append(CString(std::to_string(data[L"kpl"][L"industry_rank"].GetArray()[1].GetInt()).c_str()));
|
kplInfo.Append(L"】");
|
kplInfo.Append(L"\t");
|
}
|
dlg->labelKPLDataInfo.SetWindowTextW(kplInfo);
|
|
CString deviceInfo;
|
auto deviceObject = data[L"device"].GetObjectW();
|
if (deviceObject.HasMember(L"cpu")) {
|
deviceInfo.Append(L"CPU-【");
|
deviceInfo.Append(CString(StringUtil::to_string(deviceObject[L"cpu"].GetDouble()).c_str()));
|
deviceInfo.Append(L"%】");
|
deviceInfo.Append(L"\t");
|
}
|
|
if (deviceObject.HasMember(L"memery")) {
|
deviceInfo.Append(L"内存-【");
|
deviceInfo.Append(CString(StringUtil::to_string(deviceObject[L"memery"].GetDouble()).c_str()));
|
deviceInfo.Append(L"%】");
|
}
|
dlg->labelDeviceInfo.SetWindowTextW(deviceInfo);
|
|
if (data.HasMember(L"mysql")) {
|
if (data[L"mysql"].GetInt() == 1) {
|
dlg->labelColors[IDC_STATIC_MYSQL] = RGB(0, 0, 0);
|
dlg->labelMySQL.SetWindowTextW(L"正常");
|
|
}
|
else {
|
dlg->labelColors[IDC_STATIC_MYSQL] = RGB(255, 0, 0);
|
dlg->labelMySQL.SetWindowTextW(L"异常");
|
}
|
|
}
|
if (data.HasMember(L"redis")) {
|
if (data[L"redis"].GetInt() == 1) {
|
dlg->labelColors[IDC_STATIC_REDIS] = RGB(0, 0, 0);
|
dlg->labelRedis.SetWindowTextW(L"正常");
|
}
|
else {
|
dlg->labelColors[IDC_STATIC_REDIS] = RGB(255, 0, 0);
|
dlg->labelRedis.SetWindowTextW(L"异常");
|
}
|
|
}
|
if (data.HasMember(L"redis_async_task_count")) {
|
int count = data[L"redis_async_task_count"].GetInt();
|
dlg->lableRedisAsyncTaskCount.SetWindowTextW(to_wstring(count).c_str());
|
}
|
if (data.HasMember(L"trade_channel_access")) {
|
int state = data[L"trade_channel_access"].GetInt();
|
if (state > 0) {
|
dlg->labelColors[IDC_STATIC_TRADE_CAHNNEL_STATE] = RGB(0, 0, 0);
|
dlg->labelTradeChannelState.SetWindowTextW(L"正常");
|
}
|
else {
|
dlg->labelColors[IDC_STATIC_TRADE_CAHNNEL_STATE] = RGB(255, 0, 0);
|
dlg->labelTradeChannelState.SetWindowTextW(L"异常");
|
}
|
}
|
}
|
else {
|
dlg->labelColors[IDC_STATIC_JUEJIN_STATE] = RGB(255, 0, 0);
|
dlg->labelJueJinState.SetWindowTextW(L"未知");
|
}
|
}
|
}
|
catch (CString st) {
|
dlg->labelColors[IDC_STATIC_JUEJIN_STATE] = RGB(255, 0, 0);
|
dlg->labelJueJinState.SetWindowTextW(st);
|
}
|
if (kill) {
|
break;
|
}
|
|
|
|
|
|
|
Sleep(2000);
|
}
|
|
|
}
|
|
//请求系统日志
|
void MonitorDlg::requestSystemLog(MonitorDlg* dlg)
|
{
|
while (TRUE) {
|
if (kill) {
|
break;
|
}
|
try {
|
string result = NetworkApi::list_system_log(dlg->logStartIndex, 20);
|
cout << result << endl;
|
rapidjson::GenericDocument<rapidjson::UTF16<>> doc = JsonUtil::parseUTF16(result);
|
|
if (doc.IsObject() && doc[L"code"].GetInt() == 0) {
|
list<TradeDealRecord> tempRecordList;
|
//解析结果
|
auto dataList = doc[L"data"][L"list"].GetArray();
|
if (dataList.Size() > 0) {
|
dlg->logStartIndex += dataList.Size();
|
std::list<CString> tempList;
|
for (int i = 0; i < dataList.Size(); i++) {
|
auto item = dataList[i].GetArray();
|
CString time = item[0].GetString();
|
CString level = item[1].GetString();
|
CString content = item[2].GetString();
|
CString contentStr = L"";
|
contentStr.Append(time.Mid(11));
|
contentStr.Append(L" - ");
|
contentStr.Append(L"[");
|
contentStr.Append(level);
|
contentStr.Append(L"] ");
|
contentStr.Append(content);
|
tempList.push_back(contentStr);
|
}
|
CString content;
|
for (std::list<CString>::iterator el = tempList.begin(); el != tempList.end(); ++el) {
|
content.Append(*el);
|
content.Append(L"\r\n");
|
dlg->logList.push_back(*el);
|
}
|
tempList.clear();
|
|
|
//追加文本
|
int nLength = dlg->editLog.GetWindowTextLength();
|
dlg->editLog.SetSel(nLength, nLength);//定位到文本末尾
|
dlg->editLog.ReplaceSel(content);//在文本末尾追加
|
|
|
if (dlg->logList.size() > dlg->MAX_LOG_LINES) {
|
//删除前几行
|
int delLength = 0;
|
int delCount = 0;
|
int delLine = dlg->logList.size() - dlg->MAX_LOG_LINES;
|
for (int i = 0; i < delLine; i++) {
|
delCount += 1;
|
list<CString>::iterator its = (dlg->logList).begin();
|
advance(its, i);
|
CString content = *its;
|
content.Append(L"\r\n");
|
delLength += content.GetLength();
|
}
|
for (int i = 0; i < delCount; i++) {
|
(dlg->logList).pop_front();
|
}
|
//删除前面的文本
|
dlg->editLog.SetSel(0, delLength);
|
dlg->editLog.ReplaceSel(_T(""));
|
int nLength = dlg->editLog.GetWindowTextLength();
|
dlg->editLog.SetSel(nLength, nLength);//定位到文本末尾
|
}
|
}
|
}
|
}
|
catch (...) {
|
|
|
}
|
// 每1s请求一次
|
Sleep(2000);
|
}
|
|
}
|
|
//请求系统日志
|
void MonitorDlg::requestL2ListenActiveCount(MonitorDlg* dlg)
|
{
|
while (TRUE) {
|
if (kill) {
|
break;
|
}
|
try {
|
string result = NetworkApi::get_l2_listen_active_count();
|
cout << result << endl;
|
auto doc = JsonUtil::parseUTF8(result);
|
|
if (doc.IsObject() && doc["code"].GetInt() == 0) {
|
int order = doc["data"]["order"].GetInt();
|
int transaction = doc["data"]["transaction"].GetInt();
|
int market = doc["data"]["market"].GetInt();
|
CString st;
|
st.Append(L"逐笔委托-");
|
st.Append(to_wstring( order).c_str());
|
st.Append(L" ");
|
st.Append(L"逐笔成交-");
|
st.Append(to_wstring(transaction).c_str());
|
st.Append(L" ");
|
st.Append(L"行情-");
|
st.Append(to_wstring(market).c_str());
|
dlg->labelL2ListenData.SetWindowTextW(st);
|
}
|
}
|
catch (...) {
|
|
|
}
|
// 每1s请求一次
|
Sleep(3000);
|
}
|
|
}
|
|
void MonitorDlg::initView()
|
{
|
|
|
//初始化列表
|
listDelegate.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
|
CRect rect;
|
listDelegate.GetClientRect(&rect);
|
listDelegate.SetRowHeigt(24);
|
|
int unitSize = (rect.Width() - 20) / 6.4f;
|
listDelegate.InsertColumn(0, _T("委托时间"), LVCFMT_LEFT, unitSize * 1, 0);
|
listDelegate.InsertColumn(1, _T("合约代码"), LVCFMT_LEFT, unitSize * 1, 1);
|
listDelegate.InsertColumn(2, _T("合约名称"), LVCFMT_LEFT, unitSize * 1.2, 2);
|
listDelegate.InsertColumn(3, _T("操作"), LVCFMT_LEFT, unitSize * 0.8, 3);
|
listDelegate.InsertColumn(4, _T("备注"), LVCFMT_LEFT, unitSize * 1.4, 4);
|
listDelegate.InsertColumn(5, _T("委托数量"), LVCFMT_LEFT, unitSize * 1, 5);
|
listDelegate.AutoColumn();
|
|
|
|
listDeal.GetClientRect(&rect);
|
listDeal.SetRowHeigt(24);
|
unitSize = (rect.Width() - 20) / 6.4f;
|
listDeal.InsertColumn(0, _T("序号"), LVCFMT_LEFT, unitSize * 0.4, 0);
|
listDeal.InsertColumn(1, _T("交易ID"), LVCFMT_LEFT, unitSize * 2, 0);
|
listDeal.InsertColumn(2, _T("合约代码"), LVCFMT_LEFT, unitSize * 1, 1);
|
listDeal.InsertColumn(3, _T("操作"), LVCFMT_LEFT, unitSize * 0.7, 2);
|
listDeal.InsertColumn(4, _T("成交时间"), LVCFMT_LEFT, unitSize * 1, 3);
|
listDeal.InsertColumn(5, _T("成交价格"), LVCFMT_LEFT, unitSize * 0.9, 4);
|
listDeal.InsertColumn(6, _T("成交数量"), LVCFMT_LEFT, unitSize * 0.8, 5);
|
listDeal.AutoColumn();
|
|
|
}
|
|
MonitorDlg::MonitorDlg(CWnd* pParent /*=nullptr*/)
|
: CDialogEx(IDD_MONITOR, pParent)
|
{
|
|
}
|
|
MonitorDlg::~MonitorDlg()
|
{
|
}
|
|
void MonitorDlg::DoDataExchange(CDataExchange* pDX)
|
{
|
CDialogEx::DoDataExchange(pDX);
|
DDX_Control(pDX, IDC_LIST_L2_CODES, listL2Codes);
|
DDX_Control(pDX, IDC_LIST_DELEGATE, listDelegate);
|
DDX_Control(pDX, IDC_LIST_DEAL, listDeal);
|
DDX_Control(pDX, IDC_EDIT_CODE, editCode);
|
DDX_Control(pDX, IDC_STATIC_HUAXIN_TRADE_CHANNEL, labelHXTradeChannel);
|
DDX_Control(pDX, IDC_STATIC_JUEJIN_STATE, labelJueJinState);
|
DDX_Control(pDX, IDC_STATIC_KPL_DATA, labelKPLDataInfo);
|
DDX_Control(pDX, IDC_STATIC_DEVICE_INFO, labelDeviceInfo);
|
DDX_Control(pDX, IDC_STATIC_MYSQL, labelMySQL);
|
DDX_Control(pDX, IDC_STATIC_REDIS, labelRedis);
|
DDX_Control(pDX, IDC_STATIC_REDIS_TEST_RESULT, labelRedisTestResult);
|
DDX_Control(pDX, IDC_STATIC_REDIS_ASYNC_TASK_COUNT, lableRedisAsyncTaskCount);
|
DDX_Control(pDX, IDC_STATIC_TRADE_CAHNNEL_STATE, labelTradeChannelState);
|
DDX_Control(pDX, IDC_STATIC_L2_SUBSCRIPT_CODES_UPDATE_TIME, labelL2SubscriptCodesUpdateTime);
|
DDX_Control(pDX, IDC_EDIT1, editLog);
|
DDX_Control(pDX, IDC_STATIC_L2_LISTEN_ACTIVE, labelL2ListenData);
|
}
|
|
|
BEGIN_MESSAGE_MAP(MonitorDlg, CDialogEx)
|
ON_BN_CLICKED(IDC_BUTTON_REFRESH_DELEGATE, &MonitorDlg::OnBnClickedButtonRefreshDelegate)
|
ON_BN_CLICKED(IDC_BUTTON_REFRESH_DEAL, &MonitorDlg::OnBnClickedButtonRefreshDeal)
|
ON_BN_CLICKED(IDC_BUTTON_REFRESH_POSITION, &MonitorDlg::OnBnClickedButtonRefreshPosition)
|
ON_BN_CLICKED(IDC_BUTTON_REFRESH_MONEY, &MonitorDlg::OnBnClickedButtonRefreshMoney)
|
|
ON_WM_CLOSE()
|
ON_BN_CLICKED(IDC_BUTTON_EXPORT_L2, &MonitorDlg::OnBnClickedButtonExportL2)
|
ON_BN_CLICKED(IDC_BUTTON_INIT_DATA, &MonitorDlg::OnBnClickedButtonInitData)
|
ON_WM_CTLCOLOR()
|
ON_BN_CLICKED(IDC_BUTTON_REDIS_TEST, &MonitorDlg::OnBnClickedButtonRedisTest)
|
ON_BN_CLICKED(IDC_BUTTON_SYNC_SHSZ_CODES, &MonitorDlg::OnBnClickedButtonSyncShszCodes)
|
ON_BN_CLICKED(IDC_BUTTON_SAVE_RUNNING_DATA, &MonitorDlg::OnBnClickedButtonSaveRunningData)
|
END_MESSAGE_MAP()
|
|
|
// MonitorDlg 消息处理程序
|
|
|
void MonitorDlg::OnBnClickedButtonRefreshDelegate()
|
{
|
|
try {
|
NetworkApi::sync_trade_data("delegate_list");
|
MessageBox(_T("刷新成功"), _T("温馨提示"), MB_TASKMODAL);
|
}
|
catch (CString st) {
|
AfxMessageBox(st);
|
}
|
catch (wstring st) {
|
AfxMessageBox(CString(st.c_str()));
|
}
|
}
|
|
|
void MonitorDlg::OnBnClickedButtonRefreshDeal()
|
{
|
try {
|
NetworkApi::sync_trade_data("deal_list");
|
MessageBox(_T("刷新成功"), _T("温馨提示"), MB_TASKMODAL);
|
}
|
catch (CString st) {
|
AfxMessageBox(st);
|
}
|
catch (wstring st) {
|
AfxMessageBox(CString(st.c_str()));
|
}
|
}
|
|
|
void MonitorDlg::OnBnClickedButtonRefreshPosition()
|
{
|
try {
|
NetworkApi::sync_trade_data("position_list");
|
MessageBox(_T("刷新成功"), _T("温馨提示"), MB_TASKMODAL);
|
}
|
catch (CString st) {
|
AfxMessageBox(st);
|
}
|
catch (wstring st) {
|
AfxMessageBox(CString(st.c_str()));
|
}
|
}
|
|
|
void MonitorDlg::OnBnClickedButtonRefreshMoney()
|
{
|
try {
|
NetworkApi::sync_trade_data("money");
|
MessageBox(_T("刷新成功"), _T("温馨提示"), MB_TASKMODAL);
|
}
|
catch (CString st) {
|
AfxMessageBox(st);
|
}
|
catch (wstring st) {
|
AfxMessageBox(CString(st.c_str()));
|
}
|
}
|
|
|
|
|
|
|
BOOL MonitorDlg::OnInitDialog()
|
{
|
CDialogEx::OnInitDialog();
|
|
initView();
|
|
kill = FALSE;
|
logStartIndex = 1;
|
|
l2RefreshThread = std::thread(requestL2CodeList, this);
|
delegateRefreshThread = std::thread(requestDelegateList, this);
|
dealRefreshThread = std::thread(requestDealList, this);
|
autoRefreshThread = std::thread(autoRefresh, this);
|
systemLogThread = std::thread(requestSystemLog, this);
|
l2ListenActiveThread = std::thread(requestL2ListenActiveCount, this);
|
|
//启动
|
l2RefreshThread.detach();
|
delegateRefreshThread.detach();
|
dealRefreshThread.detach();
|
autoRefreshThread.detach();
|
systemLogThread.detach();
|
l2ListenActiveThread.detach();
|
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
// 异常: OCX 属性页应返回 FALSE
|
}
|
|
|
void MonitorDlg::OnClose()
|
{
|
kill = TRUE;
|
if (l2RefreshThread.joinable())
|
l2RefreshThread.join();
|
if (delegateRefreshThread.joinable())
|
delegateRefreshThread.join();
|
if (dealRefreshThread.joinable())
|
dealRefreshThread.join();
|
if (autoRefreshThread.joinable())
|
autoRefreshThread.join();
|
|
CDialogEx::OnClose();
|
}
|
|
|
void MonitorDlg::OnBnClickedButtonExportL2()
|
{
|
CString code;
|
editCode.GetWindowTextW(code);
|
if (code.GetLength() != 6) {
|
AfxMessageBox(L"代码格式不正确");
|
return;
|
}
|
|
string result = NetworkApi::export_l2_data(code);
|
auto doc = JsonUtil::parseUTF16(result);
|
if (doc.IsObject()) {
|
if (doc[L"code"].GetInt() == 0) {
|
MessageBox(L"导出成功", L"提示");
|
}
|
else {
|
AfxMessageBox(doc[L"msg"].GetString());
|
}
|
}
|
else {
|
AfxMessageBox(L"返回数据非JSON格式");
|
}
|
}
|
|
|
void MonitorDlg::OnBnClickedButtonInitData()
|
{
|
string result = NetworkApi::every_init();
|
auto doc = JsonUtil::parseUTF16(result);
|
if (doc.IsObject()) {
|
if (doc[L"code"].GetInt() == 0) {
|
MessageBox(L"初始化成功", L"提示");
|
}
|
else {
|
AfxMessageBox(doc[L"msg"].GetString());
|
}
|
}
|
else {
|
AfxMessageBox(L"返回数据非JSON格式");
|
}
|
}
|
|
|
HBRUSH MonitorDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
|
{
|
HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
|
|
if (nCtlColor == CTLCOLOR_STATIC) {
|
int nID = pWnd->GetDlgCtrlID();
|
auto iterator = labelColors.find(nID);
|
if (iterator != labelColors.end()) {
|
pDC->SetTextColor(iterator->second);
|
}
|
}
|
return hbr;
|
}
|
|
|
void MonitorDlg::OnBnClickedButtonRedisTest()
|
{
|
// Redis测速
|
string result = NetworkApi::test_redis();
|
auto resultDoc = JsonUtil::parseUTF8(result);
|
string st = "";
|
if (resultDoc["code"].GetInt() == 0) {
|
auto arr = resultDoc["data"].GetArray();
|
for (int i = 0; i < arr.Size(); i++) {
|
st.append(StringUtil::to_string(arr[i].GetDouble() * 1000));
|
st.append("ms");
|
if (i< arr.Size() - 1) {
|
st.append(",");
|
}
|
}
|
labelRedisTestResult.SetWindowTextW(CString(st.c_str()));
|
|
}
|
|
|
}
|
|
|
void MonitorDlg::OnBnClickedButtonSyncShszCodes()
|
{
|
string result = NetworkApi::sync_l1_subscript_codes();
|
auto resultDoc = JsonUtil::parseUTF8(result);
|
if (resultDoc.IsObject() && resultDoc["code"].GetInt() == 0) {
|
int count = resultDoc["data"]["codes_sh"].GetInt() + resultDoc["data"]["codes_sz"].GetInt();
|
CString msg;
|
msg.Append(L"更新成功,代码总数:");
|
msg.Append(std::to_wstring(count).c_str());
|
MessageBox(msg, L"提示");
|
}
|
else {
|
AfxMessageBox(L"更新失败");
|
}
|
|
}
|
|
|
void MonitorDlg::OnBnClickedButtonSaveRunningData()
|
{
|
string result = NetworkApi::save_running_data();
|
auto resultDoc = JsonUtil::parseUTF16(result);
|
if (resultDoc.IsObject() && resultDoc[L"code"].GetInt() == 0) {
|
MessageBox(L"保存成功!", L"提示");
|
}
|
else {
|
AfxMessageBox(resultDoc[L"msg"].GetString());
|
}
|
|
}
|