Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Tongshi supports subscribe using regex string
  • Loading branch information
gzadigo committed Nov 1, 2015
commit 3c80d7681b29fc4a29af62dc133f4d32208a2c49
37 changes: 24 additions & 13 deletions QuantBox_TongShi_Quote/MdUserApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <mutex>
#include <vector>
#include <regex>

#include "resource.h"
#include "DialogStockDrv.h"
Expand All @@ -47,14 +48,10 @@ LRESULT CMdUserApi::_OnMsg(WPARAM wParam, LPARAM lParam)
RCV_REPORT_STRUCTEx* pFirst = &pHeader->m_pReport[0];
RCV_REPORT_STRUCTEx* pLast = &pHeader->m_pReport[pHeader->m_nPacketNum - 1];

// 前后都不合要求才跳过
if (FilterExchangeInstrument(pFirst->m_wMarket, 0) || FilterExchangeInstrument(pLast->m_wMarket, 0))
for (i = 0; i < pHeader->m_nPacketNum; i++)
{
for (i = 0; i < pHeader->m_nPacketNum; i++)
{
// 数据处理
OnRtnDepthMarketData(&pHeader->m_pReport[i], i, pHeader->m_nPacketNum);
}
// 数据处理
OnRtnDepthMarketData(&pHeader->m_pReport[i], i, pHeader->m_nPacketNum);
}
}
break;
Expand Down Expand Up @@ -88,6 +85,7 @@ void* __stdcall Query(char type, void* pApi1, void* pApi2, double double1, doubl

CMdUserApi::CMdUserApi(void)
{
m_Filter = "xxxxxx"; // 这样的字符串不可能匹配
//m_pApi = nullptr;
m_lRequestID = 0;
m_nSleep = 1;
Expand Down Expand Up @@ -289,6 +287,20 @@ void CMdUserApi::Disconnect()
}
}

void CMdUserApi::Subscribe(const string& szInstrumentIDs, const string& szExchageID)
{
if (nullptr == m_hThread)
return;
m_Filter = szInstrumentIDs;
}

void CMdUserApi::Unsubscribe(const string& szInstrumentIDs, const string& szExchageID)
{
if (nullptr == m_hThread)
return;
m_Filter = "xxxxxx";
}

void CMdUserApi::OnRspQryInstrument(DepthMarketDataNField* _pField,RCV_REPORT_STRUCTEx *pDepthMarketData, int index, int Count)
{
InstrumentField* pField = (InstrumentField*)m_msgQueue->new_block(sizeof(InstrumentField));
Expand Down Expand Up @@ -324,20 +336,19 @@ void CMdUserApi::OnRspQryInstrument(DepthMarketDataNField* _pField,RCV_REPORT_ST
}


bool CMdUserApi::FilterExchangeInstrument(WORD wMarket, int instrument)
bool CMdUserApi::FilterExchangeInstrument(WORD wMarket, string instrument)
{
// 行情太多,需要过滤
return (bool)m_msgQueue->Input_Output(ResponeType::OnFilterSubscribe, m_msgQueue, m_pClass, Market_2_ExchangeType(wMarket), 0, nullptr, instrument, nullptr, 0, nullptr, 0);
string ExhangeInstrument = instrument + "." + (wMarket==1 ? "SS" : "SZ");
const std::regex pattern(m_Filter);
return std::regex_match(ExhangeInstrument, pattern);
}

//行情回调,得保证此函数尽快返回
void CMdUserApi::OnRtnDepthMarketData(RCV_REPORT_STRUCTEx *pDepthMarketData, int index, int Count)
{
// 把不想要的过滤了,加快速度
if (!FilterExchangeInstrument(
pDepthMarketData->m_wMarket,
atoi(pDepthMarketData->m_szLabel))
)
if (!FilterExchangeInstrument(pDepthMarketData->m_wMarket, pDepthMarketData->m_szLabel))
return;

DepthMarketDataNField* pField = (DepthMarketDataNField*)m_msgQueue->new_block(sizeof(DepthMarketDataNField)+sizeof(DepthField)* 10);
Expand Down
8 changes: 5 additions & 3 deletions QuantBox_TongShi_Quote/MdUserApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ class CMdUserApi

void InitDriver(HWND hWnd, UINT Msg);
void QuitDriver();
//void Subscribe(const string& szInstrumentIDs, const string& szExchageID);
//void Unsubscribe(const string& szInstrumentIDs, const string& szExchageID);
void Subscribe(const string& szInstrumentIDs, const string& szExchageID);
void Unsubscribe(const string& szInstrumentIDs, const string& szExchageID);

//void SubscribeQuote(const string& szInstrumentIDs, const string& szExchageID);
//void UnsubscribeQuote(const string& szInstrumentIDs, const string& szExchageID);
private:
bool FilterExchangeInstrument(WORD wMarket, int instrument);
bool FilterExchangeInstrument(WORD wMarket, string instrument);

void StartThread();
void StopThread();
Expand Down Expand Up @@ -121,6 +121,8 @@ class CMdUserApi
UserInfoField m_UserInfo;
int m_nSleep;

string m_Filter; //��Լ������

CMsgQueue* m_msgQueue; //��Ϣ����ָ��
//CMsgQueue* m_msgQueue_Query;
void* m_pClass;
Expand Down