-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathQuoteSpi.cpp
executable file
·117 lines (96 loc) · 3.01 KB
/
QuoteSpi.cpp
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
#include "QuoteSpi.h"
using namespace std;
QuoteSpi::QuoteSpi(wxEvtHandler* handler, map<string, CThostFtdcInstrumentField>& validInstrument)
:pUserApi(NULL)
,mainWin_(handler)
,instrumentData_(validInstrument)
{
}
void QuoteSpi::DisplayMsg(const wxString& msg, int type)
{
if (mainWin_)
{
wxCommandEvent evt(EVENT_MAIN_WIN_SHOW_MSG);
evt.SetInt(type);
evt.SetString(msg);
mainWin_->AddPendingEvent(evt);
}
else
{
wxLogVerbose(msg);
}
}
void QuoteSpi::OnRspError(CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast)
{
}
void QuoteSpi::OnFrontConnected()
{
ReqUserLogin(investor_, password_);
}
void QuoteSpi::OnFrontDisconnected(int nReason)
{
DisplayMsg("行情断开");
}
void QuoteSpi::OnHeartBeatWarning(int nTimeLapse)
{
}
void QuoteSpi::OnRspUserLogin(CThostFtdcRspUserLoginField* pRspUserLogin,
CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast)
{
if(IsErrorRspInfo(pRspInfo))
{
DisplayMsg(wxString::Format("登录错误:%s", pRspInfo->ErrorMsg));
}
else
{
tradingDay_ = pRspUserLogin->TradingDay;
DisplayMsg("行情登录成功!"); //
}
}
void QuoteSpi::OnRspSubMarketData(CThostFtdcSpecificInstrumentField* pSpecificInstrument, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast)
{
}
void QuoteSpi::OnRspUnSubMarketData(CThostFtdcSpecificInstrumentField* pSpecificInstrument, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast)
{
}
//深度行情响应
void QuoteSpi::OnRtnDepthMarketData(CThostFtdcDepthMarketDataField* pDepthMarketData)
{
if (pDepthMarketData) SaveTickInfo(pDepthMarketData);
}
CThostFtdcDepthMarketDataField QuoteSpi::GetMarketDataByInstrumentId(const char* id) const
{
CThostFtdcDepthMarketDataField data;
memset(&data, 0, sizeof(data));
{
wxMutexLocker lock(tickLocker_);
map<string, CThostFtdcDepthMarketDataField>::const_iterator it = tickData_.find(id);
if (it == tickData_.end()) return data;
return it->second;
}
}
//tick写入文本
void QuoteSpi::SaveTickInfo(CThostFtdcDepthMarketDataField* f)
{
wxMutexLocker lock(tickLocker_);
//合法合约//合法数据
map<string, CThostFtdcInstrumentField>::const_iterator it = instrumentData_.find(f->InstrumentID);
if(it != instrumentData_.end() && f->LastPrice < f->UpperLimitPrice)
{
CThostFtdcInstrumentField instField;
memset(&instField, 0, sizeof(instField));
instField = it->second; //合约信息
strcpy(f->TradingDay, tradingDay_.c_str()); //日期
strcpy(f->ExchangeID, instField.ExchangeID); //交易所
if(f->AskPrice1 > f->UpperLimitPrice) //单边有挂边的情况
f->AskPrice1 = f->LastPrice;
if(f->BidPrice1 > f->UpperLimitPrice)
f->BidPrice1 = f->LastPrice;
if(instField.ExchangeID == "CZCE") //成交额与均价
f->Turnover *= instField.VolumeMultiple;
else
f->AveragePrice /= instField.VolumeMultiple;
tickData_[string(f->InstrumentID)] = *f; //更新Tick
return;
}
}