From 3c80d7681b29fc4a29af62dc133f4d32208a2c49 Mon Sep 17 00:00:00 2001 From: gzadigo Date: Sun, 1 Nov 2015 13:43:53 +0800 Subject: [PATCH 1/5] Tongshi supports subscribe using regex string --- QuantBox_TongShi_Quote/MdUserApi.cpp | 37 ++++++++++++++++++---------- QuantBox_TongShi_Quote/MdUserApi.h | 8 +++--- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/QuantBox_TongShi_Quote/MdUserApi.cpp b/QuantBox_TongShi_Quote/MdUserApi.cpp index f7d8a96..9c7e6a2 100644 --- a/QuantBox_TongShi_Quote/MdUserApi.cpp +++ b/QuantBox_TongShi_Quote/MdUserApi.cpp @@ -21,6 +21,7 @@ #include #include +#include #include "resource.h" #include "DialogStockDrv.h" @@ -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; @@ -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; @@ -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)); @@ -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); diff --git a/QuantBox_TongShi_Quote/MdUserApi.h b/QuantBox_TongShi_Quote/MdUserApi.h index 9555c92..879ccbd 100644 --- a/QuantBox_TongShi_Quote/MdUserApi.h +++ b/QuantBox_TongShi_Quote/MdUserApi.h @@ -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(); @@ -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; From 076e223f86a35b9d77e5b18f88ba65437574ed48 Mon Sep 17 00:00:00 2001 From: gzadigo Date: Sun, 1 Nov 2015 15:35:01 +0800 Subject: [PATCH 2/5] instrument filter changed to map, and some spelling check --- QuantBox_TongShi_Quote/MdUserApi.cpp | 21 ++++++++++++--------- QuantBox_TongShi_Quote/MdUserApi.h | 15 ++++++++------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/QuantBox_TongShi_Quote/MdUserApi.cpp b/QuantBox_TongShi_Quote/MdUserApi.cpp index 9c7e6a2..0721873 100644 --- a/QuantBox_TongShi_Quote/MdUserApi.cpp +++ b/QuantBox_TongShi_Quote/MdUserApi.cpp @@ -85,7 +85,6 @@ 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; @@ -287,18 +286,21 @@ void CMdUserApi::Disconnect() } } -void CMdUserApi::Subscribe(const string& szInstrumentIDs, const string& szExchageID) +void CMdUserApi::Subscribe(const string& szInstrumentIDs, const string& szExchangeID) { if (nullptr == m_hThread) return; - m_Filter = szInstrumentIDs; + + set& instruments = m_DictSet[szExchangeID]; + instruments.insert(szInstrumentIDs); } -void CMdUserApi::Unsubscribe(const string& szInstrumentIDs, const string& szExchageID) +void CMdUserApi::Unsubscribe(const string& szInstrumentIDs, const string& szExchangeID) { if (nullptr == m_hThread) return; - m_Filter = "xxxxxx"; + set& instruments = m_DictSet[szExchangeID]; + instruments.erase(szInstrumentIDs); } void CMdUserApi::OnRspQryInstrument(DepthMarketDataNField* _pField,RCV_REPORT_STRUCTEx *pDepthMarketData, int index, int Count) @@ -338,10 +340,11 @@ void CMdUserApi::OnRspQryInstrument(DepthMarketDataNField* _pField,RCV_REPORT_ST bool CMdUserApi::FilterExchangeInstrument(WORD wMarket, string instrument) { - // 行情太多,需要过滤 - string ExhangeInstrument = instrument + "." + (wMarket==1 ? "SS" : "SZ"); - const std::regex pattern(m_Filter); - return std::regex_match(ExhangeInstrument, pattern); + // 这里我乱写一个,暂时不知道通视对市场的定义 + string szExchangeID = wMarket == 0 ? "SS" : "SZ"; + set& instruments = m_DictSet[szExchangeID]; + set::iterator it = instruments.find(instrument); + return it != instruments.end(); } //行情回调,得保证此函数尽快返回 diff --git a/QuantBox_TongShi_Quote/MdUserApi.h b/QuantBox_TongShi_Quote/MdUserApi.h index 879ccbd..9926ba4 100644 --- a/QuantBox_TongShi_Quote/MdUserApi.h +++ b/QuantBox_TongShi_Quote/MdUserApi.h @@ -19,6 +19,7 @@ #include #include #include +#include using namespace std; @@ -56,11 +57,11 @@ 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& szExchangeID); + void Unsubscribe(const string& szInstrumentIDs, const string& szExchangeID); - //void SubscribeQuote(const string& szInstrumentIDs, const string& szExchageID); - //void UnsubscribeQuote(const string& szInstrumentIDs, const string& szExchageID); + //void SubscribeQuote(const string& szInstrumentIDs, const string& szExchangeID); + //void UnsubscribeQuote(const string& szInstrumentIDs, const string& szExchangeID); private: bool FilterExchangeInstrument(WORD wMarket, string instrument); @@ -84,8 +85,8 @@ class CMdUserApi //int _ReqUserLogin(char type, void* pApi1, void* pApi2, double double1, double double2, void* ptr1, int size1, void* ptr2, int size2, void* ptr3, int size3); // - void Subscribe(const set& instrumentIDs, const string& szExchageID); - void SubscribeQuote(const set& instrumentIDs, const string& szExchageID); + void Subscribe(const set& instrumentIDs, const string& szExchangeID); + void SubscribeQuote(const set& instrumentIDs, const string& szExchangeID); //virtual void OnFrontConnected(); //virtual void OnFrontDisconnected(int nReason); @@ -121,7 +122,7 @@ class CMdUserApi UserInfoField m_UserInfo; int m_nSleep; - string m_Filter; //Լ + map> m_DictSet; //Լ CMsgQueue* m_msgQueue; //Ϣָ //CMsgQueue* m_msgQueue_Query; From c68d4ba9e369ead1d1cb60fec123879f72972a20 Mon Sep 17 00:00:00 2001 From: gzadigo Date: Tue, 3 Nov 2015 06:55:47 +0800 Subject: [PATCH 3/5] suggest new subscribe interface --- QuantBox_TongShi_Quote/MdUserApi.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/QuantBox_TongShi_Quote/MdUserApi.h b/QuantBox_TongShi_Quote/MdUserApi.h index 9926ba4..598e76f 100644 --- a/QuantBox_TongShi_Quote/MdUserApi.h +++ b/QuantBox_TongShi_Quote/MdUserApi.h @@ -57,6 +57,15 @@ class CMdUserApi void InitDriver(HWND hWnd, UINT Msg); void QuitDriver(); + + // ¶Ľӿ +#define Subscibe_Regex = 0x00000001, // ַʽ +#define Subscibe_Last = 0x00000002, // һʱײӦðǰеĶ()ۺһ𷢳 +#define Subscibe_All = 0x00000004, // ȫģ ʱInstrumentIDָ + + void Subscribe(const string& InstrumentID, int Flags); + void Unsubscribe(const string& InstrumentID, int Flags); + void Subscribe(const string& szInstrumentIDs, const string& szExchangeID); void Unsubscribe(const string& szInstrumentIDs, const string& szExchangeID); From f9656f60c4978344c7c7d4ac0c10688d2b132fbc Mon Sep 17 00:00:00 2001 From: gzadigo Date: Tue, 3 Nov 2015 06:57:14 +0800 Subject: [PATCH 4/5] Revert "suggest new subscribe interface" This reverts commit c68d4ba9e369ead1d1cb60fec123879f72972a20. --- QuantBox_TongShi_Quote/MdUserApi.h | 9 --------- 1 file changed, 9 deletions(-) diff --git a/QuantBox_TongShi_Quote/MdUserApi.h b/QuantBox_TongShi_Quote/MdUserApi.h index 598e76f..9926ba4 100644 --- a/QuantBox_TongShi_Quote/MdUserApi.h +++ b/QuantBox_TongShi_Quote/MdUserApi.h @@ -57,15 +57,6 @@ class CMdUserApi void InitDriver(HWND hWnd, UINT Msg); void QuitDriver(); - - // ¶Ľӿ -#define Subscibe_Regex = 0x00000001, // ַʽ -#define Subscibe_Last = 0x00000002, // һʱײӦðǰеĶ()ۺһ𷢳 -#define Subscibe_All = 0x00000004, // ȫģ ʱInstrumentIDָ - - void Subscribe(const string& InstrumentID, int Flags); - void Unsubscribe(const string& InstrumentID, int Flags); - void Subscribe(const string& szInstrumentIDs, const string& szExchangeID); void Unsubscribe(const string& szInstrumentIDs, const string& szExchangeID); From b2992d67894e05d141b56ce1b3bd1263f733cbf1 Mon Sep 17 00:00:00 2001 From: gzadigo Date: Tue, 3 Nov 2015 07:05:29 +0800 Subject: [PATCH 5/5] subscribe interface suggest --- QuantBox_TongShi_Quote/MdUserApi.h | 9 +++++++++ QuantBox_TongShi_Quote/suggest.txt | 7 +++++++ 2 files changed, 16 insertions(+) create mode 100644 QuantBox_TongShi_Quote/suggest.txt diff --git a/QuantBox_TongShi_Quote/MdUserApi.h b/QuantBox_TongShi_Quote/MdUserApi.h index 9926ba4..598e76f 100644 --- a/QuantBox_TongShi_Quote/MdUserApi.h +++ b/QuantBox_TongShi_Quote/MdUserApi.h @@ -57,6 +57,15 @@ class CMdUserApi void InitDriver(HWND hWnd, UINT Msg); void QuitDriver(); + + // ¶Ľӿ +#define Subscibe_Regex = 0x00000001, // ַʽ +#define Subscibe_Last = 0x00000002, // һʱײӦðǰеĶ()ۺһ𷢳 +#define Subscibe_All = 0x00000004, // ȫģ ʱInstrumentIDָ + + void Subscribe(const string& InstrumentID, int Flags); + void Unsubscribe(const string& InstrumentID, int Flags); + void Subscribe(const string& szInstrumentIDs, const string& szExchangeID); void Unsubscribe(const string& szInstrumentIDs, const string& szExchangeID); diff --git a/QuantBox_TongShi_Quote/suggest.txt b/QuantBox_TongShi_Quote/suggest.txt new file mode 100644 index 0000000..19003e6 --- /dev/null +++ b/QuantBox_TongShi_Quote/suggest.txt @@ -0,0 +1,7 @@ + // ¶Ľӿ +#define Subscibe_Regex = 0x00000001, // ַʽ +#define Subscibe_Last = 0x00000002, // һʱײӦðǰеĶ()ۺһ𷢳 +#define Subscibe_All = 0x00000004, // ȫģ ʱInstrumentIDָ + + void Subscribe(const string& InstrumentID, int Flags); + void Unsubscribe(const string& InstrumentID, int Flags); \ No newline at end of file