// FloatTradeDlg.cpp: 实现文件
|
//
|
|
#include "common/pch.h"
|
#include "FloatTrade.h"
|
#include "FloatTradeDlg.h"
|
#include "afxdialogex.h"
|
#include "../common/JsonUtil.h"
|
#include <iostream>
|
#include "base64.h"
|
#include "../common/StringUtil.h"
|
#include "ConfigUtil.h"
|
#include "../common/NetworkApi.h"
|
#include "../common/LowSuctionNetworkApi.h"
|
#include "../common/TimeUtil.h"
|
|
#ifdef _DEBUG
|
#define new DEBUG_NEW
|
#endif
|
#include <string>
|
#include <locale>
|
#include <codecvt>
|
#include <thread>
|
#include "../common/Win32Util.h"
|
#include "../common/TimeUtil.h"
|
#include "ThsUtil.h"
|
#include "CSettingDlg.h"
|
#include "CBuyDlg.h"
|
#include "SellRuleDlg.h"
|
#include "MyApi.h"
|
#include "CCBBuyDlg.h"
|
#include "Constant.h"
|
#include "PositionDlg.h"
|
#include "DealQueueDlg.h"
|
#include <regex>
|
|
struct ViewDetailData {
|
string code;
|
};
|
|
|
// CFloatTradeDlg 对话框
|
|
//定义快捷键
|
const int HOT_KEY_SELL_ALL = 1;
|
const int HOT_KEY_CANCEL = 2;
|
const int HOT_KEY_BUY = 3;
|
const int HOT_KEY_UPDATE_BSD = 4;// 更新板上盯
|
const int HOT_KEY_ADD_WANT_BUY = 6;// 加想买
|
|
// 可转债消息
|
#define WM_CB_WINDOW (WM_APP + 1000)
|
|
|
bool CFloatTradeDlg::breakCancelMsg;
|
HHOOK CFloatTradeDlg::hMouseHook;
|
long CFloatTradeDlg::ocrCodeExpireTimestamp;
|
|
|
|
string CFloatTradeDlg::getCode()
|
{
|
CString csX;
|
editCode.GetWindowText(csX);
|
string code = StringUtil::cstring2String(csX);
|
if (code.length() == 0) {
|
throw wstring(L"尚未获取到目标代码");
|
}
|
else if (code.length() != 6) {
|
throw wstring(L"目标代码长度不为6位");
|
}
|
return code;
|
}
|
|
void CFloatTradeDlg::setMsg(CString msg, MSG_TYPE msgType, bool autoCancel)
|
{
|
labelAtrribute.SetWindowTextW(msg);
|
if (msgType == MSG_TYPE_INFO) {
|
msgColor = COLOR_BLACK;
|
}
|
else if (msgType == MSG_TYPE_SUCCESS) {
|
msgColor = COLOR_RED;
|
}
|
else if (msgType == MSG_TYPE_FAIL) {
|
msgColor = COLOR_GREEN;
|
}
|
//重新绘制
|
labelAtrribute.Invalidate();
|
|
breakCancelMsg = TRUE;
|
if (autoCancel) {
|
if (cancelMsgThread != nullptr) {
|
//
|
delete cancelMsgThread;
|
}
|
cancelMsgThread = new std::thread(clearMsg, this);
|
cancelMsgThread->detach();
|
}
|
}
|
|
|
void CFloatTradeDlg::showTips(CString message, int msgType, int delayMs, int position)
|
{
|
TipDlg* p_MsgWindow = new TipDlg(delayMs, position, this);
|
p_MsgWindow->Create(IDD_DIALOG_TIPS, this);
|
if (msgType == MSG_TYPE_INFO) {
|
msgColor = COLOR_BLACK;
|
}
|
else if (msgType == MSG_TYPE_SELL_SUCCESS) {
|
msgColor = COLOR_BLUE;
|
}
|
else if (msgType == MSG_TYPE_SUCCESS) {
|
msgColor = COLOR_RED;
|
}
|
else if (msgType == MSG_TYPE_FAIL) {
|
msgColor = COLOR_GREEN;
|
}
|
else if (msgType == MSG_TYPE_WARNING) {
|
msgColor = COLOR_ORANGE;
|
}
|
p_MsgWindow->setMsg(message, msgColor);
|
p_MsgWindow->ShowWindow(SW_SHOW);
|
}
|
|
void CFloatTradeDlg::getTradeState(CFloatTradeDlg* context)
|
{
|
try {
|
bool can = NetworkApi::get_buy_state();
|
if (can) {
|
context->btnOpenBuy.SetWindowTextW(L"开启交易※");
|
context->btnCloseBuy.SetWindowTextW(L"关闭交易");
|
}
|
else {
|
context->btnOpenBuy.SetWindowTextW(L"开启交易");
|
context->btnCloseBuy.SetWindowTextW(L"关闭交易※");
|
}
|
}
|
catch (...) {
|
context->setMsg(L"获取交易状态失败", MSG_TYPE_FAIL);
|
}
|
}
|
|
void CFloatTradeDlg::getAutoCancelSellMode(CFloatTradeDlg* context, string code)
|
{
|
try {
|
int mode = NetworkApi::get_auto_cancel_sell_mode(code);
|
if (mode == 0) {
|
context->checkAutoCancelSell.SetCheck(TRUE);
|
}
|
else {
|
context->checkAutoCancelSell.SetCheck(FALSE);
|
}
|
}
|
catch (...) {
|
context->setMsg(L"获取交易状态失败", MSG_TYPE_FAIL);
|
}
|
}
|
|
void CFloatTradeDlg::getContinueBuyInfo(CFloatTradeDlg* context, string code)
|
{
|
try {
|
string msg = NetworkApi::get_continue_buy_info(code);
|
auto doc = JsonUtil::parseUTF8(msg);
|
if (doc.IsObject()) {
|
if (doc["code"].GetInt() == 0) {
|
int money = doc["data"]["money"].GetInt();
|
((CButton*)context->GetDlgItem(IDC_CHECK_CONTINUE_BUY))->SetCheck(money>0);
|
CComboBox *comboMoneyList = (CComboBox*)context->GetDlgItem(IDC_COMBO_CONTINUE_BUY_MONEY);
|
int count = comboMoneyList->GetCount();
|
if (count == 0) {
|
auto money_list = doc["data"]["money_list"].GetArray();
|
for (int i = 0; i < money_list.Size(); i++) {
|
comboMoneyList->AddString(to_wstring(money_list[i].GetInt()).c_str());
|
}
|
}
|
// 查看是否有和money相等的选项
|
for (int i = 0; i < comboMoneyList->GetCount(); i++) {
|
CString strItem;
|
comboMoneyList->GetLBText(i, strItem);
|
if (_ttoi(strItem) == money) {
|
comboMoneyList -> SetCurSel(i);
|
break;
|
}
|
}
|
}
|
}
|
}
|
catch (...) {
|
|
}
|
}
|
|
void CFloatTradeDlg::setContinueBuyMoney(CFloatTradeDlg* context, string code, int money)
|
{
|
|
}
|
|
|
void CFloatTradeDlg::getTradeMode(CFloatTradeDlg* context)
|
{
|
/*try {
|
int mode = NetworkApi::get_buy_mode();
|
if (mode == 0) {
|
context->btnBuyModeAll.SetWindowTextW(L"全部都买*");
|
context->btnBuyModeWant.SetWindowTextW(L"仅买想买");
|
}
|
else {
|
context->btnBuyModeAll.SetWindowTextW(L"全部都买");
|
context->btnBuyModeWant.SetWindowTextW(L"仅买想买*");
|
}
|
}
|
catch (...) {
|
context->setMsg(L"获取交易模式失败", MSG_TYPE_FAIL);
|
}*/
|
|
|
}
|
|
void CFloatTradeDlg::clearMsg(CFloatTradeDlg* context)
|
{
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
breakCancelMsg = FALSE;
|
//10s之后小时
|
for (int i = 0; i < 1000; i++) {
|
if (breakCancelMsg) {
|
return;
|
}
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
}
|
|
context->labelAtrribute.SetWindowTextW(L"");
|
}
|
|
void CFloatTradeDlg::getCodeDesc(string code, CFloatTradeDlg* context)
|
{
|
|
//请求网络获取消息
|
try {
|
wstring result = NetworkApi::getCodeDesc(code);
|
CString resultC(result.c_str());
|
//context->setMsg(resultC, MSG_TYPE_INFO, FALSE);
|
context->labelCodeInfo.SetWindowTextW(resultC);
|
}
|
catch (wstring st) {
|
/*CString msgc;
|
msgc.Append(CString(code.c_str()));
|
msgc.Append(L":");
|
msgc.Append(st.c_str());
|
context->setMsg(msgc, MSG_TYPE_FAIL);*/
|
}
|
catch (CString st) {
|
/* CString msgc;
|
msgc.Append(CString(code.c_str()));
|
msgc.Append(L":");
|
msgc.Append(st);
|
context->setMsg(msgc, MSG_TYPE_FAIL);*/
|
}
|
|
}
|
|
void CFloatTradeDlg::requestCodePosition(string code, CFloatTradeDlg* context, bool showCodeDesc, int delayMs)
|
{
|
if (delayMs > 0) {
|
std::this_thread::sleep_for(std::chrono::milliseconds(delayMs));
|
}
|
context->sellManager->init(code);
|
try {
|
CodePosition newCodePosition;
|
// 如果是持仓代码就不更新代码信息
|
if (context->positionMap.find(code) != context->positionMap.end()) {
|
newCodePosition = context->positionMap[code];
|
CString resultC;
|
resultC.Append(CString(newCodePosition.code.c_str()));
|
resultC.Append(L" ");
|
resultC.Append(newCodePosition.name);
|
context->setMsg(resultC, MSG_TYPE_INFO, FALSE);
|
std::thread t1(updateCodePosition, code, context);
|
t1.detach();
|
}
|
else {
|
string result = NetworkApi::get_code_position_info(code);
|
auto doc = JsonUtil::parseUTF16(result);
|
if (doc.IsObject()) {
|
|
if (doc[_T("data")].HasMember(L"code_info"))
|
{
|
auto data = doc[_T("data")].GetObjectW();
|
CString c = data[_T("code_info")].GetArray()[0].GetString();
|
wstring name = L"";
|
// 获取输入框的内容
|
if (context != nullptr) {
|
CString realCode;
|
context->editCode.GetWindowTextW(realCode);
|
if (c != realCode) {
|
return;
|
}
|
}
|
}
|
newCodePosition.total = doc[L"data"][L"total"].GetInt();
|
newCodePosition.available = doc[L"data"][L"available"].GetInt();
|
newCodePosition.costPrice = doc[L"data"][L"cost_price"].GetFloat();
|
newCodePosition.sell_rules_count = doc[L"data"][L"sell_rules_count"].GetInt();
|
list<int> sellVolumes;
|
if (doc[L"data"].HasMember(L"sell_orders")) {
|
auto sell_orders_array = doc[L"data"][L"sell_orders"].GetArray();
|
|
for (int i = 0; i < sell_orders_array.Size(); i++) {
|
sellVolumes.push_back(sell_orders_array[i].GetInt());
|
}
|
}
|
newCodePosition.sell_orders = sellVolumes;
|
|
if (showCodeDesc && doc[_T("data")].HasMember(L"code_info"))
|
{
|
auto data = doc[_T("data")].GetObjectW();
|
CString c = data[_T("code_info")].GetArray()[0].GetString();
|
wstring name = L"";
|
if (!data[_T("code_info")].GetArray()[1].IsNull()) {
|
name = data[_T("code_info")].GetArray()[1].GetString();
|
}
|
if (data.HasMember(L"desc")) {
|
wstring desc = data[_T("desc")].GetString();
|
wstring fresult;
|
fresult.append(c).append(L" ").append(name).append(L" ").append(desc);
|
CString resultC(fresult.c_str());
|
context->setMsg(resultC, MSG_TYPE_INFO, FALSE);
|
}
|
}
|
|
}
|
}
|
|
|
CodePosition* codePosition = context->sellManager->getCodePosition(code);
|
/*codePosition->total = newCodePosition.total;
|
codePosition->available = newCodePosition.available;
|
codePosition->sell_rules_count = newCodePosition.sell_rules_count;
|
codePosition->costPrice = newCodePosition.costPrice;*/
|
|
|
|
// TODO 测试
|
//codePosition->sell_orders.clear();
|
//codePosition->sell_orders.push_back(900);
|
//codePosition->available = 900;
|
|
|
// 设置卖框显示的内容
|
if (context->sellDlgMap.find(code) != context->sellDlgMap.end()) {
|
context->sellDlgMap[code]->SetPositionInfo(newCodePosition.total, newCodePosition.available);
|
}
|
|
//设置内容
|
context->showCodePositionInfo();
|
context->initSellSettingView();
|
}
|
catch (wstring st) {
|
context->setMsg(CString(st.c_str()), MSG_TYPE_FAIL);
|
}
|
// 设置数据请求完毕
|
if (context->requestingCode == code) {
|
context->requestingCode = "";
|
}
|
|
string nowTime = TimeUtil::getNowTime("%H%M%S");
|
// 09:26:00之前都是跌停价卖
|
if (stoi(nowTime) < stoi("092500")) {
|
context->comboSellPriceType.SetCurSel(1);
|
}
|
else {
|
context->comboSellPriceType.SetCurSel(0);
|
}
|
|
SellSetting* sellSetting = context->sellManager->getSellSetting(code);
|
|
if (sellSetting->lockBuyMoney > 0) {
|
context->editBuyMoney.SetWindowTextW(to_wstring(sellSetting->lockBuyMoney).c_str());
|
}
|
else {
|
context->editBuyMoney.SetWindowTextW(to_wstring(ConfigUtil::getBuyMoney()).c_str());
|
}
|
|
if (sellSetting->lock) {
|
context->checkLockVolume.SetCheck(TRUE);
|
}
|
else {
|
context->checkLockVolume.SetCheck(FALSE);
|
}
|
|
int money = context->sellManager->computeCurrentMoney(code);
|
context->editSellMoney.SetWindowTextW(to_wstring(money).c_str());
|
|
}
|
|
void CFloatTradeDlg::updateCodePosition(string code, CFloatTradeDlg* context)
|
{
|
try {
|
string result = NetworkApi::get_code_position_info(code);
|
auto doc = JsonUtil::parseUTF16(result);
|
if (doc.IsObject()) {
|
if (context->positionMap.find(code) != context->positionMap.end()) {
|
CodePosition codePosition = context->positionMap[code];
|
codePosition.total = doc[L"data"][L"total"].GetInt();
|
codePosition.available = doc[L"data"][L"available"].GetInt();
|
codePosition.costPrice = doc[L"data"][L"cost_price"].GetFloat();
|
}
|
CodePosition* codePosition = context->sellManager->getCodePosition(code);
|
if (codePosition != nullptr) {
|
codePosition->total = doc[L"data"][L"total"].GetInt();
|
codePosition->available = doc[L"data"][L"available"].GetInt();
|
codePosition->costPrice = doc[L"data"][L"cost_price"].GetFloat();
|
}
|
}
|
}
|
catch (...) {
|
cout << "出错" << endl;
|
}
|
}
|
|
void CFloatTradeDlg::requestSellResult(int order_ref, CFloatTradeDlg* context, int delayMs)
|
{
|
if (delayMs > 0) {
|
std::this_thread::sleep_for(std::chrono::milliseconds(delayMs));
|
}
|
try {
|
// 测试
|
string result = NetworkApi::get_sell_result(order_ref);
|
//string result = string(StringUtil::cstring2String(L"{\"code\":0,\"data\":{\"msg\":\"成交\"}}"));
|
|
auto doc = JsonUtil::parseUTF16(result);
|
if (doc.IsObject()) {
|
if (doc[L"code"] == 0) {
|
auto data = doc[L"data"].GetObjectW();
|
CString msg = data[L"msg"].GetString();
|
MSG_TYPE msgType = MSG_TYPE_INFO;
|
if (msg.Find(L"成交") >= 0) {
|
msgType = MSG_TYPE_SELL_SUCCESS;
|
}
|
else if (msg.Find(L"撤单") >= 0) {
|
msgType = MSG_TYPE_FAIL;
|
}
|
|
showFloatMsg(context, msg, msgType);
|
|
|
CString code;
|
context->editCode.GetWindowText(code);
|
if (code && code.GetLength() == 6) {
|
requestCodePosition(StringUtil::cstring2String(code), context, FALSE);
|
}
|
}
|
else {
|
showFloatMsg(context, doc[L"msg"].GetString(), MSG_TYPE_FAIL);
|
}
|
}
|
}
|
catch (wstring st) {
|
showFloatMsg(context, st.c_str(), MSG_TYPE_FAIL);
|
}
|
// 更新持仓
|
requestAllPositions(context);
|
if (context->positionDialog != nullptr) {
|
context->positionDialog->updatePositions();
|
}
|
}
|
|
void CFloatTradeDlg::regularUpdatePositionInfo(CFloatTradeDlg* context)
|
{
|
|
while (TRUE) {
|
|
try {
|
string nowTime = TimeUtil::getNowTime("%H%M%S");
|
// 09:26:00之前都是跌停价卖
|
if (stoi(nowTime) >= stoi("093000") && stoi(nowTime) <= stoi("093003")) {
|
//if (stoi(nowTime) >= stoi("154000") && stoi(nowTime) <= stoi("155000")) {
|
CString codew;
|
context->editCode.GetWindowTextW(codew);
|
if (codew.GetLength() == 6) {
|
string code = StringUtil::cstring2String(codew);
|
// 更新持仓
|
requestCodePosition(code, context, FALSE);
|
}
|
}
|
}
|
catch (...) {
|
|
}
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
}
|
}
|
|
void CFloatTradeDlg::runPushMsgHeart(CFloatTradeDlg* context, SOCKET socket)
|
{
|
|
while (TRUE) {
|
rapidjson::StringBuffer buf;
|
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buf);
|
writer.StartObject();
|
writer.Key("type");
|
writer.String("heart");
|
writer.Key("data");
|
writer.StartObject();
|
writer.EndObject();
|
writer.EndObject();
|
string json_content = buf.GetString();
|
string data = NetworkApi::load_request_data(json_content);
|
try {
|
int result = send(socket, data.c_str(), strlen(data.c_str()), 0);
|
if (result < 0) {
|
throw string("发送失败");
|
}
|
}
|
catch (...) {
|
break;
|
}
|
std::this_thread::sleep_for(std::chrono::milliseconds(5 * 1000));
|
}
|
|
}
|
|
void CFloatTradeDlg::runPushMsgReceiver(CFloatTradeDlg* context)
|
{
|
while (TRUE) {
|
try {
|
SOCKET socket = SocketManager::createSocket();
|
|
rapidjson::StringBuffer buf;
|
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buf);
|
writer.StartObject();
|
writer.Key("type");
|
writer.String("register_msg_receiver");
|
writer.Key("data");
|
writer.StartObject();
|
writer.Key("types");
|
writer.StartArray();
|
writer.String("order_almost_deal");
|
writer.String("delegate_order_danger");
|
writer.EndArray();
|
writer.EndObject();
|
writer.EndObject();
|
string json_content = buf.GetString();
|
string data = NetworkApi::load_request_data(json_content);
|
SocketManager::sendMsg(socket, data.c_str());
|
std::thread t1(runPushMsgHeart, context, socket);
|
t1.detach();
|
// 注册成功
|
while (TRUE) {
|
// 接收消息
|
string result = SocketManager::receiveMsg(socket);
|
auto doc = JsonUtil::parseUTF16(result);
|
if (doc.IsObject() && doc[L"code"] == 0) {
|
if (doc.HasMember(L"data")) {
|
CString type = doc[L"data"][L"type"].GetString();
|
if (type == L"order_almost_deal") {
|
auto data = doc[L"data"][L"data"].GetObjectW();
|
if (data.HasMember(L"code") && data.HasMember(L"code_name"))
|
{
|
CString st;
|
st.Append(data[L"code"].GetString());
|
st.Append(L" ");
|
st.Append(data[L"code_name"].GetString());
|
st.Append(L" 即将买入:");
|
st.Append(data[L"msg"].GetString());
|
|
std::thread t1(context->showFloatMsg, context, st, MSG_TYPE_WARNING, 5000, TipDlg::POSITION_RIGHT_BOTTOM);
|
t1.detach();
|
}
|
}
|
else if (type == L"delegate_order_danger") {
|
auto data = doc[L"data"][L"data"].GetObjectW();
|
if (data.HasMember(L"code") && data.HasMember(L"code_name"))
|
{
|
CString st;
|
st.Append(data[L"code"].GetString());
|
st.Append(L" ");
|
st.Append(data[L"code_name"].GetString());
|
st.Append(L" 封单不足:");
|
st.Append(data[L"msg"].GetString());
|
std::thread t1(context->showFloatMsg, context, st, MSG_TYPE_WARNING, 5000, TipDlg::POSITION_RIGHT_BOTTOM);
|
t1.detach();
|
}
|
}
|
}
|
}
|
cout << result << endl;
|
}
|
|
}
|
catch (...) {
|
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
}
|
|
}
|
|
}
|
|
void CFloatTradeDlg::startShake(CFloatTradeDlg* context, CString text)
|
{
|
|
}
|
|
void CFloatTradeDlg::showCodePositionInfo()
|
{
|
string code = getInputCode();
|
sellManager->init(code);
|
CodePosition* codePosition = sellManager->getCodePosition(code);
|
SellSetting* sellSetting = sellManager->getSellSetting(code);
|
if (codePosition->sell_rules_count > 0) {
|
btnSellRule.SetWindowTextW(L"条件单※");
|
}
|
else {
|
btnSellRule.SetWindowTextW(L"条件单");
|
}
|
|
CString totalStr;
|
totalStr.Append(L"¥");
|
totalStr.Append(std::to_wstring((int)(codePosition->total * codePosition->costPrice * 100) / 100).c_str());
|
labelTotalPosition.SetWindowTextW(totalStr);
|
|
CString availableStr;
|
availableStr.Append(L"¥");
|
availableStr.Append(std::to_wstring((int)(codePosition->available * codePosition->costPrice * 100) / 100).c_str());
|
|
|
labelSelledVolume.SetWindowTextW(availableStr);
|
fillSellMoney(code, codePosition->available);
|
|
checkLockBuyVolume.SetCheck(sellSetting->lockBuy);
|
//if (sellSetting->lockBuy) {
|
// if (sellSetting->lockBuyMoney > 0) {
|
// editBuyMoney.SetWindowTextW(to_wstring(sellSetting->lockBuyMoney).c_str());
|
// }
|
//}
|
//else {
|
// string nowTime = TimeUtil::getNowTime("%H%M%S");
|
// // 09:25:00之前都是跌停价卖
|
// if (stoi(nowTime) < stoi("093000")) {
|
// editBuyMoney.SetWindowTextW(std::to_wstring((int)(codePosition->total * codePosition->costPrice * 100) / 100).c_str());
|
// }
|
// else {
|
// editBuyMoney.SetWindowTextW(L"");
|
// }
|
//}
|
|
}
|
|
list<UINT> CFloatTradeDlg::distributeVolume(UINT total, UINT percent)
|
{
|
list<UINT> volumeList;
|
UINT base = total / percent;
|
UINT left = total % percent;
|
for (UINT i = 0; i < percent; i++) {
|
if (i + 1 <= left) {
|
volumeList.push_back(base + 1);
|
}
|
else {
|
volumeList.push_back(base);
|
}
|
}
|
return volumeList;
|
}
|
|
UINT CFloatTradeDlg::computeSellVolume(list<UINT> volumeList, list<int> sell_volumes)
|
{
|
if (sell_volumes.size() >= volumeList.size()) {
|
return 0;
|
}
|
list<UINT>::iterator el = volumeList.begin();
|
advance(el, sell_volumes.size());
|
if (el != volumeList.end()) {
|
return *el;
|
}
|
return 0;
|
}
|
|
CFloatTradeDlg::CFloatTradeDlg(CWnd* pParent /*=nullptr*/)
|
: CDialogEx(IDD_TRADE, pParent)
|
{
|
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
|
}
|
|
void CFloatTradeDlg::DoDataExchange(CDataExchange* pDX)
|
{
|
CDialogEx::DoDataExchange(pDX);
|
DDX_Control(pDX, label_atrribute, labelAtrribute);
|
DDX_Control(pDX, btn_close_buy, btnCloseBuy);
|
DDX_Control(pDX, btn_open_buy, btnOpenBuy);
|
//DDX_Control(pDX, btn_buy_mode_want, btnBuyModeWant);
|
//DDX_Control(pDX, btn_buy_mode_all, btnBuyModeAll);
|
DDX_Control(pDX, check_auto_refresh, checkAutoRefresh);
|
DDX_Control(pDX, check_auto_click, checkAutoCancelSell);
|
DDX_Control(pDX, check_trade_quick_key, checkTradeQuickKey);
|
DDX_Control(pDX, btn_white_list, whiteList);
|
DDX_Control(pDX, btn_black_list, blackList);
|
DDX_Control(pDX, btn_sell, btnSell);
|
DDX_Control(pDX, btn_already_canceled, btnCancelBuy);
|
|
|
DDX_Control(pDX, edit_code, editCode);
|
//DDX_Control(pDX, btn_buy, btnBuy);
|
DDX_Control(pDX, IDC_STATIC_TOTAL_POSITION, labelTotalPosition);
|
DDX_Control(pDX, IDC_STATIC_ALREADY_SELL, labelSelledVolume);
|
DDX_Control(pDX, IDC_EDIT_SELL_VOLUME, editSellMoney);
|
DDX_Control(pDX, IDC_COMBO_SELL_PRICE, comboSellPriceType);
|
DDX_Control(pDX, btn_code_trade_info, btnSellRule);
|
DDX_Control(pDX, IDC_CHECK_LOCK_SELL_VOLUME, checkLockVolume);
|
DDX_Control(pDX, IDC_CHECK_LOCK_BUY_VOLUME, checkLockBuyVolume);
|
DDX_Control(pDX, IDC_EDIT_BUY_VOLUME, editBuyMoney);
|
DDX_Control(pDX, label_code_info, labelCodeInfo);
|
DDX_Control(pDX, btn_buy, btnBuy);
|
DDX_Control(pDX, IDC_COMBO_BUY_PRICE, comboBuyPriceType);
|
}
|
|
BEGIN_MESSAGE_MAP(CFloatTradeDlg, CDialogEx)
|
ON_WM_PAINT()
|
ON_WM_QUERYDRAGICON()
|
ON_WM_HOTKEY()
|
ON_BN_CLICKED(btn_already_canceled, &CFloatTradeDlg::OnClickedBtnAlreadyCanceled)
|
ON_BN_CLICKED(btn_black, &CFloatTradeDlg::OnClickedBtnBlack)
|
ON_BN_CLICKED(btn_close_buy, &CFloatTradeDlg::OnClickedBtnCloseBuy)
|
ON_BN_CLICKED(btn_open_buy, &CFloatTradeDlg::OnClickedBtnOpenBuy)
|
//ON_BN_CLICKED(btn_pause_buy, &CFloatTradeDlg::OnClickedBtnPauseBuy)
|
//ON_BN_CLICKED(btn_pause_buy_remove, &CFloatTradeDlg::OnClickedBtnPauseBuyRemove)
|
ON_BN_CLICKED(btn_remove_black, &CFloatTradeDlg::OnClickedBtnRemoveBlack)
|
ON_BN_CLICKED(btn_remove_white, &CFloatTradeDlg::OnClickedBtnRemoveWhite)
|
ON_BN_CLICKED(btn_sell, &CFloatTradeDlg::OnClickedBtnSell)
|
ON_BN_CLICKED(btn_want_buy, &CFloatTradeDlg::OnClickedBtnWantBuy)
|
ON_BN_CLICKED(btn_want_buy_remove, &CFloatTradeDlg::OnClickedBtnWantBuyRemove)
|
ON_BN_CLICKED(btn_white, &CFloatTradeDlg::OnClickedBtnWhite)
|
ON_BN_CLICKED(check_auto_click, &CFloatTradeDlg::OnClickedCheckAutoClick)
|
ON_BN_CLICKED(check_auto_refresh, &CFloatTradeDlg::OnClickedCheckAutoRefresh)
|
ON_BN_CLICKED(check_trade_quick_key, &CFloatTradeDlg::OnClickedCheckTradeQuickKey)
|
ON_WM_COPYDATA()
|
ON_BN_CLICKED(btn_want_list, &CFloatTradeDlg::OnBnClickedwantlist)
|
//ON_BN_CLICKED(btn_pause_buy_list, &CFloatTradeDlg::OnBnClickedpausebuylist)
|
ON_BN_CLICKED(btn_black_list, &CFloatTradeDlg::OnBnClickedblacklist)
|
ON_BN_CLICKED(btn_white_list, &CFloatTradeDlg::OnBnClickedwhitelist)
|
ON_WM_CLOSE()
|
ON_BN_CLICKED(btn_buy, &CFloatTradeDlg::OnBnClickedbuy)
|
ON_BN_CLICKED(btn_config, &CFloatTradeDlg::OnBnClickedconfig)
|
ON_WM_CTLCOLOR()
|
ON_BN_CLICKED(btn_code_trade_info, &CFloatTradeDlg::OnBnClickedcodetradeinfo)
|
ON_BN_CLICKED(IDC_BUTTON_SELL_VOLUME_1, &CFloatTradeDlg::OnBnClickedButtonSellVolume1)
|
ON_BN_CLICKED(IDC_BUTTON_SELL_VOLUME_2, &CFloatTradeDlg::OnBnClickedButtonSellVolume1)
|
ON_BN_CLICKED(IDC_BUTTON_SELL_VOLUME_3, &CFloatTradeDlg::OnBnClickedButtonSellVolume1)
|
ON_BN_CLICKED(IDC_BUTTON_SELL_VOLUME_4, &CFloatTradeDlg::OnBnClickedButtonSellVolume1)
|
ON_BN_CLICKED(IDC_BUTTON_SELL_VOLUME_5, &CFloatTradeDlg::OnBnClickedButtonSellVolume1)
|
ON_BN_CLICKED(IDC_BUTTON_SELL_VOLUME_6, &CFloatTradeDlg::OnBnClickedButtonSellVolume1)
|
ON_BN_CLICKED(IDC_BUTTON_SELL_VOLUME_7, &CFloatTradeDlg::OnBnClickedButtonSellVolume1)
|
ON_BN_CLICKED(IDC_BUTTON_SELL_VOLUME_8, &CFloatTradeDlg::OnBnClickedButtonSellVolume1)
|
ON_BN_CLICKED(IDC_BUTTON_SELL_VOLUME_9, &CFloatTradeDlg::OnBnClickedButtonSellVolume1)
|
ON_BN_CLICKED(IDC_BUTTON_SELL_VOLUME_10, &CFloatTradeDlg::OnBnClickedButtonSellVolume1)
|
ON_BN_CLICKED(IDC_BUTTON_SELL_VOLUME_11, &CFloatTradeDlg::OnBnClickedButtonSellVolume1)
|
ON_BN_CLICKED(IDC_BUTTON_SELL_VOLUME_13, &CFloatTradeDlg::OnBnClickedButtonSellVolume1)
|
ON_BN_CLICKED(IDC_BUTTON_REFRESH, &CFloatTradeDlg::OnBnClickedButtonRefresh)
|
ON_BN_CLICKED(IDC_BUTTON_MUST_LIST, &CFloatTradeDlg::OnBnClickedmustlist)
|
ON_BN_CLICKED(IDC_BUTTON_ADD_MUST, &CFloatTradeDlg::OnBnClickedmust)
|
ON_BN_CLICKED(IDC_BUTTON_REMOVE_MUST, &CFloatTradeDlg::OnBnClickedremovefrommust)
|
ON_MESSAGE(WM_FLOAT_MSG, &CFloatTradeDlg::OnFloatMsg)
|
ON_BN_CLICKED(IDC_CHECK_LOCK_SELL_VOLUME, &CFloatTradeDlg::OnBnClickedCheckLockSellVolume)
|
ON_BN_CLICKED(IDC_BUTTON_ADD_WANT, &CFloatTradeDlg::OnBnClickedButtonAddWant)
|
ON_BN_CLICKED(IDC_BUTTON_REMOVE_WANT, &CFloatTradeDlg::OnBnClickedButtonRemoveWant)
|
ON_BN_CLICKED(IDC_BUTTON_WANT_LIST, &CFloatTradeDlg::OnBnClickedButtonWantList)
|
ON_BN_CLICKED(IDC_BUTTON_GET_POSITIONS, &CFloatTradeDlg::OnBnClickedButtonGetPositions)
|
ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_VOLUME, &CFloatTradeDlg::OnDeltaposSpinVolume)
|
ON_BN_CLICKED(IDC_CHECK_LOCK_BUY_VOLUME, &CFloatTradeDlg::OnBnClickedCheckLockBuyVolume)
|
ON_WM_KEYDOWN()
|
ON_BN_CLICKED(btn_code_trade_update_watch_buy1, &CFloatTradeDlg::OnBnClickedcodetradeupdatewatchbuy1)
|
ON_BN_CLICKED(IDC_BUTTON_ADD_GREEN, &CFloatTradeDlg::OnBnClickedButtonAddGreen)
|
ON_BN_CLICKED(IDC_BUTTON_REMOVE_GREEN, &CFloatTradeDlg::OnBnClickedButtonRemoveGreen)
|
ON_BN_CLICKED(IDC_BUTTON_GREEN_LIST, &CFloatTradeDlg::OnBnClickedButtonGreenList)
|
ON_BN_CLICKED(btn_add_watch_limit_up_for_sell, &CFloatTradeDlg::OnBnClickedaddwatchlimitupforsell)
|
ON_WM_LBUTTONDOWN()
|
ON_BN_CLICKED(check_ocr_code, &CFloatTradeDlg::OnClickedCheckOcrCode)
|
ON_WM_DESTROY()
|
ON_STN_CLICKED(IDC_STATIC_TOTAL_POSITION, &CFloatTradeDlg::OnStnClickedStaticTotalPosition)
|
ON_STN_CLICKED(IDC_STATIC_LS_CODE_NAME, &CFloatTradeDlg::OnStnClickedStaticLsCodeName)
|
ON_BN_CLICKED(IDC_BUTTON_LS_ADD_FORBIDDEN, &CFloatTradeDlg::OnBnClickedButtonLsAddForbidden)
|
ON_BN_CLICKED(IDC_BUTTON_LS_BUY, &CFloatTradeDlg::OnBnClickedButtonLsBuy)
|
ON_BN_CLICKED(IDC_BUTTON_LS_NOT_BUY, &CFloatTradeDlg::OnBnClickedButtonLsNotBuy)
|
ON_STN_CLICKED(IDC_STATIC_LS_PLATES, &CFloatTradeDlg::OnStnClickedStaticLsPlates)
|
ON_CBN_SELCHANGE(IDC_COMBO_CONTINUE_BUY_MONEY, &CFloatTradeDlg::OnCbnSelchangeComboContinueBuyList)
|
ON_BN_CLICKED(IDC_CHECK_CONTINUE_BUY, &CFloatTradeDlg::OnBnClickedContinueBuy)
|
END_MESSAGE_MAP()
|
|
// CFloatTradeDlg 消息处理程序
|
|
void CFloatTradeDlg::initView()
|
{
|
bigFont.CreateFont(22 * 2, 0, 0, 0, FW_NORMAL, 0, 0, 0, 0, 0, 0, 0, 0, L"微软雅黑");
|
middleFont.CreateFont(24, 0, 0, 0, FW_NORMAL, 0, 0, 0, 0, 0, 0, 0, 0, L"微软雅黑");
|
|
// 设置透明度(0透明,255完全不透明)
|
ModifyStyleEx(0, WS_EX_LAYERED);
|
BYTE opacity = 230; // 透明度值取值范围为0~255
|
SetLayeredWindowAttributes(RGB(0, 0, 0), opacity, LWA_ALPHA);
|
|
//设置字体
|
labelAtrribute.SetFont(&middleFont, FALSE);
|
labelCodeInfo.SetFont(&middleFont, FALSE);
|
btnCancelBuy.SetFont(&bigFont, FALSE);
|
btnSell.SetFont(&bigFont, FALSE);
|
btnBuy.SetFont(&bigFont, FALSE);
|
|
((CStatic *)GetDlgItem(IDC_STATIC_LS_TIME))->SetFont(&middleFont, FALSE);
|
((CStatic*)GetDlgItem(IDC_STATIC_LS_CODE_NAME))->SetFont(&middleFont, FALSE);
|
((CStatic*)GetDlgItem(IDC_STATIC_LS_PLATES))->SetFont(&middleFont, FALSE);
|
((CStatic*)GetDlgItem(IDC_STATIC_LS_BIG_ORDERS))->SetFont(&middleFont, FALSE);
|
|
|
if (dealQueueDlg == nullptr) {
|
dealQueueDlg = new DealQueueDlg();
|
dealQueueDlg->Create(IDD_DIALOG_DEAL_QUEUE, this);
|
}
|
}
|
|
void CFloatTradeDlg::initData()
|
{
|
sellManager = new SellManager();
|
buyWin = 0;
|
requestingCode = "";
|
if (ConfigUtil::isTradeRefresh()) {
|
checkAutoRefresh.SetCheck(TRUE);
|
}
|
else {
|
checkAutoRefresh.SetCheck(FALSE);
|
}
|
|
if (ConfigUtil::isTradeQuickKey()) {
|
checkTradeQuickKey.SetCheck(TRUE);
|
}
|
else {
|
checkTradeQuickKey.SetCheck(FALSE);
|
}
|
|
// 初始化刷新频率
|
|
|
HWND hWnd = CWnd::GetSafeHwnd();
|
//设置热键/快捷键
|
RegisterHotKey(hWnd, HOT_KEY_SELL_ALL, MOD_SHIFT, VK_F10);
|
RegisterHotKey(hWnd, HOT_KEY_CANCEL, MOD_SHIFT, VK_F1);
|
RegisterHotKey(hWnd, HOT_KEY_BUY, MOD_SHIFT, VK_F9);
|
RegisterHotKey(hWnd, HOT_KEY_UPDATE_BSD, MOD_SHIFT, VK_F8); // 板上盯
|
RegisterHotKey(hWnd, HOT_KEY_ADD_WANT_BUY, MOD_SHIFT, VK_F7); // 成交队列
|
|
|
|
//置顶
|
SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
|
//请求网络数据
|
|
std::thread t1(getTradeState, this);
|
t1.detach();
|
|
std::thread t2(getTradeMode, this);
|
t2.detach();
|
|
//启动交易刷新
|
std::thread t3(ThsUtil::run_trade_refresh);
|
t3.detach();
|
|
// 启动代码识别
|
std::thread t4(runTHSCodeOCR, this);
|
t4.detach();
|
|
// 设置位置
|
MyPoint p = ConfigUtil::getWindowPos();
|
RECT rect;
|
Win32Util::getWindowRect(GetSafeHwnd(), &rect);
|
Win32Util::moveWin(GetSafeHwnd(), p.x, p.y, (rect.right - rect.left + 1), (rect.bottom - rect.top + 1));
|
comboSellPriceType.AddString(_T("价格笼子"));
|
comboSellPriceType.AddString(_T("跌停价"));
|
comboSellPriceType.AddString(_T("涨停价"));
|
comboSellPriceType.AddString(_T("现价"));
|
comboSellPriceType.AddString(_T("买5价"));
|
comboSellPriceType.SetCurSel(0);
|
|
comboBuyPriceType.AddString(_T("价格笼子"));
|
comboBuyPriceType.AddString(_T("跌停价"));
|
comboBuyPriceType.AddString(_T("涨停价"));
|
comboBuyPriceType.AddString(_T("现价"));
|
comboBuyPriceType.AddString(_T("买5价"));
|
comboBuyPriceType.SetCurSel(0);
|
|
|
std::thread thread_ru(regularUpdatePositionInfo, this);
|
thread_ru.detach();
|
|
std::thread thread_push_msg_receive(runPushMsgReceiver, this);
|
thread_push_msg_receive.detach();
|
|
// 获取持仓
|
std::thread thread_request_all_position(requestAllPositions, this);
|
thread_request_all_position.detach();
|
|
// 加载代码名称
|
Constant::loadCodeNames();
|
|
|
// 按下组合键
|
list<HWND> hwndList = Win32Util::searchWindow("同花顺");
|
if (hwndList.size() > 0) {
|
UINT hwnd = (UINT) * (hwndList.begin());
|
Win32Util::focus((HWND)hwnd);
|
//SendMessage(hwnd, WM_KEYDOWN, VK_SHIFT);
|
//SendMessage(hwnd, WM_KEYDOWN, VK_F12);
|
//// 发送 SHIFT 键释放事件
|
//PostMessage(hwnd, WM_KEYUP, VK_F12);
|
//PostMessage(hwnd, WM_KEYUP, VK_SHIFT);
|
keybd_event(VK_SHIFT, 0, KEYEVENTF_EXTENDEDKEY, 0); // 按下按键
|
keybd_event(VK_F12, 0, KEYEVENTF_EXTENDEDKEY, 0);
|
|
keybd_event(VK_SHIFT, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0); // 释放按键
|
keybd_event(VK_F12, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0); // 释放按键
|
}
|
|
editBuyMoney.SetWindowTextW(to_wstring(ConfigUtil::getBuyMoney()).c_str());
|
|
fillMoneys();
|
lastBuyClickTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
canOCRCode = ConfigUtil::getEnableOCRCode();
|
if (canOCRCode) {
|
this->hMouseHook = SetWindowsHookEx(WH_MOUSE_LL, MouseProc, 0, 0);
|
}
|
((CButton*)GetDlgItem(check_ocr_code))->SetCheck(canOCRCode);
|
thread(runReadLSPlaceOrderRecords, this).detach();
|
}
|
|
|
BOOL CFloatTradeDlg::OnInitDialog()
|
{
|
CDialogEx::OnInitDialog();
|
|
// 设置此对话框的图标。 当应用程序主窗口不是对话框时,框架将自动
|
// 执行此操作
|
SetIcon(m_hIcon, TRUE); // 设置大图标
|
SetIcon(m_hIcon, FALSE); // 设置小图标
|
|
//ShowWindow(SW_MINIMIZE);
|
ShowWindow(SW_SHOW);
|
|
//设置透明度
|
// 设置对话框样式为Layered窗口
|
|
|
initView();
|
|
|
|
// TODO: 在此添加额外的初始化代码
|
//初始化配置文件
|
initData();
|
|
|
// 测试
|
return TRUE;
|
}
|
|
// 鼠标钩子过程函数示例
|
LRESULT CALLBACK CFloatTradeDlg::MouseProc(int nCode, WPARAM wParam, LPARAM lParam) {
|
if (nCode >= 0) {
|
MSLLHOOKSTRUCT* pMouseStruct = reinterpret_cast<MSLLHOOKSTRUCT*>(lParam);
|
switch (wParam) {
|
case WM_LBUTTONDOWN:
|
CFloatTradeDlg::ocrCodeExpireTimestamp = TimeUtil::getNowTimestamp() + 1000;
|
break;
|
}
|
}
|
return CallNextHookEx(hMouseHook, nCode, wParam, lParam);
|
}
|
|
|
|
|
|
|
|
|
|
|
void CFloatTradeDlg::OnHotKey(UINT nHotKeyId, UINT nKey, UINT nModifiers) {
|
|
if (!checkTradeQuickKey.GetCheck()) {
|
//未开启交易快捷键
|
return;
|
}
|
|
if (nHotKeyId == HOT_KEY_SELL_ALL) {
|
|
list<HWND> hwnds = Win32Util::searchWindow("可转债交易");
|
HWND cbHwnd = 0;
|
if (hwnds.size() > 0) {
|
for (list<HWND>::iterator e = hwnds.begin(); e != hwnds.end(); ++e) {
|
HWND hwnd = *e;
|
if (string("可转债交易")._Equal(Win32Util::getWindowName(hwnd))) {
|
auto fw = ::GetForegroundWindow();
|
if (fw == hwnd) {
|
cbHwnd = hwnd;
|
}
|
break;
|
}
|
}
|
}
|
|
if (cbHwnd > 0) {
|
string data = "你是不是傻";
|
COPYDATASTRUCT cds;
|
cds.dwData = 100; // 可以自定义标识数据
|
cds.cbData = (DWORD)data.size() + 1; // 字符串数据长度
|
cds.lpData = (PVOID)data.c_str();
|
::SendMessage(cbHwnd, WM_COPYDATA, NULL, (LPARAM)&cds);
|
}
|
else {
|
cout << "卖" << endl;
|
OnClickedBtnSell();
|
}
|
}
|
else if (nHotKeyId == HOT_KEY_CANCEL) {
|
cout << "撤当前" << endl;
|
OnClickedBtnAlreadyCanceled();
|
}
|
else if (nHotKeyId == HOT_KEY_BUY) {
|
cout << "买入" << endl;
|
buy();
|
}
|
else if (nHotKeyId == HOT_KEY_UPDATE_BSD) {
|
cout << "更板上盯" << endl;
|
OnBnClickedcodetradeupdatewatchbuy1();
|
}
|
else if (nHotKeyId == HOT_KEY_ADD_WANT_BUY) {
|
OnBnClickedButtonAddWant();
|
}
|
|
|
}
|
|
|
// 如果向对话框添加最小化按钮,则需要下面的代码
|
// 来绘制该图标。 对于使用文档/视图模型的 MFC 应用程序,
|
// 这将由框架自动完成。
|
|
void CFloatTradeDlg::OnPaint()
|
{
|
if (IsIconic())
|
{
|
CPaintDC dc(this); // 用于绘制的设备上下文
|
|
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
|
|
// 使图标在工作区矩形中居中
|
int cxIcon = GetSystemMetrics(SM_CXICON);
|
int cyIcon = GetSystemMetrics(SM_CYICON);
|
CRect rect;
|
GetClientRect(&rect);
|
int x = (rect.Width() - cxIcon + 1) / 2;
|
int y = (rect.Height() - cyIcon + 1) / 2;
|
|
// 绘制图标
|
dc.DrawIcon(x, y, m_hIcon);
|
}
|
else
|
{
|
CDialogEx::OnPaint();
|
}
|
}
|
|
//当用户拖动最小化窗口时系统调用此函数取得光标
|
//显示。
|
HCURSOR CFloatTradeDlg::OnQueryDragIcon()
|
{
|
return static_cast<HCURSOR>(m_hIcon);
|
}
|
|
|
|
void CFloatTradeDlg::OnClickedBtnAlreadyCanceled()
|
{
|
|
// showTips(L"这是条测试消息~~~~~~~", MSG_TYPE_FAIL,1000);
|
|
//list<HWND> hwnds = Win32Util::searchWindow("副屏1");
|
//HWND hwnd = *(hwnds.begin());
|
//::SetWindowPos(hwnd, HWND_TOPMOST,0,0,0,0, SWP_NOMOVE | SWP_NOSIZE);
|
//return;
|
|
// 撤单
|
try {
|
string code = getCode();
|
NetworkApi::cancel_buy(CString(code.c_str()));
|
CString msg(code.c_str());
|
msg.Append(_T("撤单提交成功"));
|
setMsg(msg, MSG_TYPE_SUCCESS);
|
}
|
catch (wstring st) {
|
CString msg(st.c_str());
|
setMsg(msg, MSG_TYPE_FAIL);
|
}
|
catch (CString st) {
|
setMsg(st, MSG_TYPE_FAIL);
|
}
|
}
|
|
void CFloatTradeDlg::OnBnClickedbuy()
|
{
|
/*
|
CString codew;
|
editCode.GetWindowTextW(codew);
|
CBuyDlg dlg(codew);
|
INT_PTR nResponse = dlg.DoModal();
|
*/
|
buy();
|
}
|
|
|
|
void CFloatTradeDlg::OnClickedBtnBlack()
|
{
|
// 加入黑名单
|
try {
|
string code = getCode();
|
NetworkApi::add_black(code);
|
CString msg(code.c_str());
|
msg.Append(_T("加入黑名单成功"));
|
setMsg(msg, MSG_TYPE_SUCCESS);
|
}
|
catch (wstring st) {
|
CString msg(st.c_str());
|
setMsg(msg, MSG_TYPE_FAIL);
|
}
|
}
|
|
|
|
void CFloatTradeDlg::OnClickedBtnCloseBuy()
|
{
|
// 关闭交易
|
try {
|
NetworkApi::set_buy_state(FALSE);
|
CString msg;
|
msg.Append(_T("关闭交易成功"));
|
setMsg(msg, MSG_TYPE_SUCCESS);
|
getTradeState(this);
|
}
|
catch (wstring st) {
|
CString msg(st.c_str());
|
setMsg(msg, MSG_TYPE_FAIL);
|
}
|
}
|
|
|
void CFloatTradeDlg::OnClickedBtnOpenBuy()
|
{
|
// 开启交易
|
try {
|
NetworkApi::set_buy_state(TRUE);
|
CString msg;
|
msg.Append(_T("开启交易成功"));
|
setMsg(msg, MSG_TYPE_SUCCESS);
|
getTradeState(this);
|
}
|
catch (wstring st) {
|
CString msg(st.c_str());
|
setMsg(msg, MSG_TYPE_FAIL);
|
}
|
}
|
|
|
void CFloatTradeDlg::OnClickedBtnPauseBuy()
|
{
|
// 加入暂不买
|
try {
|
string code = getCode();
|
NetworkApi::add_pause_buy(code);
|
CString msg(code.c_str());
|
msg.Append(_T("加入暂不买成功"));
|
setMsg(msg, MSG_TYPE_SUCCESS);
|
}
|
catch (wstring st) {
|
CString msg(st.c_str());
|
setMsg(msg, MSG_TYPE_FAIL);
|
}
|
}
|
|
|
void CFloatTradeDlg::OnClickedBtnPauseBuyRemove()
|
{
|
// 移除暂不买
|
try {
|
string code = getCode();
|
NetworkApi::remove_pause_buy(code);
|
CString msg(code.c_str());
|
msg.Append(_T("移除暂不买成功"));
|
setMsg(msg, MSG_TYPE_SUCCESS);
|
}
|
catch (wstring st) {
|
CString msg(st.c_str());
|
setMsg(msg, MSG_TYPE_FAIL);
|
}
|
}
|
|
|
void CFloatTradeDlg::OnClickedBtnRemoveBlack()
|
{
|
// 移除黑名单
|
try {
|
// 批量移除黑名单
|
/*string codes_str = "603580,003010,605388,603511,002133,603106,000888,603729,301396,603517,600718,300643,603566,603716,002025,603228,002296,000599,002760,603881,601619,600590,001389,002384,605186,600120,603296,002380,002734,002357,002875,002707,002354,002993,300078,600183,000056,000710,002305,002800,002261,600719,002970,300067,600095,002883,605069,002560,300253,002444,300819,002913,000428,300454,301299,300766,603028,600280,600665,603829,000592,600143,603238,002285,000757,002946,000722,000007,001282,002976,000818,002152,002295,603108,603183,001333,000796,002248,603280,002982,603860,600818,002205,001298,002122,605228,300244,002743,603578,002335,300153,603305,600595,600588,600336,000899,002953,605255,605398,605011,300155,002622,000715,603312,002436,002529,002475,002881,603063,000503,002173,002364,002134,300534,002418,002105,300599,603938,600868,600376,603109,300528,002905,600889,002785,002044,002363,002065,002463,603888,000048,301230,601921,300746,002188,000151,603269,600708,002779,003038,603693,002209,603001,002273,002559,002662,600238,600650,002733,000657,000920,000815,600322,600456,000558,603920,002448,603506,600032,000688,603193,600728,600960,002068,603979,002888,001313,600506,300947,300451,600319,001279,002666,603286,600979,002484,002802,605162,300058,300069,002847,603121,002990,605333,002599,002394,600602,600101,002358,002715,603882,300946,300941,600758,603901,603967,603268,603038,603950,001258,300488,002851,002943,002580,603610,603215,600533,603876,002938,600318,002229,002298,605259,603273,002163,601777,600114,002725,002286,600785,300288,600825,002965,603076,601579,603500,601869,002518,002829,000659,600173,601218,601566";
|
std::vector<std::string> tokens;
|
size_t start = 0;
|
size_t end = codes_str.find(',');
|
|
while (end != std::string::npos) {
|
tokens.push_back(codes_str.substr(start, end - start));
|
start = end + 1;
|
end = codes_str.find(',', start);
|
}
|
|
tokens.push_back(codes_str.substr(start));
|
for (vector<string>::iterator e = tokens.begin();e != tokens.end();++e) {
|
auto code = *e;
|
NetworkApi::remove_black(code);
|
}*/
|
|
string code = getCode();
|
NetworkApi::remove_black(code);
|
CString msg(code.c_str());
|
msg.Append(_T("移除黑名单成功"));
|
setMsg(msg, MSG_TYPE_SUCCESS);
|
}
|
catch (wstring st) {
|
CString msg(st.c_str());
|
setMsg(msg, MSG_TYPE_FAIL);
|
}
|
}
|
|
|
void CFloatTradeDlg::OnClickedBtnRemoveWhite()
|
{
|
// 移除白名单
|
try {
|
string code = getCode();
|
NetworkApi::remove_white(code);
|
CString msg(code.c_str());
|
msg.Append(_T("移除白名单成功"));
|
setMsg(msg, MSG_TYPE_SUCCESS);
|
}
|
catch (wstring st) {
|
CString msg(st.c_str());
|
setMsg(msg, MSG_TYPE_FAIL);
|
}
|
}
|
|
|
void CFloatTradeDlg::OnClickedBtnSell()
|
{
|
bool showMsg = true;
|
try {
|
string code = "";
|
try {
|
code = getCode();
|
}
|
catch (...) {
|
|
}
|
//if (requestingCode.size() >= 6) {
|
// showTips(L"持仓请求未结束(150ms以后才能卖)", MSG_TYPE_FAIL, 1000);
|
// return;
|
//}
|
|
CString sell_money;
|
editSellMoney.GetWindowTextW(sell_money);
|
if (!StringUtil::isNumber(StringUtil::cstring2String(sell_money))) {
|
showTips(L"卖金额输入错误", MSG_TYPE_FAIL, 1000);
|
return;
|
}
|
int sell_money_int = stoi(StringUtil::cstring2String(sell_money));
|
if (sell_money_int <= 0) {
|
showTips(L"卖金额不能为0", MSG_TYPE_FAIL, 1000);
|
return;
|
}
|
|
|
// 卖
|
|
|
int sell_volume_int = sellMoneyToVolume(code, sell_money_int);
|
if (sell_volume_int == 0) {
|
sell_volume_int = 100;
|
}
|
// 获取持仓
|
CodePosition* pos = sellManager->getCodePosition(code);
|
if (pos != nullptr) {
|
if (pos->available > 0 && sell_volume_int > pos->available) {
|
// 卖剩余的所有
|
sell_volume_int = pos->available;
|
}
|
}
|
|
std::thread t1(this->sellByVolume, code, sell_volume_int, this);
|
t1.detach();
|
}
|
catch (wstring st) {
|
CString msg(st.c_str());
|
//setMsg(msg, MSG_TYPE_FAIL);
|
showTips(msg, MSG_TYPE_FAIL, 1000);
|
}
|
|
}
|
|
|
void CFloatTradeDlg::OnClickedBtnWantBuy()
|
{
|
// 加入想买
|
try {
|
string code = getCode();
|
NetworkApi::add_want_buy(code);
|
CString msg(code.c_str());
|
msg.Append(_T("加入想买单成功"));
|
setMsg(msg, MSG_TYPE_SUCCESS);
|
}
|
catch (wstring st) {
|
CString msg(st.c_str());
|
setMsg(msg, MSG_TYPE_FAIL);
|
}
|
}
|
|
|
void CFloatTradeDlg::OnClickedBtnWantBuyRemove()
|
{
|
// 移除想买
|
try {
|
string code = getCode();
|
NetworkApi::remove_want_buy(code);
|
CString msg(code.c_str());
|
msg.Append(_T("移除想买单成功"));
|
setMsg(msg, MSG_TYPE_SUCCESS);
|
}
|
catch (wstring st) {
|
CString msg(st.c_str());
|
setMsg(msg, MSG_TYPE_FAIL);
|
}
|
}
|
|
|
void CFloatTradeDlg::OnClickedBtnWhite()
|
{
|
// 加入白名单
|
try {
|
string code = getCode();
|
NetworkApi::add_white(code);
|
CString msg(code.c_str());
|
msg.Append(_T("加入白名单成功"));
|
setMsg(msg, MSG_TYPE_SUCCESS);
|
}
|
catch (wstring st) {
|
CString msg(st.c_str());
|
setMsg(msg, MSG_TYPE_FAIL);
|
}
|
}
|
|
void CFloatTradeDlg::OnBnClickedmustlist()
|
{
|
try {
|
std::list<wstring> wlist = NetworkApi::list_must_buy();
|
|
MessageBox(formatListResult(wlist), TEXT("红名单"), MB_TASKMODAL);
|
}
|
catch (wstring st) {
|
CString cs(st.c_str());
|
AfxMessageBox(cs);
|
}
|
}
|
|
|
void CFloatTradeDlg::OnBnClickedmust()
|
{
|
try {
|
string code = getCode();
|
NetworkApi::add_must_buy(code);
|
CString msg(code.c_str());
|
msg.Append(_T("加入红名单成功"));
|
setMsg(msg, MSG_TYPE_SUCCESS);
|
}
|
catch (wstring st) {
|
CString msg(st.c_str());
|
setMsg(msg, MSG_TYPE_FAIL);
|
}
|
}
|
|
|
void CFloatTradeDlg::OnBnClickedremovefrommust()
|
{
|
// 移除白名单
|
try {
|
string code = getCode();
|
NetworkApi::remove_must_buy(code);
|
CString msg(code.c_str());
|
msg.Append(_T("移除红名单成功"));
|
setMsg(msg, MSG_TYPE_SUCCESS);
|
}
|
catch (wstring st) {
|
CString msg(st.c_str());
|
setMsg(msg, MSG_TYPE_FAIL);
|
}
|
}
|
|
|
|
void CFloatTradeDlg::OnClickedCheckAutoClick()
|
{
|
// 判断是否选中了代码
|
string code = "";
|
try {
|
code = this->getInputCode();
|
}
|
catch (wstring msg) {
|
checkAutoCancelSell.SetCheck(!checkAutoCancelSell.GetCheck());
|
AfxMessageBox(msg.c_str());
|
return;
|
}
|
|
if (checkAutoCancelSell.GetCheck()) {
|
// 撤所有
|
try {
|
NetworkApi::set_auto_cancel_sell_mode(code, 0);
|
}
|
catch (wstring msg) {
|
checkAutoCancelSell.SetCheck(FALSE);
|
AfxMessageBox(msg.c_str());
|
}
|
}
|
else {
|
// 撤机器
|
try {
|
NetworkApi::set_auto_cancel_sell_mode(code, 1);
|
}
|
catch (wstring msg) {
|
checkAutoCancelSell.SetCheck(TRUE);
|
AfxMessageBox(msg.c_str());
|
}
|
}
|
}
|
|
|
void CFloatTradeDlg::OnClickedCheckAutoRefresh()
|
{
|
// 交易刷新
|
ConfigUtil::setTradeRefresh(checkAutoRefresh.GetCheck());
|
}
|
|
|
|
void CFloatTradeDlg::OnClickedCheckTradeQuickKey()
|
{
|
// 交易快捷键
|
ConfigUtil::setTradeQuickKey(checkTradeQuickKey.GetCheck());
|
}
|
|
LRESULT CFloatTradeDlg::OnFloatMsg(WPARAM wParam, LPARAM lParam)
|
{
|
|
FloatMsg* pData = (FloatMsg*)lParam;
|
|
showTips(CString(pData->msg.c_str()), pData->msgType, pData->showMS, pData->position);
|
|
return LRESULT();
|
}
|
|
|
|
CString CFloatTradeDlg::formatListResult(std::list<wstring> wlist) {
|
CString st;
|
int index = 0;
|
for (std::list<wstring>::iterator ele = wlist.begin(); ele != wlist.end(); ++ele) {
|
wstring ws = *ele;
|
st.Append(ws.c_str());
|
if (index + 1 != wlist.size() && index % 2 == 0)
|
{
|
st.Append(L",");
|
}
|
if (index % 2 == 1) {
|
st.Append(L"\n");
|
}
|
index++;
|
}
|
return st;
|
}
|
|
void CFloatTradeDlg::initSellSettingView()
|
{
|
SellSettingView sellSettingView;
|
string code = "";
|
try {
|
code = getInputCode();
|
}
|
catch (...) {
|
return;
|
}
|
|
}
|
|
string CFloatTradeDlg::getInputCode()
|
{
|
CString codew;
|
editCode.GetWindowTextW(codew);
|
if (codew.GetLength() != 6) {
|
throw wstring(L"代码输入错误");
|
}
|
return StringUtil::cstring2String(codew);
|
}
|
|
void CFloatTradeDlg::OnSellCallback(string code, CWnd* context)
|
{
|
CFloatTradeDlg* dlg = ((CFloatTradeDlg*)context);
|
try {
|
dlg->sell(code, dlg);
|
}
|
catch (wstring msg) {
|
dlg->showTips(msg.c_str(), MSG_TYPE_FAIL);
|
}
|
}
|
|
void CFloatTradeDlg::OnSellCloseCallback(string code, CWnd* context)
|
{
|
SellDlg* dlg = ((CFloatTradeDlg*)context)->sellDlgMap[code];
|
dlg->CloseWindow();
|
delete dlg;
|
((CFloatTradeDlg*)context)->sellDlgMap.erase(code);
|
}
|
|
void CFloatTradeDlg::sellByVolume(string code, int volume, CFloatTradeDlg* context)
|
{
|
|
//0-价格笼子 1-跌停价 2-涨停价 3-现价
|
int sellPriceType = context->comboSellPriceType.GetCurSel();
|
if (sellPriceType < 0 || sellPriceType > 10) {
|
context->showTips(L"请选择卖价类型", MSG_TYPE_FAIL, 1000);
|
return;
|
}
|
|
string nowTime = TimeUtil::getNowTime("%H%M%S");
|
// 09:25:00之前都是跌停价卖
|
if (stoi(nowTime) >= stoi("092500")) {
|
if (sellPriceType == 1) {
|
sellPriceType = 0;
|
context->comboSellPriceType.SetCurSel(0);
|
}
|
}
|
|
// 卖
|
try {
|
int orderRef = context->sellManager->sell(code, volume, sellPriceType);
|
std::thread t1(context->requestSellResult, orderRef, context, 2000);
|
t1.detach();
|
|
std::thread t2(context->requestAllPositions, context);
|
t2.detach();
|
|
|
//context->showTips(L"卖提交成功", MSG_TYPE_SUCCESS, 1000);
|
showFloatMsg(context, L"卖提交成功", MSG_TYPE_SUCCESS, 1000);
|
}
|
catch (wstring st) {
|
CString msg(st.c_str());
|
//setMsg(msg, MSG_TYPE_FAIL);
|
showFloatMsg(context, msg, MSG_TYPE_FAIL, 1000);
|
}
|
|
}
|
|
void CFloatTradeDlg::sell(string code, CFloatTradeDlg* dlg)
|
{
|
//0-价格笼子 1-跌停价 2-涨停价 3-现价
|
int sellPriceType = dlg->comboSellPriceType.GetCurSel();
|
if (sellPriceType < 0 || sellPriceType > 10) {
|
dlg->showTips(L"请选择卖价类型", MSG_TYPE_FAIL, 1000);
|
return;
|
}
|
|
string nowTime = TimeUtil::getNowTime("%H%M%S");
|
// 09:25:00之前都是跌停价卖
|
if (stoi(nowTime) >= stoi("092500")) {
|
if (sellPriceType == 1) {
|
sellPriceType = 0;
|
dlg->comboSellPriceType.SetCurSel(0);
|
}
|
}
|
|
// 卖
|
try {
|
int orderRef = dlg->sellManager->sell(code, sellPriceType);
|
std::thread t1(dlg->requestSellResult, orderRef, dlg, 2000);
|
t1.detach();
|
dlg->showTips(L"卖提交成功", MSG_TYPE_SUCCESS, 1000);
|
}
|
catch (wstring st) {
|
CString msg(st.c_str());
|
dlg->showTips(msg, MSG_TYPE_FAIL, 1000);
|
}
|
}
|
|
void CFloatTradeDlg::fillSellMoney(string code, int volume)
|
{
|
CodePosition* codePosition = sellManager->getCodePosition(code);
|
editSellMoney.SetWindowTextW(to_wstring((int)(codePosition->costPrice * volume * 100) / 100).c_str());
|
}
|
|
int CFloatTradeDlg::sellMoneyToVolume(string code, int money)
|
{
|
CodePosition* codePosition = sellManager->getCodePosition(code);
|
int volume = ((int)round((money / codePosition->costPrice) * 100)) / 100;
|
return SellManager::sellMoneyToVolume(money, codePosition->costPrice);
|
}
|
|
void CFloatTradeDlg::buy()
|
{
|
|
|
try {
|
auto now = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
// 买入频率限制
|
if (now - lastBuyClickTime < 1000) {
|
throw wstring(L"买入时间小于1000ms");
|
}
|
lastBuyClickTime = now;
|
string code = getInputCode();
|
CString buyMoneyw;
|
editBuyMoney.GetWindowTextW(buyMoneyw);
|
if (buyMoneyw.GetLength() < 1) {
|
throw wstring(L"请输入买入金额");
|
}
|
|
/*CodePosition* pos = sellManager->getCodePosition(code);
|
if (pos == nullptr) {
|
throw wstring(L"没有获取到现价");
|
}*/
|
int buyMoney = stoi(StringUtil::cstring2String(buyMoneyw));
|
/*if (round(pos->costPrice) <= 0) {
|
throw wstring(L"未获取到现价");
|
}*/
|
/*int volume = SellManager::sellMoneyToVolume(buyMoney, pos->costPrice);
|
if (volume <= 0) {
|
CString msg = L"买入量不能小于100(单价:";
|
msg.Append(to_wstring(pos->costPrice).c_str());
|
msg.Append(L")");
|
throw wstring(msg);
|
}*/
|
NetworkApi::buy(code, buyMoney, comboBuyPriceType.GetCurSel());
|
showTips(L"买入提交成功", MSG_TYPE_SUCCESS, 1000);
|
}
|
catch (wstring st) {
|
showTips(st.c_str(), MSG_TYPE_FAIL, 1000);
|
}
|
}
|
|
void CFloatTradeDlg::showFloatMsg(CFloatTradeDlg* context, CString msg, MSG_TYPE msgType, int showMS, int position)
|
{
|
FloatMsg params;
|
params.msg = StringUtil::cstring2String(msg);
|
params.msgType = msgType;
|
params.showMS = showMS;
|
params.position = position;
|
LPARAM lm = (LPARAM)¶ms;
|
::SendMessage(context->GetSafeHwnd(), WM_FLOAT_MSG, 0, lm);
|
}
|
|
void CFloatTradeDlg::requestAllPositions(CFloatTradeDlg* context)
|
{
|
try {
|
string result = NetworkApi::get_all_positions();
|
auto doc = JsonUtil::parseUTF16(result);
|
if (doc[L"code"].GetInt() == 0) {
|
auto data = doc[L"data"].GetArray();
|
for (int i = 0; i < data.Size(); i++) {
|
auto item = data[i].GetObjectW();
|
string code = StringUtil::cstring2String(item[L"code"].GetString());
|
context->sellManager->init(code);
|
CodePosition codePosition;
|
codePosition.total = item[L"total"].GetInt();
|
codePosition.available = item[L"available"].GetInt();
|
codePosition.code = code;
|
codePosition.name = item[L"code_name"].GetString();
|
codePosition.costPrice = item[L"cost_price"].GetFloat();
|
codePosition.sell_rules_count = 0;
|
context->positionMap[codePosition.code] = codePosition;
|
|
CodePosition* positionForSell = context->sellManager->getCodePosition(code);
|
if (positionForSell != nullptr) {
|
positionForSell->total = item[L"total"].GetInt();
|
positionForSell->available = item[L"available"].GetInt();
|
positionForSell->code = code;
|
positionForSell->name = item[L"code_name"].GetString();
|
positionForSell->costPrice = item[L"cost_price"].GetFloat();
|
positionForSell->sell_rules_count = 0;
|
}
|
}
|
}
|
}
|
catch (...) {
|
|
}
|
}
|
|
void CFloatTradeDlg::fillMoneys()
|
{
|
list<int> volumeList = ConfigUtil::getVolumesSetting();
|
int ids[] = {
|
IDC_BUTTON_SELL_VOLUME_13,IDC_BUTTON_SELL_VOLUME_11,IDC_BUTTON_SELL_VOLUME_10,IDC_BUTTON_SELL_VOLUME_9,IDC_BUTTON_SELL_VOLUME_8,IDC_BUTTON_SELL_VOLUME_7,IDC_BUTTON_SELL_VOLUME_6,IDC_BUTTON_SELL_VOLUME_5, IDC_BUTTON_SELL_VOLUME_4, IDC_BUTTON_SELL_VOLUME_3, IDC_BUTTON_SELL_VOLUME_2, IDC_BUTTON_SELL_VOLUME_1
|
};
|
|
if (volumeList.size() == 12) {
|
int index = 0;
|
for (list<int>::iterator e = volumeList.begin(); e != volumeList.end(); ++e) {
|
int volume = *e;
|
CButton* edit = (CButton*)GetDlgItem(ids[index]);
|
edit->SetWindowTextW(to_wstring(volume).c_str());
|
index++;
|
}
|
}
|
}
|
|
void CFloatTradeDlg::runTHSCodeOCR(CFloatTradeDlg* context)
|
{
|
if (context->thsCodeOCR == nullptr) {
|
context->thsCodeOCR = new ThsCodeOCR();
|
}
|
|
while (TRUE)
|
{
|
try {
|
if (context->canOCRCode) {
|
if (TimeUtil::getNowTimestamp() < context->ocrCodeExpireTimestamp) {
|
string code = context->thsCodeOCR->ocrCode();
|
// 设置目标代码
|
if (!code._Equal(context->lastOCRCode)) {
|
context->lastOCRCode = code;
|
context->setTargetCode(code);
|
}
|
}
|
}
|
}
|
catch (...) {
|
}
|
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
}
|
}
|
|
void CFloatTradeDlg::setTargetCode(string code)
|
{
|
editCode.SetWindowTextW(CString(code.c_str()));
|
requestingCode = code;
|
|
//请求网络获取消息
|
std::thread t1(getCodeDesc, code, this);
|
t1.detach();
|
|
std::thread t2(requestCodePosition, code, this, TRUE, 0);
|
t2.detach();
|
|
std::thread t3(getAutoCancelSellMode, this, code);
|
t3.detach();
|
|
std::thread t4(getContinueBuyInfo, this, code);
|
t4.detach();
|
|
if (dealQueueDlg != nullptr && dealQueueDlg->IsWindowVisible()) {
|
dealQueueDlg->setTargetCode(code);
|
}
|
|
|
}
|
|
void CFloatTradeDlg::setLockInfo(string code, bool lock, int lockMoney)
|
{
|
string nowTimeStr = TimeUtil::getNowTime("%H%M%S");
|
SellSetting* sellSetting = sellManager->getSellSetting(code);
|
sellSetting->lock = TRUE;
|
sellSetting->lockMoney = lockMoney;
|
sellSetting->lockTime = stoi(nowTimeStr.c_str());
|
sellManager->syncSettingToFile(code);
|
}
|
|
void CFloatTradeDlg::setLockBuyInfo(string code, bool lock, int lockMoney)
|
{
|
string nowTimeStr = TimeUtil::getNowTime("%H%M%S");
|
SellSetting* sellSetting = sellManager->getSellSetting(code);
|
sellSetting->lockBuy = TRUE;
|
sellSetting->lockBuyMoney = lockMoney;
|
sellSetting->lockTime = stoi(nowTimeStr.c_str());
|
sellManager->syncSettingToFile(code);
|
}
|
|
void CFloatTradeDlg::requestReadLSPlaceOrderRecords(CFloatTradeDlg* context)
|
{
|
string result = LowSuctionNetworkApi::read_place_order_queue();
|
auto doc = JsonUtil::parseUTF16(result);
|
if (doc.IsObject()) {
|
if (doc[L"code"].GetInt() == 0) {
|
auto data = doc[L"data"].GetObjectW();
|
LowSuctionQueue info;
|
info.id = StringUtil::cstring2String( data[L"id"].GetString());
|
info.code = StringUtil::cstring2String(data[L"code"].GetString());
|
info.name = StringUtil::cstring2String(data[L"name"].GetString());
|
info.time_str = StringUtil::cstring2String(data[L"time_str"].GetString());
|
info.bigOrderInfo = StringUtil::cstring2String(data[L"bigOrderInfo"].GetString());
|
|
auto platesInfo = data[L"platesInfo"].GetObjectW();
|
for (auto it = platesInfo.MemberBegin();it != platesInfo.MemberEnd();++it) {
|
CString k = it->name.GetString();
|
auto value = it->value.GetArray();
|
info.plates.push_back(StringUtil::cstring2String(k));
|
for (int i = 0;i < value.Size();i++) {
|
|
info.plateLimitUpCodes[StringUtil::cstring2String(k)].push_back(LowSuctionCodeInfo({ StringUtil::cstring2String(value[i][0].GetString()), value[i][1].IsString()?StringUtil::cstring2String(value[i][1].GetString()):""}));
|
}
|
}
|
|
((CStatic*)context->GetDlgItem(IDC_STATIC_LS_TIME))->SetWindowTextW(CString(info.time_str.c_str()));
|
((CStatic*)context->GetDlgItem(IDC_STATIC_LS_CODE_NAME))->SetWindowTextW(CString(info.name.c_str()));
|
CString plates = L"";
|
for (list<string>::iterator e = info.plates.begin();e != info.plates.end();++e) {
|
plates.Append(CString((*e).c_str()));
|
plates.Append(L"/");
|
}
|
if (plates.GetLength() > 0) {
|
plates = plates.Left(plates.GetLength() - 1);
|
}
|
((CStatic*)context->GetDlgItem(IDC_STATIC_LS_PLATES))->SetWindowTextW(plates);
|
((CStatic*)context->GetDlgItem(IDC_STATIC_LS_BIG_ORDERS))->SetWindowTextW(CString(info.bigOrderInfo.c_str()));
|
context->lowSuctionQueue = info;
|
}
|
else {
|
context->lowSuctionQueue.id = "";
|
((CStatic*)context->GetDlgItem(IDC_STATIC_LS_TIME))->SetWindowTextW(L"--:--:--");
|
((CStatic*)context->GetDlgItem(IDC_STATIC_LS_CODE_NAME))->SetWindowTextW(L"----");
|
((CStatic*)context->GetDlgItem(IDC_STATIC_LS_PLATES))->SetWindowTextW(L"----");
|
((CStatic*)context->GetDlgItem(IDC_STATIC_LS_BIG_ORDERS))->SetWindowTextW(L"----");
|
}
|
|
}
|
}
|
|
void CFloatTradeDlg::runReadLSPlaceOrderRecords(CFloatTradeDlg* context)
|
{
|
while (TRUE) {
|
try {
|
requestReadLSPlaceOrderRecords(context);
|
}
|
catch (...) {
|
|
}
|
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
}
|
|
}
|
|
|
void CFloatTradeDlg::OnBnClickedwantlist()
|
{
|
try {
|
// 想买单
|
std::list<wstring> wlist = NetworkApi::list_want_buy();
|
MessageBox(formatListResult(wlist), TEXT("想买单"), MB_TASKMODAL);
|
}
|
catch (wstring st) {
|
CString cs(st.c_str());
|
AfxMessageBox(cs);
|
}
|
}
|
|
|
void CFloatTradeDlg::OnBnClickedpausebuylist()
|
{
|
try {
|
//暂不买单
|
std::list<wstring> wlist = NetworkApi::list_pause_buy();
|
|
MessageBox(formatListResult(wlist), TEXT("暂不买单"), MB_TASKMODAL);
|
}
|
catch (wstring st) {
|
CString cs(st.c_str());
|
AfxMessageBox(cs);
|
}
|
}
|
|
|
void CFloatTradeDlg::OnBnClickedblacklist()
|
{
|
try {
|
// 黑名单
|
std::list<wstring> wlist = NetworkApi::list_black();
|
|
MessageBox(formatListResult(wlist), TEXT("黑名单"), MB_TASKMODAL);
|
}
|
catch (wstring st) {
|
CString cs(st.c_str());
|
AfxMessageBox(cs);
|
}
|
}
|
|
// 白名单
|
void CFloatTradeDlg::OnBnClickedwhitelist()
|
{
|
try {
|
std::list<wstring> wlist = NetworkApi::list_white();
|
|
MessageBox(formatListResult(wlist), TEXT("白名单"), MB_TASKMODAL);
|
}
|
catch (wstring st) {
|
CString cs(st.c_str());
|
AfxMessageBox(cs);
|
}
|
}
|
|
BOOL SendCopyData(HWND hwndTo, const void* pData, DWORD dwDataSize) {
|
COPYDATASTRUCT cds;
|
cds.dwData = 0; // 自定义数据标识,可以根据需要设置
|
cds.cbData = dwDataSize; // 数据大小
|
cds.lpData = (PVOID)pData;// 数据指针
|
// 发送 WM_COPYDATA 消息
|
return SendMessage(hwndTo, WM_COPYDATA, (WPARAM)NULL, (LPARAM)&cds);
|
}
|
|
|
BOOL CFloatTradeDlg::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct)
|
{
|
//this->labelAtrribute.Set
|
//将当前页面显示在最前面并获取焦点
|
|
BYTE* pBuf = (BYTE*)(pCopyDataStruct->lpData);
|
DWORD dwSize = (DWORD)(pCopyDataStruct->cbData);
|
|
// 读取数据
|
if (pBuf != nullptr && dwSize > 0)
|
{
|
std::string str(reinterpret_cast<const char*>(pBuf), dwSize);
|
wstring wstr = StringUtil::Unescape(str);
|
rapidjson::GenericDocument<rapidjson::UTF16<>> root;
|
root.Parse(wstr.c_str());
|
|
wstring type = root[_T("type")].GetString();
|
if (type == _T("set_code")) {
|
//this->SetForegroundWindow();
|
//this->SetFocus();
|
wstring codew = root[_T("data")][_T("code")].GetString();
|
|
string code = StringUtil::wstringToString(codew);
|
// 设置正在请求的代码
|
setTargetCode(code);
|
|
|
// 判断是否有下单窗口
|
/*if (!buyWin || !Win32Util::isWindowShow(buyWin)) {
|
list<HWND> hwndlist = Win32Util::searchWindow("下单");
|
for (list<HWND>::iterator el = hwndlist.begin(); el != hwndlist.end(); el++) {
|
HWND hw = *el;
|
if (Win32Util::getWindowName(hw) == "下单" && Win32Util::isWindowShow(hw)) {
|
buyWin = hw;
|
break;
|
}
|
}
|
}
|
if (buyWin) {
|
SendCopyData(buyWin, pBuf, dwSize);
|
}*/
|
}
|
else if (type == _T("set_msg")) {
|
wstring msg = root[_T("data")][_T("msg")].GetString();
|
CString msgc(msg.c_str());
|
setMsg(msgc, MSG_TYPE_INFO, FALSE);
|
}
|
}
|
return CDialogEx::OnCopyData(pWnd, pCopyDataStruct);
|
}
|
|
|
void CFloatTradeDlg::OnClose()
|
{
|
// 保存位置
|
|
// 获取对话框位置
|
RECT rect;
|
Win32Util::getWindowRect(GetSafeHwnd(), &rect);
|
if (rect.left < -3000 || rect.top < -3000) {
|
// 错误的坐标
|
}
|
else {
|
ConfigUtil::setWindowPos(rect.left, rect.top);
|
}
|
CDialogEx::OnClose();
|
|
}
|
|
|
|
|
void CFloatTradeDlg::OnBnClickedconfig()
|
{
|
//参数设置
|
CSettingDlg dlg;
|
INT_PTR nResponse = dlg.DoModal();
|
|
fillMoneys();
|
}
|
|
|
HBRUSH CFloatTradeDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
|
{
|
HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
|
|
if (nCtlColor == CTLCOLOR_STATIC) {
|
int nID = pWnd->GetDlgCtrlID();
|
switch (nID) {
|
case label_atrribute:
|
pDC->SetTextColor(msgColor);
|
break;
|
case IDC_STATIC_ALREADY_SELL:
|
pDC->SetTextColor(RGB(255, 0, 0));
|
break;
|
}
|
}
|
return hbr;
|
}
|
|
|
void CFloatTradeDlg::OnBnClickedcodetradeinfo()
|
{
|
CString code;
|
editCode.GetWindowText(code);
|
SellRuleDlg dlg(code, 0);
|
//dlg.Create(IDD_BUY,this);
|
//dlg.ShowWindow(SW_SHOW);
|
//return;
|
INT_PTR nResponse = dlg.DoModal();
|
}
|
|
|
void CFloatTradeDlg::OnBnClickedButtonSellVolume1()
|
{
|
int nID = ((CButton*)GetFocus())->GetDlgCtrlID();
|
CString num_str;
|
GetDlgItem(nID)->GetWindowTextW(num_str);
|
editSellMoney.SetWindowTextW(num_str);
|
|
try {
|
string code = getInputCode();
|
int sellMoney_int = stoi(StringUtil::cstring2String(num_str).c_str());
|
setLockInfo(code, true, sellMoney_int);
|
}
|
catch (wstring msg) {
|
AfxMessageBox(msg.c_str());
|
}
|
}
|
|
void CFloatTradeDlg::OnBnClickedButtonRefresh()
|
{
|
try {
|
requestCodePosition(getInputCode(), this, TRUE);
|
}
|
catch (wstring msg) {
|
AfxMessageBox(msg.c_str());
|
}
|
|
std::thread t3(getAutoCancelSellMode, this, getInputCode());
|
t3.detach();
|
|
std::thread t4(getContinueBuyInfo, this, getInputCode());
|
t4.detach();
|
}
|
|
|
|
|
void CFloatTradeDlg::OnBnClickedCheckLockSellVolume()
|
{
|
// 锁量,
|
// 判断代码是否填充
|
try {
|
string code = getInputCode();
|
sellManager->init(code);
|
if (!checkLockVolume.GetCheck()) {
|
setLockInfo(code, false, 0);
|
return;
|
}
|
// 判断量是否输入
|
CString sellMoneyw;
|
editSellMoney.GetWindowTextW(sellMoneyw);
|
string sellMoney = StringUtil::cstring2String(sellMoneyw);
|
if (!StringUtil::isNumber(sellMoney)) {
|
throw wstring(L"请输入正确的金额");
|
}
|
int sellMoney_int = stoi(sellMoney);
|
setLockInfo(code, true, sellMoney_int);
|
}
|
catch (wstring msg) {
|
AfxMessageBox(msg.c_str());
|
}
|
}
|
|
|
void CFloatTradeDlg::OnBnClickedButtonAddWant()
|
{
|
try {
|
string code = getCode();
|
NetworkApi::add_want_buy(code);
|
CString msg(code.c_str());
|
msg.Append(_T("加入想买单成功"));
|
setMsg(msg, MSG_TYPE_SUCCESS);
|
}
|
catch (wstring st) {
|
CString msg(st.c_str());
|
setMsg(msg, MSG_TYPE_FAIL);
|
}
|
}
|
|
|
void CFloatTradeDlg::OnBnClickedButtonRemoveWant()
|
{
|
|
try {
|
string code = getCode();
|
NetworkApi::remove_want_buy(code);
|
CString msg(code.c_str());
|
msg.Append(_T("移除想买单成功"));
|
setMsg(msg, MSG_TYPE_SUCCESS);
|
}
|
catch (wstring st) {
|
CString msg(st.c_str());
|
setMsg(msg, MSG_TYPE_FAIL);
|
}
|
}
|
|
|
void CFloatTradeDlg::OnBnClickedButtonWantList()
|
{
|
|
try {
|
std::list<wstring> wlist = NetworkApi::list_want_buy();
|
|
MessageBox(formatListResult(wlist), TEXT("想买单"), MB_TASKMODAL);
|
}
|
catch (wstring st) {
|
CString cs(st.c_str());
|
AfxMessageBox(cs);
|
}
|
}
|
|
|
void CFloatTradeDlg::OnBnClickedButtonGetPositions()
|
{
|
requestAllPositions(this);
|
MessageBox(L"拉取成功");
|
}
|
|
|
void CFloatTradeDlg::OnDeltaposSpinVolume(NMHDR* pNMHDR, LRESULT* pResult)
|
{
|
LPNMUPDOWN pNMUpDown = reinterpret_cast<LPNMUPDOWN>(pNMHDR);
|
try {
|
CString st;
|
editSellMoney.GetWindowTextW(st);
|
int old = stoi(StringUtil::cstring2String(st));
|
if (pNMUpDown->iDelta < 0) {
|
st = std::to_wstring(old + 1000).c_str();
|
}
|
else {
|
if (old >= 1000)
|
{
|
st = std::to_wstring(old - 1000).c_str();
|
}
|
else {
|
st = std::to_wstring(0).c_str();
|
}
|
}
|
editSellMoney.SetWindowTextW(st);
|
}
|
catch (...) {
|
|
}
|
*pResult = 0;
|
}
|
|
|
void CFloatTradeDlg::OnBnClickedCheckLockBuyVolume()
|
{
|
// 锁量,
|
// 判断代码是否填充
|
try {
|
string code = getInputCode();
|
sellManager->init(code);
|
if (!checkLockBuyVolume.GetCheck()) {
|
SellSetting* sellSetting = sellManager->getSellSetting(code);
|
sellSetting->lockBuy = FALSE;
|
sellSetting->lockBuyMoney = 0;
|
sellManager->syncSettingToFile(code);
|
return;
|
}
|
// 判断量是否输入
|
CString buyMoneyw;
|
editBuyMoney.GetWindowTextW(buyMoneyw);
|
string buyMoney = StringUtil::cstring2String(buyMoneyw);
|
if (buyMoney.length() == 0 || !StringUtil::isNumber(buyMoney)) {
|
throw wstring(L"请输入正确的金额");
|
}
|
int buyMoney_int = stoi(buyMoney);
|
SellSetting* sellSetting = sellManager->getSellSetting(code);
|
sellSetting->lockBuy = TRUE;
|
sellSetting->lockBuyMoney = buyMoney_int;
|
sellManager->syncSettingToFile(code);
|
}
|
catch (wstring msg) {
|
checkLockBuyVolume.SetCheck(!checkLockBuyVolume.GetCheck());
|
|
AfxMessageBox(msg.c_str());
|
}
|
}
|
|
|
BOOL CFloatTradeDlg::PreTranslateMessage(MSG* pMsg)
|
{
|
if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN) // 按下 Enter 键
|
{
|
// 关闭窗口
|
// EndDialog(IDOK);
|
if (CWnd::GetFocus() == GetDlgItem(IDC_EDIT_SELL_VOLUME)) {
|
if (checkLockVolume.GetCheck()) {
|
// 保存锁定的金额
|
try {
|
string code = getInputCode();
|
CString sellMoneyw;
|
editSellMoney.GetWindowTextW(sellMoneyw);
|
string sellMoney = StringUtil::cstring2String(sellMoneyw);
|
if (!StringUtil::isNumber(sellMoney)) {
|
throw wstring(L"请输入正确的金额");
|
}
|
int sellMoney_int = stoi(sellMoney);
|
setLockInfo(code, true, sellMoney_int);
|
}
|
catch (wstring msg) {
|
AfxMessageBox(msg.c_str());
|
}
|
}
|
}
|
else if (CWnd::GetFocus() == GetDlgItem(IDC_EDIT_BUY_VOLUME))
|
{
|
// 保存锁定的金额
|
try {
|
string code = getInputCode();
|
CString buyMoneyw;
|
editBuyMoney.GetWindowTextW(buyMoneyw);
|
string buyMoney = StringUtil::cstring2String(buyMoneyw);
|
if (!StringUtil::isNumber(buyMoney)) {
|
throw wstring(L"请输入正确的金额");
|
}
|
int buyMoney_int = stoi(buyMoney);
|
setLockBuyInfo(code, true, buyMoney_int);
|
}
|
catch (wstring msg) {
|
AfxMessageBox(msg.c_str());
|
}
|
}
|
|
return TRUE;
|
}
|
|
return CDialogEx::PreTranslateMessage(pMsg);
|
}
|
|
|
void CFloatTradeDlg::OnBnClickedcodetradeupdatewatchbuy1()
|
{
|
// 批量更新填充数据
|
try {
|
list<SellRule> rules = MyApi::listSellRules();
|
if (rules.size() > 0)
|
{
|
for (list<SellRule>::iterator e = rules.begin(); e != rules.end(); ++e) {
|
SellRule rule = *e;
|
if (rule.type == 2) {
|
if (rule.buy1_volume > 0) {
|
// 获取买1
|
Buy1Info info = MyApi::getBuy1Info(StringUtil::cstring2String(rule.code));
|
int volume = (info.volume / 100) * 2 / 5;
|
int buy1Volume_int = volume;
|
rapidjson::StringBuffer buf;
|
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buf);
|
writer.StartObject();
|
writer.Key("id");
|
writer.String(StringUtil::cstring2String(rule.id_).c_str());
|
writer.Key("code");
|
writer.String(StringUtil::cstring2String(rule.code).c_str());
|
writer.Key("buy1_volume");
|
writer.Int(buy1Volume_int * 100);
|
|
writer.Key("buy1_price");
|
writer.String(StringUtil::to_string(info.price).c_str());
|
|
writer.Key("sell_volume");
|
writer.Int(rule.sell_volume);
|
|
writer.Key("sell_price_type");
|
writer.Int(rule.sell_price_type);
|
|
writer.Key("end_time");
|
writer.String(StringUtil::cstring2String(rule.end_time).c_str());
|
writer.EndObject();
|
const char* json_content = buf.GetString();
|
string result = NetworkApi::update_sell_rule(JsonUtil::parseUTF8(json_content));
|
rapidjson::GenericDocument<rapidjson::UTF16<>> doc = JsonUtil::parseUTF16(result);
|
if (doc[L"code"].GetInt() != 0) {
|
throw doc[L"msg"].GetString();
|
}
|
}
|
}
|
}
|
showTips(L"更新完成", MSG_TYPE_INFO, 1000);
|
}
|
else {
|
throw CString(L"没有板上盯数据");
|
}
|
}
|
|
|
|
|
catch (CString st) {
|
AfxMessageBox(st);
|
}
|
catch (wstring st) {
|
AfxMessageBox(CString(st.c_str()));
|
}
|
|
}
|
|
|
|
void CFloatTradeDlg::OnBnClickedButtonAddGreen()
|
{
|
try {
|
string code = getCode();
|
NetworkApi::add_green_buy(code);
|
CString msg(code.c_str());
|
msg.Append(_T("加入绿名单成功"));
|
setMsg(msg, MSG_TYPE_SUCCESS);
|
}
|
catch (wstring st) {
|
CString msg(st.c_str());
|
setMsg(msg, MSG_TYPE_FAIL);
|
}
|
}
|
|
|
void CFloatTradeDlg::OnBnClickedButtonRemoveGreen()
|
{
|
// 移除绿名单
|
try {
|
string code = getCode();
|
NetworkApi::remove_green_buy(code);
|
CString msg(code.c_str());
|
msg.Append(_T("移除绿名单成功"));
|
setMsg(msg, MSG_TYPE_SUCCESS);
|
}
|
catch (wstring st) {
|
CString msg(st.c_str());
|
setMsg(msg, MSG_TYPE_FAIL);
|
}
|
}
|
|
|
void CFloatTradeDlg::OnBnClickedButtonGreenList()
|
{
|
try {
|
std::list<wstring> wlist = NetworkApi::list_green_buy();
|
MessageBox(formatListResult(wlist), TEXT("绿名单"), MB_TASKMODAL);
|
}
|
catch (wstring st) {
|
CString cs(st.c_str());
|
AfxMessageBox(cs);
|
}
|
}
|
|
|
void CFloatTradeDlg::OnBnClickedaddwatchlimitupforsell()
|
{
|
try {
|
string code = getCode();
|
// 获取板上盯列表
|
// 批量更新填充数据
|
CodePosition* codePosition = sellManager->getCodePosition(code);
|
if (codePosition == nullptr) {
|
throw CString(L"当前代码无持仓");
|
}
|
|
if (codePosition->available <= 0) {
|
throw CString(L"当前代码无剩余持仓");
|
}
|
|
list<SellRule> rules = MyApi::listSellRules();
|
if (rules.size() > 0)
|
{
|
for (list<SellRule>::iterator e = rules.begin(); e != rules.end(); ++e) {
|
SellRule rule = *e;
|
if (rule.excuted) {
|
continue;
|
}
|
if (rule.type == 2) {
|
if (rule.buy1_volume > 0) {
|
if (code._Equal(StringUtil::cstring2String(rule.code))) {
|
throw CString(L"已存在板上盯");
|
return;
|
}
|
}
|
}
|
}
|
}
|
// 获取买1
|
Buy1Info info = MyApi::getBuy1Info(code);
|
int volume = (info.volume / 100) * 2 / 5;
|
int buy1Volume_int = volume;
|
rapidjson::StringBuffer buf;
|
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buf);
|
writer.StartObject();
|
writer.Key("code");
|
writer.String(code.c_str());
|
writer.Key("buy1_volume");
|
writer.Int(buy1Volume_int * 100);
|
|
writer.Key("buy1_price");
|
writer.String(StringUtil::to_string(info.price).c_str());
|
|
writer.Key("sell_volume");
|
writer.Int(codePosition->available);
|
|
writer.Key("sell_price_type");
|
writer.Int(0);
|
|
writer.Key("end_time");
|
writer.String("14:56:56");
|
|
writer.Key("type");
|
writer.Int(2);
|
|
writer.EndObject();
|
const char* json_content = buf.GetString();
|
string result = NetworkApi::add_sell_rule(JsonUtil::parseUTF8(json_content));
|
rapidjson::GenericDocument<rapidjson::UTF16<>> doc = JsonUtil::parseUTF16(result);
|
if (doc[L"code"].GetInt() != 0) {
|
throw doc[L"msg"].GetString();
|
}
|
MessageBox(L"添加板上盯完成", L"提示");
|
}
|
catch (CString msg) {
|
setMsg(msg, MSG_TYPE_FAIL);
|
}
|
catch (wstring msg) {
|
setMsg(msg.c_str(), MSG_TYPE_FAIL);
|
}
|
}
|
|
|
void CFloatTradeDlg::OnLButtonDown(UINT nFlags, CPoint point)
|
{
|
// TODO: 在此添加消息处理程序代码和/或调用默认值
|
RECT rect;
|
labelTotalPosition.GetWindowRect(&rect);
|
ScreenToClient(&rect);
|
if (point.x > rect.left && point.x < rect.right && point.y > rect.top && point.y < rect.bottom) {
|
if (positionDialog == nullptr) {
|
positionDialog = new PositionDlg;
|
positionDialog->Create(IDD_DIALOG_POSITION, this);
|
}
|
positionDialog->ShowWindow(SW_SHOW);
|
}
|
((CStatic*) GetDlgItem(IDC_STATIC_LS_PLATES))->GetWindowRect(&rect);
|
ScreenToClient(&rect);
|
if (point.x > rect.left && point.x < rect.right && point.y > rect.top && point.y < rect.bottom) {
|
// 点击低吸的板块
|
if (lowSuctionQueue.id.size() <= 0) {
|
return;
|
}
|
map<string, list<LowSuctionCodeInfo>> plateLimitUpCodes = lowSuctionQueue.plateLimitUpCodes;
|
for (map<string, list<LowSuctionCodeInfo>>::iterator e = plateLimitUpCodes.begin();e != plateLimitUpCodes.end();++e) {
|
string title = (*e).first;
|
list<LowSuctionCodeInfo> limitUpList = (*e).second;
|
CString msg = L"";
|
for (list<LowSuctionCodeInfo>::iterator ee = limitUpList.begin();ee != limitUpList.end();++ee) {
|
msg.Append(CString((*ee).code.c_str()));
|
msg.Append(L"【");
|
msg.Append(CString((*ee).name.c_str()));
|
msg.Append(L"】\n");
|
}
|
MessageBox(msg, CString(title.c_str()));
|
}
|
|
|
}
|
|
((CStatic*)GetDlgItem(IDC_STATIC_LS_CODE_NAME))->GetWindowRect(&rect);
|
ScreenToClient(&rect);
|
if (point.x > rect.left && point.x < rect.right && point.y > rect.top && point.y < rect.bottom) {
|
// 点击低吸的板块
|
if (lowSuctionQueue.id.size() <= 0) {
|
return;
|
}
|
// 添加到同花顺
|
try {
|
Win32Util::addToTHS(lowSuctionQueue.code);
|
}
|
catch (CString msg) {
|
}
|
catch (...) {
|
}
|
|
}
|
|
|
|
|
CDialogEx::OnLButtonDown(nFlags, point);
|
|
|
|
}
|
|
|
void CFloatTradeDlg::OnClickedCheckOcrCode()
|
{
|
if (((CButton*)GetDlgItem(check_ocr_code))->GetCheck()) {
|
canOCRCode = true;
|
this->hMouseHook = SetWindowsHookEx(WH_MOUSE_LL, MouseProc, 0, 0);
|
}
|
else {
|
canOCRCode = false;
|
UnhookWindowsHookEx(this->hMouseHook);
|
}
|
ConfigUtil::setEnableOCRCode(canOCRCode);
|
}
|
|
|
void CFloatTradeDlg::OnDestroy()
|
{
|
CDialogEx::OnDestroy();
|
|
if (thsCodeOCR != nullptr) {
|
delete thsCodeOCR;
|
}
|
}
|
|
|
void CFloatTradeDlg::OnStnClickedStaticTotalPosition()
|
{
|
|
}
|
|
|
void CFloatTradeDlg::OnStnClickedStaticLsCodeName()
|
{
|
// TODO: 在此添加控件通知处理程序代码
|
}
|
|
|
void CFloatTradeDlg::OnBnClickedButtonLsAddForbidden()
|
{
|
try {
|
OnBnClickedButtonLsNotBuy();
|
if (lowSuctionQueue.id.size() <= 0) {
|
throw CString(L"没有待下单数据");
|
return;
|
}
|
string result = LowSuctionNetworkApi::add_black_list(lowSuctionQueue.code);
|
auto doc = JsonUtil::parseUTF16(result);
|
if (!doc.IsObject()) {
|
throw CString(L"网络请求出错");
|
}
|
if (doc[L"code"].GetInt() != 0) {
|
throw CString(doc[L"msg"].GetString());
|
}
|
setMsg(L"低吸拉黑代码成功", MSG_TYPE_SUCCESS);
|
|
}
|
catch (CString msg) {
|
setMsg(msg, MSG_TYPE_FAIL);
|
}
|
}
|
|
|
void CFloatTradeDlg::OnBnClickedButtonLsBuy()
|
{
|
try {
|
if (lowSuctionQueue.id.size() <= 0) {
|
throw CString(L"没有待下单数据");
|
return;
|
}
|
string result = LowSuctionNetworkApi::set_buy(lowSuctionQueue.id);
|
auto doc = JsonUtil::parseUTF16(result);
|
if (!doc.IsObject()) {
|
throw CString(L"网络请求出错");
|
}
|
if (doc[L"code"].GetInt() != 0) {
|
throw CString(doc[L"msg"].GetString());
|
}
|
setMsg(L"确认下单成功", MSG_TYPE_SUCCESS);
|
requestReadLSPlaceOrderRecords(this);
|
}
|
catch (CString msg) {
|
setMsg(msg, MSG_TYPE_FAIL);
|
}
|
}
|
|
|
void CFloatTradeDlg::OnBnClickedButtonLsNotBuy()
|
{
|
try {
|
if (lowSuctionQueue.id.size() <= 0) {
|
throw CString(L"没有待下单数据");
|
return;
|
}
|
string result = LowSuctionNetworkApi::set_not_buy(lowSuctionQueue.id);
|
auto doc = JsonUtil::parseUTF16(result);
|
if (!doc.IsObject()) {
|
throw CString(L"网络请求出错");
|
}
|
if (doc[L"code"].GetInt() != 0) {
|
throw CString(doc[L"msg"].GetString());
|
}
|
setMsg(L"确认不下单成功", MSG_TYPE_SUCCESS);
|
requestReadLSPlaceOrderRecords(this);
|
}
|
catch (CString msg) {
|
setMsg(msg, MSG_TYPE_FAIL);
|
}
|
}
|
|
|
void CFloatTradeDlg::OnStnClickedStaticLsPlates()
|
{
|
|
|
|
|
|
|
|
|
}
|
|
void CFloatTradeDlg::OnCbnSelchangeComboContinueBuyList()
|
{
|
bool check = ((CButton*)GetDlgItem(IDC_CHECK_CONTINUE_BUY))->GetCheck();
|
if (!check) {
|
return;
|
}
|
|
OnBnClickedContinueBuy();
|
}
|
|
void CFloatTradeDlg::OnBnClickedContinueBuy()
|
{
|
auto checkControl = (CButton*)GetDlgItem(IDC_CHECK_CONTINUE_BUY);
|
string code = "";
|
try {
|
code = getInputCode();
|
}
|
catch (wstring msg){
|
setMsg(msg.c_str(), MSG_TYPE_FAIL);
|
checkControl->SetCheck(!checkControl->GetCheck());
|
return;
|
}
|
try {
|
bool check = ((CButton*)GetDlgItem(IDC_CHECK_CONTINUE_BUY))->GetCheck();
|
if (check) {
|
CComboBox* comboMoneyList = (CComboBox*)GetDlgItem(IDC_COMBO_CONTINUE_BUY_MONEY);
|
int index = comboMoneyList->GetCurSel();
|
if (index < 0) {
|
checkControl->SetCheck(!checkControl->GetCheck());
|
throw wstring(L"请选择金额");
|
}
|
CString strText;
|
comboMoneyList->GetLBText(index, strText);
|
int money = _ttoi(strText);
|
auto result = NetworkApi::set_continue_buy_money(code, money);
|
auto doc = JsonUtil::parseUTF16(result);
|
if (!doc.IsObject()) {
|
checkControl->SetCheck(!checkControl->GetCheck());
|
throw CString(L"网络请求出错");
|
}
|
if (doc[L"code"].GetInt() != 0) {
|
checkControl->SetCheck(!checkControl->GetCheck());
|
throw CString(doc[L"msg"].GetString());
|
}
|
setMsg(L"续买金额设置成功", MSG_TYPE_SUCCESS);
|
}
|
else {
|
int money = 0;
|
auto result = NetworkApi::set_continue_buy_money(code, money);
|
auto doc = JsonUtil::parseUTF16(result);
|
if (!doc.IsObject()) {
|
checkControl->SetCheck(!checkControl->GetCheck());
|
throw CString(L"网络请求出错");
|
}
|
if (doc[L"code"].GetInt() != 0) {
|
checkControl->SetCheck(!checkControl->GetCheck());
|
throw CString(doc[L"msg"].GetString());
|
}
|
setMsg(L"续买金额取消成功", MSG_TYPE_SUCCESS);
|
}
|
|
}
|
catch (wstring msg) {
|
setMsg(msg.c_str(), MSG_TYPE_FAIL);
|
}
|
|
}
|