admin
2025-07-17 6cd92a169cbc0db35042f243a09d976fd3e1445c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
 
// FloatTradeDlg.h: 头文件
//
 
#pragma once
#include "MyButton.h"
#include "CColorStatic.h"
#include <string>
#include <thread>
#include <map>
#include <list>
#include "SellDlg.h"
#include "SellStruct.h"
#include "SellManager.h"
#include "TipDlg.h"
#include "PositionDlg.h"
#include <ctime>
#include "ThsCodeOCR.h"
#include "DealQueueDlg.h"
#include "DataStruct.h"
 
 
#define WM_FLOAT_MSG (WM_USER + 100)
 
#define COLOR_RED RGB(205,54,54)
#define COLOR_GREEN RGB(0,230,0)
#define COLOR_BLUE RGB(25,6,173)
#define COLOR_BLACK RGB(0,0,0)
#define COLOR_ORANGE RGB(255,128,32)
 
using namespace std;
 
 
enum MSG_TYPE{
MSG_TYPE_INFO,
MSG_TYPE_SUCCESS,
MSG_TYPE_SELL_SUCCESS,
MSG_TYPE_FAIL,
MSG_TYPE_WARNING,
};
 
// 悬浮消息
struct FloatMsg {
    string msg;
    MSG_TYPE msgType;
    int position;
    int showMS;// 显示的ms数
};
 
// CFloatTradeDlg 对话框
class CFloatTradeDlg : public CDialogEx
{
private:
    CFont bigFont;
    CFont middleFont;
    CFont smallFont;
    COLORREF msgColor;
    std::thread* cancelMsgThread;
    static bool breakCancelMsg;
    // 正在请求的代码
    string requestingCode;
    // 下单窗口
    HWND buyWin;
    // 持仓map
    map<string, CodePosition> positionMap;
 
    // 上次点击买的时间戳
    std::time_t lastBuyClickTime;
 
    LowSuctionQueue lowSuctionQueue;
 
 
    SellManager* sellManager;
 
    map<string, SellDlg*> sellDlgMap;
 
    // 持仓
    PositionDlg* positionDialog;
 
    // 鼠标钩子
    static HHOOK hMouseHook;
 
    ThsCodeOCR* thsCodeOCR;
 
    // 最近一次识别的代码
    string lastOCRCode;
 
    // 代码识别的截止时间
    static long ocrCodeExpireTimestamp;
    
    // 是否可以识别
    bool canOCRCode;
 
    // 成交队列
    DealQueueDlg* dealQueueDlg;
 
    void initView();
 
    void initData();
 
    string getCode();
 
    void setMsg(CString msg, MSG_TYPE msgType,  bool autoCancel=TRUE);
 
    void showTips(CString str, int textColorType,  int delayMs=2000, int position = TipDlg::POSITION_NORMAL);
 
    // 获取交易状态
    static void getTradeState(CFloatTradeDlg* context);
 
    static void getAutoCancelSellMode(CFloatTradeDlg* context,string code);
 
    // 获取续买信息
    static void getContinueBuyInfo(CFloatTradeDlg* context, string code);
 
    static void setContinueBuyMoney(CFloatTradeDlg* context, string code, int money);
 
    //获取交易模式
    static void getTradeMode(CFloatTradeDlg* context);
    //清除消息
    static void clearMsg(CFloatTradeDlg* context);
 
    static void getCodeDesc(string code,CFloatTradeDlg* context);
 
 
    // 获取代码持仓状态 
    static void requestCodePosition(string code, CFloatTradeDlg* context,bool showCodeDesc, int delayMs=0);
 
    // 更新持仓
    static void updateCodePosition(string code, CFloatTradeDlg* context);
 
    // 获取卖结果 
    static void requestSellResult(int order_ref, CFloatTradeDlg* context, int delayMs = 0);
 
    //定时更新持仓信息
    static void regularUpdatePositionInfo(CFloatTradeDlg* context);
 
    // 消息接收器心跳包发送
    static void runPushMsgHeart(CFloatTradeDlg* context, SOCKET socket);
 
    // 运行推送消息接收器
    static void runPushMsgReceiver(CFloatTradeDlg* context);
 
    // 开始震动
    static void startShake(CFloatTradeDlg* context,CString text);
 
    // 展示持仓数据
    void showCodePositionInfo();
 
    // 量的分配
    list<UINT> distributeVolume(UINT total, UINT percent);
    // 计算量索引
    UINT computeSellVolume(list<UINT> volumeList, list<int> sell_volumes);
 
    CString formatListResult(std::list<wstring> wlist);
 
    // 设置卖视图
    void initSellSettingView();
 
 
    // 获取输入的代码
    string getInputCode();
 
    // 卖回调
    static void OnSellCallback(string code, CWnd* context);
    // 关闭卖回调
    static void OnSellCloseCallback(string code, CWnd* context);
 
    
 
    static void sell(string code, CFloatTradeDlg* context);
    // 填充卖资金根据量
    void fillSellMoney(string code, int volume);
 
    int sellMoneyToVolume(string code, int money);
 
    void buy();
 
    static void showFloatMsg(CFloatTradeDlg *context, CString msg,MSG_TYPE msgType,int showMS=2000, int position=TipDlg::POSITION_NORMAL);
 
    static void requestAllPositions(CFloatTradeDlg *context);
 
    // 填充预设金额
    void fillMoneys();
 
    static void runTHSCodeOCR(CFloatTradeDlg* context);
 
    // 设置目标代码
    void setTargetCode(string code);
 
 
    // 设置锁定信息
    void setLockInfo(string code, bool lock, int lockMoney);
 
    // 设置锁定买入金额
    void setLockBuyInfo(string code, bool lock, int lockMoney);
 
 
    // 请求低吸下单待确认记录
    static void requestReadLSPlaceOrderRecords(CFloatTradeDlg* context);
 
    static void runReadLSPlaceOrderRecords(CFloatTradeDlg* context);
 
 
// 构造
public:
    CFloatTradeDlg(CWnd* pParent = nullptr);    // 标准构造函数
 
// 对话框数据
#ifdef AFX_DESIGN_TIME
    enum { IDD = IDD_TRADE };
#endif
 
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持
 
 
// 实现
protected:
    HICON m_hIcon;
 
    // 生成的消息映射函数
    virtual BOOL OnInitDialog();
    void OnHotKey(UINT nHotKeyId, UINT nKey, UINT nModifiers);
    afx_msg void OnPaint();
    afx_msg HCURSOR OnQueryDragIcon();
    DECLARE_MESSAGE_MAP()
 
    static LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam);
    
public:
    afx_msg void OnClickedBtnAlreadyCanceled();
    afx_msg void OnClickedBtnBlack();
    afx_msg void OnClickedBtnCloseBuy();
    afx_msg void OnClickedBtnOpenBuy();
    afx_msg void OnClickedBtnPauseBuy();
    afx_msg void OnClickedBtnPauseBuyRemove();
    afx_msg void OnClickedBtnRemoveBlack();
    afx_msg void OnClickedBtnRemoveWhite();
    afx_msg void OnClickedBtnSell();
    afx_msg void OnClickedBtnWantBuy();
    afx_msg void OnClickedBtnWantBuyRemove();
    afx_msg void OnClickedBtnWhite();
    afx_msg void OnClickedCheckAutoClick();
    afx_msg void OnClickedCheckAutoRefresh();
    afx_msg void OnClickedCheckTradeQuickKey();
    afx_msg LRESULT OnFloatMsg(WPARAM wParam, LPARAM lParam);
 
    CStatic labelAtrribute;
    CButton btnSell;
    CButton btnCancelBuy;
    CButton btnCloseBuy;
    CButton btnOpenBuy;
    //CButton btnBuyModeWant;
    //CButton btnBuyModeAll;
    CButton checkAutoRefresh;
    CButton checkAutoCancelSell;
    CButton checkTradeQuickKey;
    CButton whiteList;
    CButton blackList;
    afx_msg BOOL OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct);
    afx_msg void OnBnClickedwantlist();
    afx_msg void OnBnClickedpausebuylist();
    afx_msg void OnBnClickedblacklist();
    afx_msg void OnBnClickedwhitelist();
    CEdit editCode;
    afx_msg void OnClose();
    afx_msg void OnBnClickedbuy();
    afx_msg void OnBnClickedconfig();
    //CButton btnBuy;
    afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
    afx_msg void OnBnClickedcodetradeinfo();
    afx_msg void OnBnClickedButtonSellVolume1();
    CStatic labelTotalPosition;
    CStatic labelSelledVolume;
    CEdit editSellMoney;
    CComboBox comboSellPriceType;
    CButton btnSellRule;
    afx_msg void OnBnClickedButtonRefresh();
    afx_msg void OnBnClickedmustlist();
    afx_msg void OnBnClickedmust();
    afx_msg void OnBnClickedremovefrommust();
    CButton checkLockVolume;
    afx_msg void OnBnClickedCheckLockSellVolume();
    afx_msg void OnBnClickedCheckMarketSituation();
    afx_msg void OnBnClickedButtonAddWant();
    afx_msg void OnBnClickedButtonRemoveWant();
    afx_msg void OnBnClickedButtonWantList();
    afx_msg void OnBnClickedButtonGetPositions();
    afx_msg void OnDeltaposSpinVolume(NMHDR* pNMHDR, LRESULT* pResult);
    CButton checkLockBuyVolume;
    CEdit editBuyMoney;
    afx_msg void OnBnClickedCheckLockBuyVolume();
    virtual BOOL PreTranslateMessage(MSG* pMsg);
    afx_msg void OnBnClickedcodetradeupdatewatchbuy1();
    afx_msg void OnBnClickedButtonAddGreen();
    afx_msg void OnBnClickedButtonRemoveGreen();
    afx_msg void OnBnClickedButtonGreenList();
    CStatic labelCodeInfo;
    CButton btnBuy;
    CComboBox comboBuyPriceType;
    afx_msg void OnBnClickedaddwatchlimitupforsell();
    afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
    afx_msg void OnClickedCheckOcrCode();
    afx_msg void OnDestroy();
    afx_msg void OnStnClickedStaticTotalPosition();
 
 
    static void sellByVolume(string code, int volume, CFloatTradeDlg* context);
    afx_msg void OnStnClickedStaticLsCodeName();
    afx_msg void OnBnClickedButtonLsAddForbidden();
    afx_msg void OnBnClickedButtonLsBuy();
    afx_msg void OnBnClickedButtonLsNotBuy();
    afx_msg void OnStnClickedStaticLsPlates();
 
    afx_msg void OnCbnSelchangeComboContinueBuyList();
 
    afx_msg void OnBnClickedContinueBuy();
};