Repository navigation
Expand file tree
/
Copy pathxTrader.cpp
More file actions
107 lines (81 loc) · 1.99 KB
/
Copy pathxTrader.cpp
File metadata and controls
107 lines (81 loc) · 1.99 KB
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
#include "stdafx.h"
#include "xTrader.h"
#include "LoginDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
HANDLE g_hEvent;
BEGIN_MESSAGE_MAP(CXTraderApp, CWinApp)
//{{AFX_MSG_MAP(CXTraderApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
END_MESSAGE_MAP()
CXTraderApp::CXTraderApp()
{
m_MApi = NULL;
m_TApi = NULL;
m_cQ = NULL;
m_cT = NULL;
g_hEvent=CreateEvent(NULL, true, false, NULL);
}
CXTraderApp::~CXTraderApp()
{
}
void CXTraderApp::CreateApi()
{
char szFilePath[MAX_PATH]={0};
GetCurDir(szFilePath,"log\\");
m_TApi = CThostFtdcTraderApi::CreateFtdcTraderApi(szFilePath);
m_cT = new CtpTdSpi(m_TApi,m_cfg.m_sBkrId,m_cfg.m_sUid,
m_cfg.m_sPwd,m_cfg.m_sDymPwd,m_cfg.m_sAtCode);
m_TApi->RegisterSpi(m_cT);
m_TApi->SubscribePublicTopic(THOST_TERT_QUICK);
m_TApi->SubscribePrivateTopic(THOST_TERT_QUICK);
m_MApi = CThostFtdcMdApi::CreateFtdcMdApi(szFilePath,m_cfg.m_bIsUdp,m_cfg.m_bIsMulcast);
m_cQ = new CtpMdSpi(m_MApi,m_cfg.m_sBkrId);
m_MApi->RegisterSpi(m_cQ);
}
void CXTraderApp::ReleaseApi()
{
if(m_cT) { m_cT->ReqUserLogout(); }
RELZ(m_TApi);
DEL(m_cT);
RELZ(m_MApi);
DEL(m_cQ);
}
void CXTraderApp::LoadGlobCfg()
{
CString szPath = GetSpecFilePath(_T("log\\"));
if (!PathIsDirectory(szPath))
{ CreateDirectory(szPath,NULL); }
if(!PathFileExists(LoadStr(IDS_CFG_FILE)))
{ res2file(MAKEINTRESOURCE(IDR_CONFBAK),_T("STUFF"),LoadStr(IDS_CFG_FILE)); }
m_cfg.ProcConfigs();
}
CXTraderApp theApp;
BOOL CXTraderApp::InitInstance()
{
SetHighPriority();
if (!AfxSocketInit()){ return FALSE; }
LoadGlobCfg();
LoginDlg login;
if (login.DoModal() != IDOK) { return FALSE; }
CXTraderDlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
}
else if (nResponse == IDCANCEL)
{
}
return FALSE;
}
int CXTraderApp::ExitInstance()
{
ReleaseApi();
return CWinApp::ExitInstance();
}