Skip to content

Commit 7c26de7

Browse files
committed
全改成向队列申请内存模式,为内存池做准备
1 parent 8b6046b commit 7c26de7

File tree

26 files changed

+1675
-1952
lines changed

26 files changed

+1675
-1952
lines changed

QuantBox.XAPI/PInvokeUtility.cs

+11-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,17 @@ public static string GetUnicodeString(byte[] str)
2020
{
2121
return string.Empty;
2222
}
23-
// 只移除了最后一个,中间出现的不会动,导致NLog输出的有可能截断
24-
return encodingGB2312.GetString(str).TrimEnd('\0');
23+
int bytecount = 0;
24+
foreach(byte b in str)
25+
{
26+
if (0 == b)
27+
break;
28+
++bytecount;
29+
}
30+
if (0 == bytecount)
31+
return string.Empty;
32+
//比TrimEnd('\0');快,减少了内存的复制
33+
return encodingGB2312.GetString(str, 0, bytecount);
2534
}
2635

2736
public static T GetObjectFromIntPtr<T>(IntPtr handler)

QuantBox.XAPI/Program.cs

+10-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ static void OnConnectionStatus2(object sender, ConnectionStatus status, ref RspU
2424

2525
static void OnRtnDepthMarketData(object sender, ref DepthMarketDataField marketData)
2626
{
27+
Debugger.Log(0, null, "CTP:C#");
2728
Console.WriteLine(marketData.InstrumentID);
2829
Console.WriteLine(marketData.ExchangeID);
2930
Console.WriteLine(marketData.LastPrice);
@@ -63,7 +64,7 @@ static void Main(string[] args)
6364
{
6465
//for (int i = 0; i < 10000; ++i)
6566
{
66-
test_KingstarStock_Main(args);
67+
test_CTP_Main(args);
6768
}
6869
Console.ReadKey();
6970
}
@@ -163,6 +164,11 @@ static void test_CTP_Main(string[] args)
163164

164165
api.Server.BrokerID = "1017";
165166
api.Server.Address = "tcp://ctpmn1-front1.citicsf.com:51213";
167+
//api = new XApi(@"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\XAPI\CTP\x86\QuantBox_CTP_Trade.dll");
168+
169+
//api.Server.BrokerID = "1017";
170+
//api.Server.Address = "tcp://ctpmn1-front1.citicsf.com:51205";
171+
//api.Server.PrivateTopicResumeType = ResumeType.Undefined;
166172

167173
api.User.UserID = "00000015";
168174
api.User.Password = "123456";
@@ -171,8 +177,10 @@ static void test_CTP_Main(string[] args)
171177
api.OnRtnDepthMarketData = OnRtnDepthMarketData;
172178

173179
api.Connect();
180+
Thread.Sleep(3 * 1000);
181+
api.Subscribe("IF1502", "");
174182

175-
Thread.Sleep(5*1000);
183+
Thread.Sleep(5 * 1000);
176184

177185
api.Dispose();
178186

QuantBox.XAPI/QuantBox.XAPI.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
<OutputPath>C:\Program Files\SmartQuant Ltd\OpenQuant 2014\</OutputPath>
6868
<DefineConstants>DEBUG;TRACE</DefineConstants>
6969
<DebugType>full</DebugType>
70-
<PlatformTarget>x64</PlatformTarget>
70+
<PlatformTarget>AnyCPU</PlatformTarget>
7171
<ErrorReport>prompt</ErrorReport>
7272
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
7373
</PropertyGroup>

QuantBox_CTP_Quote/MdUserApi.cpp

+98-91
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void CMdUserApi::QueryInThread(char type, void* pApi1, void* pApi2, double doubl
6666
}
6767
else
6868
{
69-
m_msgQueue_Query->Input(type, pApi1, pApi2, double1, double2, ptr1, size1, ptr2, size2, ptr3, size3);
69+
m_msgQueue_Query->Input_Copy(type, pApi1, pApi2, double1, double2, ptr1, size1, ptr2, size2, ptr3, size3);
7070
//失败,按4的幂进行延时,但不超过1s
7171
m_nSleep *= 4;
7272
m_nSleep %= 1023;
@@ -103,11 +103,12 @@ bool CMdUserApi::IsErrorRspInfo(CThostFtdcRspInfoField *pRspInfo, int nRequestID
103103
bool bRet = ((pRspInfo) && (pRspInfo->ErrorID != 0));
104104
if(bRet)
105105
{
106-
ErrorField field = { 0 };
107-
field.ErrorID = pRspInfo->ErrorID;
108-
strcpy(field.ErrorMsg, pRspInfo->ErrorMsg);
106+
ErrorField* pField = (ErrorField*)m_msgQueue->new_block(sizeof(ErrorField));
109107

110-
m_msgQueue->Input(ResponeType::OnRtnError, m_msgQueue, this, bIsLast, 0, &field, sizeof(ErrorField), nullptr, 0, nullptr, 0);
108+
pField->ErrorID = pRspInfo->ErrorID;
109+
strcpy(pField->ErrorMsg, pRspInfo->ErrorMsg);
110+
111+
m_msgQueue->Input_NoCopy(ResponeType::OnRtnError, m_msgQueue, this, bIsLast, 0, pField, sizeof(ErrorField), nullptr, 0, nullptr, 0);
111112
}
112113
return bRet;
113114
}
@@ -127,7 +128,7 @@ void CMdUserApi::Connect(const string& szPath,
127128
memcpy(&m_ServerInfo, pServerInfo, sizeof(ServerInfoField));
128129
memcpy(&m_UserInfo, pUserInfo, sizeof(UserInfoField));
129130

130-
m_msgQueue_Query->Input(RequestType::E_Init, this, nullptr, 0, 0,
131+
m_msgQueue_Query->Input_NoCopy(RequestType::E_Init, this, nullptr, 0, 0,
131132
nullptr, 0, nullptr, 0, nullptr, 0);
132133
}
133134

@@ -141,7 +142,7 @@ int CMdUserApi::_Init()
141142
m_pApi = CThostFtdcMdApi::CreateFtdcMdApi(pszPath, m_ServerInfo.IsUsingUdp, m_ServerInfo.IsMulticast);
142143
delete[] pszPath;
143144

144-
m_msgQueue->Input(ResponeType::OnConnectionStatus, m_msgQueue, this, ConnectionStatus::Initialized, 0, nullptr, 0, nullptr, 0, nullptr, 0);
145+
m_msgQueue->Input_NoCopy(ResponeType::OnConnectionStatus, m_msgQueue, this, ConnectionStatus::Initialized, 0, nullptr, 0, nullptr, 0, nullptr, 0);
145146

146147
if (m_pApi)
147148
{
@@ -165,27 +166,29 @@ int CMdUserApi::_Init()
165166

166167
//初始化连接
167168
m_pApi->Init();
168-
m_msgQueue->Input(ResponeType::OnConnectionStatus, m_msgQueue, this, ConnectionStatus::Connecting, 0, nullptr, 0, nullptr, 0, nullptr, 0);
169+
m_msgQueue->Input_NoCopy(ResponeType::OnConnectionStatus, m_msgQueue, this, ConnectionStatus::Connecting, 0, nullptr, 0, nullptr, 0, nullptr, 0);
169170
}
170171

171172
return 0;
172173
}
173174

174175
void CMdUserApi::ReqUserLogin()
175176
{
176-
CThostFtdcReqUserLoginField body = { 0 };
177+
//CThostFtdcReqUserLoginField* pBody = new CThostFtdcReqUserLoginField();
178+
//memset(pBody, 0, sizeof(CThostFtdcReqUserLoginField));
179+
CThostFtdcReqUserLoginField* pBody = (CThostFtdcReqUserLoginField*)m_msgQueue_Query->new_block(sizeof(CThostFtdcReqUserLoginField));
177180

178-
strncpy(body.BrokerID, m_ServerInfo.BrokerID, sizeof(TThostFtdcBrokerIDType));
179-
strncpy(body.UserID, m_UserInfo.UserID, sizeof(TThostFtdcInvestorIDType));
180-
strncpy(body.Password, m_UserInfo.Password, sizeof(TThostFtdcPasswordType));
181+
strncpy(pBody->BrokerID, m_ServerInfo.BrokerID, sizeof(TThostFtdcBrokerIDType));
182+
strncpy(pBody->UserID, m_UserInfo.UserID, sizeof(TThostFtdcInvestorIDType));
183+
strncpy(pBody->Password, m_UserInfo.Password, sizeof(TThostFtdcPasswordType));
181184

182-
m_msgQueue_Query->Input(RequestType::E_ReqUserLoginField, this, nullptr, 0, 0,
183-
&body, sizeof(CThostFtdcReqUserLoginField), nullptr, 0, nullptr, 0);
185+
m_msgQueue_Query->Input_NoCopy(RequestType::E_ReqUserLoginField, this, nullptr, 0, 0,
186+
pBody, sizeof(CThostFtdcReqUserLoginField), nullptr, 0, nullptr, 0);
184187
}
185188

186189
int CMdUserApi::_ReqUserLogin(char type, void* pApi1, void* pApi2, double double1, double double2, void* ptr1, int size1, void* ptr2, int size2, void* ptr3, int size3)
187190
{
188-
m_msgQueue->Input(ResponeType::OnConnectionStatus, m_msgQueue, this, ConnectionStatus::Logining, 0, nullptr, 0, nullptr, 0, nullptr, 0);
191+
m_msgQueue->Input_NoCopy(ResponeType::OnConnectionStatus, m_msgQueue, this, ConnectionStatus::Logining, 0, nullptr, 0, nullptr, 0, nullptr, 0);
189192
return m_pApi->ReqUserLogin((CThostFtdcReqUserLoginField*)ptr1, ++m_lRequestID);
190193
}
191194

@@ -209,7 +212,7 @@ void CMdUserApi::Disconnect()
209212

210213
// 全清理,只留最后一个
211214
m_msgQueue->Clear();
212-
m_msgQueue->Input(ResponeType::OnConnectionStatus, m_msgQueue, this, ConnectionStatus::Disconnected, 0, nullptr, 0, nullptr, 0, nullptr, 0);
215+
m_msgQueue->Input_NoCopy(ResponeType::OnConnectionStatus, m_msgQueue, this, ConnectionStatus::Disconnected, 0, nullptr, 0, nullptr, 0, nullptr, 0);
213216
// 主动触发
214217
m_msgQueue->Process();
215218
}
@@ -376,36 +379,36 @@ void CMdUserApi::UnsubscribeQuote(const string& szInstrumentIDs, const string& s
376379

377380
void CMdUserApi::OnFrontConnected()
378381
{
379-
m_msgQueue->Input(ResponeType::OnConnectionStatus, m_msgQueue, this, ConnectionStatus::Connected, 0, nullptr, 0, nullptr, 0, nullptr, 0);
382+
m_msgQueue->Input_NoCopy(ResponeType::OnConnectionStatus, m_msgQueue, this, ConnectionStatus::Connected, 0, nullptr, 0, nullptr, 0, nullptr, 0);
380383

381384
//连接成功后自动请求登录
382385
ReqUserLogin();
383386
}
384387

385388
void CMdUserApi::OnFrontDisconnected(int nReason)
386389
{
387-
RspUserLoginField field = { 0 };
390+
RspUserLoginField* pField = (RspUserLoginField*)m_msgQueue->new_block(sizeof(RspUserLoginField));
388391
//连接失败返回的信息是拼接而成,主要是为了统一输出
389-
field.ErrorID = nReason;
390-
GetOnFrontDisconnectedMsg(nReason, field.ErrorMsg);
392+
pField->ErrorID = nReason;
393+
GetOnFrontDisconnectedMsg(nReason, pField->ErrorMsg);
391394

392-
m_msgQueue->Input(ResponeType::OnConnectionStatus, m_msgQueue, this, ConnectionStatus::Disconnected, 0, &field, sizeof(RspUserLoginField), nullptr, 0, nullptr, 0);
395+
m_msgQueue->Input_NoCopy(ResponeType::OnConnectionStatus, m_msgQueue, this, ConnectionStatus::Disconnected, 0, pField, sizeof(RspUserLoginField), nullptr, 0, nullptr, 0);
393396
}
394397

395398
void CMdUserApi::OnRspUserLogin(CThostFtdcRspUserLoginField *pRspUserLogin, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
396399
{
397-
RspUserLoginField field = { 0 };
400+
RspUserLoginField* pField = (RspUserLoginField*)m_msgQueue->new_block(sizeof(RspUserLoginField));
398401

399402
if (!IsErrorRspInfo(pRspInfo)
400403
&&pRspUserLogin)
401404
{
402405
GetExchangeTime(pRspUserLogin->TradingDay, nullptr, pRspUserLogin->LoginTime,
403-
&field.TradingDay, nullptr, &field.LoginTime, nullptr);
406+
&pField->TradingDay, nullptr, &pField->LoginTime, nullptr);
404407

405-
sprintf(field.SessionID, "%d:%d", pRspUserLogin->FrontID, pRspUserLogin->SessionID);
408+
sprintf(pField->SessionID, "%d:%d", pRspUserLogin->FrontID, pRspUserLogin->SessionID);
406409

407-
m_msgQueue->Input(ResponeType::OnConnectionStatus, m_msgQueue, this, ConnectionStatus::Logined, 0, &field, sizeof(RspUserLoginField), nullptr, 0, nullptr, 0);
408-
m_msgQueue->Input(ResponeType::OnConnectionStatus, m_msgQueue, this, ConnectionStatus::Done, 0, nullptr, 0, nullptr, 0, nullptr, 0);
410+
m_msgQueue->Input_NoCopy(ResponeType::OnConnectionStatus, m_msgQueue, this, ConnectionStatus::Logined, 0, pField, sizeof(RspUserLoginField), nullptr, 0, nullptr, 0);
411+
m_msgQueue->Input_NoCopy(ResponeType::OnConnectionStatus, m_msgQueue, this, ConnectionStatus::Done, 0, nullptr, 0, nullptr, 0, nullptr, 0);
409412

410413
//有可能断线了,本处是断线重连后重新订阅
411414
set<string> mapOld = m_setInstrumentIDs;//记下上次订阅的合约
@@ -418,10 +421,10 @@ void CMdUserApi::OnRspUserLogin(CThostFtdcRspUserLoginField *pRspUserLogin, CTho
418421
}
419422
else
420423
{
421-
field.ErrorID = pRspInfo->ErrorID;
422-
strncpy(field.ErrorMsg, pRspInfo->ErrorMsg, sizeof(ErrorMsgType));
424+
pField->ErrorID = pRspInfo->ErrorID;
425+
strncpy(pField->ErrorMsg, pRspInfo->ErrorMsg, sizeof(ErrorMsgType));
423426

424-
m_msgQueue->Input(ResponeType::OnConnectionStatus, m_msgQueue, this, ConnectionStatus::Disconnected, 0, &field, sizeof(RspUserLoginField), nullptr, 0, nullptr, 0);
427+
m_msgQueue->Input_NoCopy(ResponeType::OnConnectionStatus, m_msgQueue, this, ConnectionStatus::Disconnected, 0, pField, sizeof(RspUserLoginField), nullptr, 0, nullptr, 0);
425428
}
426429
}
427430

@@ -457,68 +460,72 @@ void CMdUserApi::OnRspUnSubMarketData(CThostFtdcSpecificInstrumentField *pSpecif
457460
//行情回调,得保证此函数尽快返回
458461
void CMdUserApi::OnRtnDepthMarketData(CThostFtdcDepthMarketDataField *pDepthMarketData)
459462
{
460-
// 测试平台穿越速度,用完后需要注释掉
461-
//WriteLog("CTP:OnRtnDepthMarketData:%s %f %s.%03d", pDepthMarketData->InstrumentID, pDepthMarketData->LastPrice, pDepthMarketData->UpdateTime, pDepthMarketData->UpdateMillisec);
463+
//for (int i = 0; i < 50; ++i)
464+
//{
465+
// // 测试平台穿越速度,用完后需要注释掉
466+
// WriteLog("CTP:OnRtnDepthMarketData:%s %f %s.%03d", pDepthMarketData->InstrumentID, pDepthMarketData->LastPrice, pDepthMarketData->UpdateTime, pDepthMarketData->UpdateMillisec);
462467

463-
DepthMarketDataField field = { 0 };
464-
strcpy(field.InstrumentID, pDepthMarketData->InstrumentID);
465-
strcpy(field.ExchangeID, pDepthMarketData->ExchangeID);
468+
DepthMarketDataField* pField = (DepthMarketDataField*)m_msgQueue->new_block(sizeof(DepthMarketDataField));
466469

467-
sprintf(field.Symbol, "%s.%s", field.InstrumentID, field.ExchangeID);
470+
strcpy(pField->InstrumentID, pDepthMarketData->InstrumentID);
471+
strcpy(pField->ExchangeID, pDepthMarketData->ExchangeID);
468472

469-
//TODO:CTP大连没有ActionDay,所以API中是将TradingDay填到了这里,所以这里这种用法可能会出错,要测
470-
GetExchangeTime(pDepthMarketData->TradingDay, pDepthMarketData->ActionDay, pDepthMarketData->UpdateTime
471-
, &field.TradingDay, &field.ActionDay, &field.UpdateTime, &field.UpdateMillisec);
473+
sprintf(pField->Symbol, "%s.%s", pField->InstrumentID, pField->ExchangeID);
472474

473-
field.UpdateMillisec = pDepthMarketData->UpdateMillisec;
475+
//TODO:CTP大连没有ActionDay,所以API中是将TradingDay填到了这里,所以这里这种用法可能会出错,要测
476+
GetExchangeTime(pDepthMarketData->TradingDay, pDepthMarketData->ActionDay, pDepthMarketData->UpdateTime
477+
, &pField->TradingDay, &pField->ActionDay, &pField->UpdateTime, &pField->UpdateMillisec);
474478

475-
field.LastPrice = pDepthMarketData->LastPrice;
476-
field.Volume = pDepthMarketData->Volume;
477-
field.Turnover = pDepthMarketData->Turnover;
478-
field.OpenInterest = pDepthMarketData->OpenInterest;
479-
field.AveragePrice = pDepthMarketData->AveragePrice;
479+
pField->UpdateMillisec = pDepthMarketData->UpdateMillisec;
480480

481-
field.OpenPrice = pDepthMarketData->OpenPrice;
482-
field.HighestPrice = pDepthMarketData->HighestPrice;
483-
field.LowestPrice = pDepthMarketData->LowestPrice;
484-
field.ClosePrice = pDepthMarketData->ClosePrice != DBL_MAX ? pDepthMarketData->ClosePrice : 0;
485-
field.SettlementPrice = pDepthMarketData->SettlementPrice;
481+
pField->LastPrice = pDepthMarketData->LastPrice;
482+
pField->Volume = pDepthMarketData->Volume;
483+
pField->Turnover = pDepthMarketData->Turnover;
484+
pField->OpenInterest = pDepthMarketData->OpenInterest;
485+
pField->AveragePrice = pDepthMarketData->AveragePrice;
486486

487-
field.UpperLimitPrice = pDepthMarketData->UpperLimitPrice;
488-
field.LowerLimitPrice = pDepthMarketData->LowerLimitPrice;
489-
field.PreClosePrice = pDepthMarketData->PreClosePrice;
490-
field.PreSettlementPrice = pDepthMarketData->PreSettlementPrice;
491-
field.PreOpenInterest = pDepthMarketData->PreOpenInterest;
487+
pField->OpenPrice = pDepthMarketData->OpenPrice;
488+
pField->HighestPrice = pDepthMarketData->HighestPrice;
489+
pField->LowestPrice = pDepthMarketData->LowestPrice;
490+
pField->ClosePrice = pDepthMarketData->ClosePrice != DBL_MAX ? pDepthMarketData->ClosePrice : 0;
491+
pField->SettlementPrice = pDepthMarketData->SettlementPrice;
492492

493-
field.BidPrice1 = pDepthMarketData->BidPrice1;
494-
field.BidVolume1 = pDepthMarketData->BidVolume1;
495-
field.AskPrice1 = pDepthMarketData->AskPrice1;
496-
field.AskVolume1 = pDepthMarketData->AskVolume1;
493+
pField->UpperLimitPrice = pDepthMarketData->UpperLimitPrice;
494+
pField->LowerLimitPrice = pDepthMarketData->LowerLimitPrice;
495+
pField->PreClosePrice = pDepthMarketData->PreClosePrice;
496+
pField->PreSettlementPrice = pDepthMarketData->PreSettlementPrice;
497+
pField->PreOpenInterest = pDepthMarketData->PreOpenInterest;
497498

498-
if (pDepthMarketData->BidPrice2 != DBL_MAX || pDepthMarketData->AskPrice2 != DBL_MAX)
499-
{
500-
field.BidPrice2 = pDepthMarketData->BidPrice2;
501-
field.BidVolume2 = pDepthMarketData->BidVolume2;
502-
field.AskPrice2 = pDepthMarketData->AskPrice2;
503-
field.AskVolume2 = pDepthMarketData->AskVolume2;
504-
505-
field.BidPrice3 = pDepthMarketData->BidPrice3;
506-
field.BidVolume3 = pDepthMarketData->BidVolume3;
507-
field.AskPrice3 = pDepthMarketData->AskPrice3;
508-
field.AskVolume3 = pDepthMarketData->AskVolume3;
509-
510-
field.BidPrice4 = pDepthMarketData->BidPrice4;
511-
field.BidVolume4 = pDepthMarketData->BidVolume4;
512-
field.AskPrice4 = pDepthMarketData->AskPrice4;
513-
field.AskVolume4 = pDepthMarketData->AskVolume4;
514-
515-
field.BidPrice5 = pDepthMarketData->BidPrice5;
516-
field.BidVolume5 = pDepthMarketData->BidVolume5;
517-
field.AskPrice5 = pDepthMarketData->AskPrice5;
518-
field.AskVolume5 = pDepthMarketData->AskVolume5;
519-
}
520-
521-
m_msgQueue->Input(ResponeType::OnRtnDepthMarketData, m_msgQueue, this, 0, 0, &field, sizeof(DepthMarketDataField), nullptr, 0, nullptr, 0);
499+
pField->BidPrice1 = pDepthMarketData->BidPrice1;
500+
pField->BidVolume1 = pDepthMarketData->BidVolume1;
501+
pField->AskPrice1 = pDepthMarketData->AskPrice1;
502+
pField->AskVolume1 = pDepthMarketData->AskVolume1;
503+
504+
if (pDepthMarketData->BidPrice2 != DBL_MAX || pDepthMarketData->AskPrice2 != DBL_MAX)
505+
{
506+
pField->BidPrice2 = pDepthMarketData->BidPrice2;
507+
pField->BidVolume2 = pDepthMarketData->BidVolume2;
508+
pField->AskPrice2 = pDepthMarketData->AskPrice2;
509+
pField->AskVolume2 = pDepthMarketData->AskVolume2;
510+
511+
pField->BidPrice3 = pDepthMarketData->BidPrice3;
512+
pField->BidVolume3 = pDepthMarketData->BidVolume3;
513+
pField->AskPrice3 = pDepthMarketData->AskPrice3;
514+
pField->AskVolume3 = pDepthMarketData->AskVolume3;
515+
516+
pField->BidPrice4 = pDepthMarketData->BidPrice4;
517+
pField->BidVolume4 = pDepthMarketData->BidVolume4;
518+
pField->AskPrice4 = pDepthMarketData->AskPrice4;
519+
pField->AskVolume4 = pDepthMarketData->AskVolume4;
520+
521+
pField->BidPrice5 = pDepthMarketData->BidPrice5;
522+
pField->BidVolume5 = pDepthMarketData->BidVolume5;
523+
pField->AskPrice5 = pDepthMarketData->AskPrice5;
524+
pField->AskVolume5 = pDepthMarketData->AskVolume5;
525+
}
526+
527+
m_msgQueue->Input_NoCopy(ResponeType::OnRtnDepthMarketData, m_msgQueue, this, 0, 0, pField, sizeof(DepthMarketDataField), nullptr, 0, nullptr, 0);
528+
//}
522529
}
523530

524531
void CMdUserApi::OnRspSubForQuoteRsp(CThostFtdcSpecificInstrumentField *pSpecificInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
@@ -546,15 +553,15 @@ void CMdUserApi::OnRspUnSubForQuoteRsp(CThostFtdcSpecificInstrumentField *pSpeci
546553
void CMdUserApi::OnRtnForQuoteRsp(CThostFtdcForQuoteRspField *pForQuoteRsp)
547554
{
548555
// 上期技术的人说,上海中金走的交易接口,大商,郑商走行情,所以这个地方后期可能要改
549-
QuoteRequestField field = { 0 };
556+
QuoteRequestField* pField = (QuoteRequestField*)m_msgQueue->new_block(sizeof(QuoteRequestField));
550557

551-
strcpy(field.Symbol, pForQuoteRsp->InstrumentID);
552-
strcpy(field.InstrumentID, pForQuoteRsp->InstrumentID);
553-
strcpy(field.ExchangeID, pForQuoteRsp->ExchangeID);
554-
sprintf(field.Symbol, "%s.%s", field.InstrumentID, field.ExchangeID);
555-
strcpy(field.TradingDay, pForQuoteRsp->TradingDay);
556-
strcpy(field.QuoteID, pForQuoteRsp->ForQuoteSysID);
557-
strcpy(field.QuoteTime, pForQuoteRsp->ForQuoteTime);
558+
strcpy(pField->Symbol, pForQuoteRsp->InstrumentID);
559+
strcpy(pField->InstrumentID, pForQuoteRsp->InstrumentID);
560+
strcpy(pField->ExchangeID, pForQuoteRsp->ExchangeID);
561+
sprintf(pField->Symbol, "%s.%s", pField->InstrumentID, pField->ExchangeID);
562+
strcpy(pField->TradingDay, pForQuoteRsp->TradingDay);
563+
strcpy(pField->QuoteID, pForQuoteRsp->ForQuoteSysID);
564+
strcpy(pField->QuoteTime, pForQuoteRsp->ForQuoteTime);
558565

559-
m_msgQueue->Input(ResponeType::OnRtnQuoteRequest, m_msgQueue, this, 0, 0, &field, sizeof(QuoteRequestField), nullptr, 0, nullptr, 0);
566+
m_msgQueue->Input_NoCopy(ResponeType::OnRtnQuoteRequest, m_msgQueue, this, 0, 0, pField, sizeof(QuoteRequestField), nullptr, 0, nullptr, 0);
560567
}

0 commit comments

Comments
 (0)