@@ -66,7 +66,7 @@ void CMdUserApi::QueryInThread(char type, void* pApi1, void* pApi2, double doubl
66
66
}
67
67
else
68
68
{
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);
70
70
// 失败,按4的幂进行延时,但不超过1s
71
71
m_nSleep *= 4 ;
72
72
m_nSleep %= 1023 ;
@@ -103,11 +103,12 @@ bool CMdUserApi::IsErrorRspInfo(CThostFtdcRspInfoField *pRspInfo, int nRequestID
103
103
bool bRet = ((pRspInfo) && (pRspInfo->ErrorID != 0 ));
104
104
if (bRet)
105
105
{
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));
109
107
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 );
111
112
}
112
113
return bRet;
113
114
}
@@ -127,7 +128,7 @@ void CMdUserApi::Connect(const string& szPath,
127
128
memcpy (&m_ServerInfo, pServerInfo, sizeof (ServerInfoField));
128
129
memcpy (&m_UserInfo, pUserInfo, sizeof (UserInfoField));
129
130
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 ,
131
132
nullptr , 0 , nullptr , 0 , nullptr , 0 );
132
133
}
133
134
@@ -141,7 +142,7 @@ int CMdUserApi::_Init()
141
142
m_pApi = CThostFtdcMdApi::CreateFtdcMdApi (pszPath, m_ServerInfo.IsUsingUdp , m_ServerInfo.IsMulticast );
142
143
delete[] pszPath;
143
144
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 );
145
146
146
147
if (m_pApi)
147
148
{
@@ -165,27 +166,29 @@ int CMdUserApi::_Init()
165
166
166
167
// 初始化连接
167
168
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 );
169
170
}
170
171
171
172
return 0 ;
172
173
}
173
174
174
175
void CMdUserApi::ReqUserLogin ()
175
176
{
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));
177
180
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));
181
184
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 );
184
187
}
185
188
186
189
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)
187
190
{
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 );
189
192
return m_pApi->ReqUserLogin ((CThostFtdcReqUserLoginField*)ptr1, ++m_lRequestID);
190
193
}
191
194
@@ -209,7 +212,7 @@ void CMdUserApi::Disconnect()
209
212
210
213
// 全清理,只留最后一个
211
214
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 );
213
216
// 主动触发
214
217
m_msgQueue->Process ();
215
218
}
@@ -376,36 +379,36 @@ void CMdUserApi::UnsubscribeQuote(const string& szInstrumentIDs, const string& s
376
379
377
380
void CMdUserApi::OnFrontConnected ()
378
381
{
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 );
380
383
381
384
// 连接成功后自动请求登录
382
385
ReqUserLogin ();
383
386
}
384
387
385
388
void CMdUserApi::OnFrontDisconnected (int nReason)
386
389
{
387
- RspUserLoginField field = { 0 } ;
390
+ RspUserLoginField* pField = (RspUserLoginField*)m_msgQueue-> new_block ( sizeof (RspUserLoginField)) ;
388
391
// 连接失败返回的信息是拼接而成,主要是为了统一输出
389
- field. ErrorID = nReason;
390
- GetOnFrontDisconnectedMsg (nReason, field. ErrorMsg );
392
+ pField-> ErrorID = nReason;
393
+ GetOnFrontDisconnectedMsg (nReason, pField-> ErrorMsg );
391
394
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 );
393
396
}
394
397
395
398
void CMdUserApi::OnRspUserLogin (CThostFtdcRspUserLoginField *pRspUserLogin, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
396
399
{
397
- RspUserLoginField field = { 0 } ;
400
+ RspUserLoginField* pField = (RspUserLoginField*)m_msgQueue-> new_block ( sizeof (RspUserLoginField)) ;
398
401
399
402
if (!IsErrorRspInfo (pRspInfo)
400
403
&&pRspUserLogin)
401
404
{
402
405
GetExchangeTime (pRspUserLogin->TradingDay , nullptr , pRspUserLogin->LoginTime ,
403
- &field. TradingDay , nullptr , &field. LoginTime , nullptr );
406
+ &pField-> TradingDay , nullptr , &pField-> LoginTime , nullptr );
404
407
405
- sprintf (field. SessionID , " %d:%d" , pRspUserLogin->FrontID , pRspUserLogin->SessionID );
408
+ sprintf (pField-> SessionID , " %d:%d" , pRspUserLogin->FrontID , pRspUserLogin->SessionID );
406
409
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 );
409
412
410
413
// 有可能断线了,本处是断线重连后重新订阅
411
414
set<string> mapOld = m_setInstrumentIDs;// 记下上次订阅的合约
@@ -418,10 +421,10 @@ void CMdUserApi::OnRspUserLogin(CThostFtdcRspUserLoginField *pRspUserLogin, CTho
418
421
}
419
422
else
420
423
{
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));
423
426
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 );
425
428
}
426
429
}
427
430
@@ -457,68 +460,72 @@ void CMdUserApi::OnRspUnSubMarketData(CThostFtdcSpecificInstrumentField *pSpecif
457
460
// 行情回调,得保证此函数尽快返回
458
461
void CMdUserApi::OnRtnDepthMarketData (CThostFtdcDepthMarketDataField *pDepthMarketData)
459
462
{
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);
462
467
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));
466
469
467
- sprintf (field.Symbol , " %s.%s" , field.InstrumentID , field.ExchangeID );
470
+ strcpy (pField->InstrumentID , pDepthMarketData->InstrumentID );
471
+ strcpy (pField->ExchangeID , pDepthMarketData->ExchangeID );
468
472
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 );
472
474
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 );
474
478
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 ;
480
480
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 ;
486
486
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 ;
492
492
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 ;
497
498
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
+ // }
522
529
}
523
530
524
531
void CMdUserApi::OnRspSubForQuoteRsp (CThostFtdcSpecificInstrumentField *pSpecificInstrument, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
@@ -546,15 +553,15 @@ void CMdUserApi::OnRspUnSubForQuoteRsp(CThostFtdcSpecificInstrumentField *pSpeci
546
553
void CMdUserApi::OnRtnForQuoteRsp (CThostFtdcForQuoteRspField *pForQuoteRsp)
547
554
{
548
555
// 上期技术的人说,上海中金走的交易接口,大商,郑商走行情,所以这个地方后期可能要改
549
- QuoteRequestField field = { 0 } ;
556
+ QuoteRequestField* pField = (QuoteRequestField*)m_msgQueue-> new_block ( sizeof (QuoteRequestField)) ;
550
557
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 );
558
565
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 );
560
567
}
0 commit comments