资源简介
CTP接口,c/C#/jAVA/MATLAB
代码片段和文件信息
#include “StdAfx.h“
#include “CTPMsgQueue.h“
void CCTPMsgQueue::Clear()
{
SMsgItem* pItem = NULL;
//清空队列
while(m_queue_TD.dequeue(pItem))
{
delete pItem;
}
while(m_queue_MD.dequeue(pItem))
{
delete pItem;
}
}
bool CCTPMsgQueue::Process()
{
SMsgItem* pItem = NULL;
if(m_queue_TD.dequeue(pItem))
{
_Output_TD(pItem);
delete pItem;
return true;
}
else if(m_queue_MD.dequeue(pItem))
{
_Output_MD(pItem);
delete pItem;
return true;
}
return false;
}
void CCTPMsgQueue::StartThread()
{
if (NULL == m_hThread)
{
m_bRunning = true;
m_hThread = CreateThread(NULL0ProcessThreadthisCREATE_SUSPENDEDNULL);
SetThreadPriority(m_hThreadTHREAD_PRIORITY_HIGHEST);
ResumeThread(m_hThread);
}
}
void CCTPMsgQueue::StopThread()
{
//停止线程
m_bRunning = false;
// 线程可能正在Wait,让它结束等待
SetEvent(m_hEvent);
WaitForSingleobject(m_hThreadINFINITE);
CloseHandle(m_hThread);
m_hThread = NULL;
}
DWORD WINAPI ProcessThread(LPVOID lpParam)
{
CCTPMsgQueue* pMsgQueue = reinterpret_cast(lpParam);
if (pMsgQueue)
pMsgQueue->RunInThread();
return 0;
}
void CCTPMsgQueue::RunInThread()
{
while (m_bRunning)
{
if(Process())
{
}
else
{
//挂起,等事件到来
WaitForSingleobject(m_hEventINFINITE);
}
}
//清理线程
CloseHandle(m_hThread);
m_hThread = NULL;
m_bRunning = false;
}
void CCTPMsgQueue::_Input_MD(SMsgItem* pMsgItem)
{
m_queue_MD.enqueue(pMsgItem);
SetEvent(m_hEvent);
}
void CCTPMsgQueue::_Input_TD(SMsgItem* pMsgItem)
{
m_queue_TD.enqueue(pMsgItem);
SetEvent(m_hEvent);
}
void CCTPMsgQueue::_Output_MD(SMsgItem* pMsgItem)
{
// 行情压入此,本来询价也应当压入此,但想想询价优先级高,所以不放这
Output_OnRtnDepthMarketData(pMsgItem);
}
void CCTPMsgQueue::_Output_TD(SMsgItem* pMsgItem)
{
//OutputDebugStringA(“CTP2“);
//内部调用,不判断指针是否有效
switch(pMsgItem->type)
{
case E_fnOnConnect:
Output_OnConnect(pMsgItem);
break;
case E_fnOnDisconnect:
Output_OnDisconnect(pMsgItem);
break;
case E_fnOnErrRtnOrderAction:
Output_OnErrRtnOrderAction(pMsgItem);
break;
case E_fnOnErrRtnOrderInsert:
Output_OnErrRtnOrderInsert(pMsgItem);
break;
case E_fnOnErrRtnQuoteAction:
Output_OnErrRtnQuoteAction(pMsgItem);
break;
case E_fnOnErrRtnQuoteInsert:
Output_OnErrRtnQuoteInsert(pMsgItem);
break;
case E_fnOnRspError:
Output_OnRspError(pMsgItem);
break;
case E_fnOnRspOrderAction:
Output_OnRspOrderAction(pMsgItem);
break;
case E_fnOnRspOrderInsert:
Output_OnRspOrderInsert(pMsgItem);
break;
case E_fnOnRspQuoteAction:
Output_OnRspQuoteAction(pMsgItem);
break;
case E_fnOnRspQuoteInsert:
Output_OnRspQuoteInsert(pMsgItem);
break;
case E_fnOnRspQryDepthMarketData:
Output_OnRspQryDepthMarketData(pMsgItem);
break;
case E_fnOnRspQryInstrument:
Output_OnRspQryInstrument(pMsgItem);
break;
case E_fnOnRspQryInstrumentCommissionRate:
Output_OnRspQryInstrumentCommissionRate(pMsgItem);
break;
case E_fnOnRspQryInstrumentMarginRate:
Output_OnRspQryInstrumentMarginRate(pMsgItem);
break;
case E_fnOnRspQryI
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2014-10-21 06:22 CTP-master\
目录 0 2014-10-21 06:22 CTP-master\C-CTP\
文件 1501 2014-10-21 06:22 CTP-master\C-CTP\BSD-LICENSE.txt
文件 7015 2014-10-21 06:22 CTP-master\C-CTP\README.md
目录 0 2014-10-21 06:22 CTP-master\C-CTP\bin\
文件 55296 2014-10-21 06:22 CTP-master\C-CTP\bin\QuantBox.C2CTP.dll
文件 16086 2014-10-21 06:22 CTP-master\C-CTP\bin\QuantBox.C2CTP.lib
目录 0 2014-10-21 06:22 CTP-master\C-CTP\src\
文件 909 2014-10-21 06:22 CTP-master\C-CTP\src\QuantBox.C2CTP.sln
目录 0 2014-10-21 06:22 CTP-master\C-CTP\src\QuantBox.C2CTP\
文件 17307 2014-10-21 06:22 CTP-master\C-CTP\src\QuantBox.C2CTP\CTPMsgQueue.cpp
文件 16400 2014-10-21 06:22 CTP-master\C-CTP\src\QuantBox.C2CTP\CTPMsgQueue.h
文件 10209 2014-10-21 06:22 CTP-master\C-CTP\src\QuantBox.C2CTP\MdUserApi.cpp
文件 2790 2014-10-21 06:22 CTP-master\C-CTP\src\QuantBox.C2CTP\MdUserApi.h
文件 13031 2014-10-21 06:22 CTP-master\C-CTP\src\QuantBox.C2CTP\QuantBox.C2CTP.cpp
文件 12852 2014-10-21 06:22 CTP-master\C-CTP\src\QuantBox.C2CTP\QuantBox.C2CTP.h
文件 4542 2014-10-21 06:22 CTP-master\C-CTP\src\QuantBox.C2CTP\QuantBox.C2CTP.rc
文件 6186 2014-10-21 06:22 CTP-master\C-CTP\src\QuantBox.C2CTP\QuantBox.C2CTP.vcxproj
文件 3626 2014-10-21 06:22 CTP-master\C-CTP\src\QuantBox.C2CTP\QuantBox.C2CTP.vcxproj.filters
文件 1580 2014-10-21 06:22 CTP-master\C-CTP\src\QuantBox.C2CTP\ReadMe.txt
文件 27218 2014-10-21 06:22 CTP-master\C-CTP\src\QuantBox.C2CTP\TraderApi.cpp
文件 9168 2014-10-21 06:22 CTP-master\C-CTP\src\QuantBox.C2CTP\TraderApi.h
文件 389 2014-10-21 06:22 CTP-master\C-CTP\src\QuantBox.C2CTP\dllmain.cpp
目录 0 2014-10-21 06:22 CTP-master\C-CTP\src\QuantBox.C2CTP\include\
目录 0 2014-10-21 06:22 CTP-master\C-CTP\src\QuantBox.C2CTP\include\CTP\
文件 5310 2014-10-21 06:22 CTP-master\C-CTP\src\QuantBox.C2CTP\include\CTP\ThostFtdcMdApi.h
文件 27435 2014-10-21 06:22 CTP-master\C-CTP\src\QuantBox.C2CTP\include\CTP\ThostFtdcTraderApi.h
文件 234760 2014-10-21 06:22 CTP-master\C-CTP\src\QuantBox.C2CTP\include\CTP\ThostFtdcUserApiDataType.h
文件 177967 2014-10-21 06:22 CTP-master\C-CTP\src\QuantBox.C2CTP\include\CTP\ThostFtdcUserApiStruct.h
文件 184 2014-10-21 06:22 CTP-master\C-CTP\src\QuantBox.C2CTP\include\CTP\error.dtd
文件 14336 2014-10-21 06:22 CTP-master\C-CTP\src\QuantBox.C2CTP\include\CTP\error.xm
............此处省略102个文件信息
评论
共有 条评论