Repository navigation
Expand file tree
/
Copy pathmdspi.cpp
More file actions
152 lines (128 loc) · 3.71 KB
/
Copy pathmdspi.cpp
File metadata and controls
152 lines (128 loc) · 3.71 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
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
#include "stdafx.h"
#include "mdspi.h"
#include "xTrader.h"
extern HANDLE g_hEvent;
void CtpMdSpi::OnRspError(CThostFtdcRspInfoField *pRspInfo,
int nRequestID, bool bIsLast)
{
IsErrorRspInfo(pRspInfo);
}
void CtpMdSpi::OnFrontDisconnected(int nReason)
{
CXTraderDlg* p = g_Dlg;
if (p){ ::PostMessage(p->m_hWnd,WM_MDISCON_MSG,0,0); }
}
void CtpMdSpi::OnHeartBeatWarning(int nTimeLapse)
{
}
void CtpMdSpi::OnFrontConnected()
{
ReqUserLogin(/*pApp->m_sBkrId*/);
}
void CtpMdSpi::ReqUserLogin(/*TThostFtdcBrokerIDType appId*/)
{
CThostFtdcReqUserLoginField req;
ZeroMemory(&req, sizeof(req));
strcpy(req.BrokerID, m_sBkrID);
//strcpy(m_sBkrID,appId);
m_pApi->ReqUserLogin(&req, ++m_iReqId);
}
void CtpMdSpi::OnRspUserLogin(CThostFtdcRspUserLoginField *pRspUserLogin,
CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
{
if (!IsErrorRspInfo(pRspInfo) && pRspUserLogin)
{
CXTraderDlg* p = g_Dlg;
if (p)
{ ::PostMessage(p->m_hWnd,WM_MDRECON_MSG,0,0); }
}
if(bIsLast) SetEvent(g_hEvent);
}
void CtpMdSpi::ReqUserLogout()
{
CThostFtdcUserLogoutField req;
ZeroMemory(&req, sizeof(req));
strcpy(req.BrokerID, m_sBkrID);
m_pApi->ReqUserLogout(&req, ++m_iReqId);
}
///登出请求响应
void CtpMdSpi::OnRspUserLogout(CThostFtdcUserLogoutField *pUserLogout,
CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
{
if( !IsErrorRspInfo(pRspInfo) && pUserLogout)
{
}
if(bIsLast) SetEvent(g_hEvent);
}
void CtpMdSpi::SubscribeMarketData(char *pInstId[], int nCount)
{
m_pApi->SubscribeMarketData(pInstId, nCount);
}
void CtpMdSpi::OnRspSubMarketData(
CThostFtdcSpecificInstrumentField *pSpecificInstrument,
CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
{
if (!IsErrorRspInfo(pRspInfo) && pSpecificInstrument)
{ /*bMdSignal = TRUE; */ }
else
{ /*bMdSignal = FALSE; */}
//if(bIsLast) SetEvent(g_hEvent);
}
void CtpMdSpi::UnSubscribeMarketData(char *pInstId[], int nCount)
{
m_pApi->UnSubscribeMarketData(pInstId, nCount);
}
void CtpMdSpi::OnRspUnSubMarketData(CThostFtdcSpecificInstrumentField *pSpecificInstrument,
CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
{
if (!IsErrorRspInfo(pRspInfo) && pSpecificInstrument)
{ /*bMdSignal = TRUE; */ }
else
{ /*bMdSignal = FALSE; */}
//if(bIsLast) SetEvent(g_hEvent);
}
void CtpMdSpi::OnRtnDepthMarketData(CThostFtdcDepthMarketDataField *pDepthMarketData)
{
CXTraderDlg* p = g_Dlg;
if (p)
{
CThostFtdcDepthMarketDataField *pDepthMd = new CThostFtdcDepthMarketDataField;
memcpy(pDepthMd,pDepthMarketData,sizeof(CThostFtdcDepthMarketDataField));
::PostMessage(p->m_hWnd,WM_UPDATEMD_MSG,0,(LPARAM)pDepthMd);
}
}
void CtpMdSpi::SubscribeForQt(char *ppInstrumentID[], int nCount)
{
m_pApi->SubscribeForQuoteRsp(ppInstrumentID,nCount);
}
///订阅询价应答
void CtpMdSpi::OnRspSubForQuoteRsp(CThostFtdcSpecificInstrumentField *pSpecificInstrument,
CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
{
if (!IsErrorRspInfo(pRspInfo) && pSpecificInstrument)
{ /*bMdSignal = TRUE; */ }
else
{ /*bMdSignal = FALSE; */}
}
void CtpMdSpi::UnSubscribeForQt(char *ppInstrumentID[], int nCount)
{
m_pApi->UnSubscribeForQuoteRsp(ppInstrumentID,nCount);
}
///取消订阅询价应答
void CtpMdSpi::OnRspUnSubForQuoteRsp(CThostFtdcSpecificInstrumentField *pSpecificInstrument,
CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
{
if (!IsErrorRspInfo(pRspInfo) && pSpecificInstrument)
{ /*bMdSignal = TRUE; */ }
else
{ /*bMdSignal = FALSE; */}
}
///询价通知
void CtpMdSpi::OnRtnForQuoteRsp(CThostFtdcForQuoteRspField *pForQuoteRsp)
{
}
bool CtpMdSpi::IsErrorRspInfo(CThostFtdcRspInfoField *pRspInfo)
{
bool ret = ((pRspInfo) && (pRspInfo->ErrorID != 0));
return ret;
}