Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tongshi supports subscribe using regex string #26

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
42 changes: 28 additions & 14 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 @@ -289,6 +286,23 @@ void CMdUserApi::Disconnect()
}
}

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

set<string>& instruments = m_DictSet[szExchangeID];
instruments.insert(szInstrumentIDs);
}

void CMdUserApi::Unsubscribe(const string& szInstrumentIDs, const string& szExchangeID)
{
if (nullptr == m_hThread)
return;
set<string>& instruments = m_DictSet[szExchangeID];
instruments.erase(szInstrumentIDs);
}

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 +338,20 @@ 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 szExchangeID = wMarket == 0 ? "SS" : "SZ";
set<string>& instruments = m_DictSet[szExchangeID];
set<string>::iterator it = instruments.find(instrument);
return it != instruments.end();
}

//行情回调,得保证此函数尽快返回
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
26 changes: 19 additions & 7 deletions QuantBox_TongShi_Quote/MdUserApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <atomic>
#include <mutex>
#include <thread>
#include <map>

using namespace std;

Expand Down Expand Up @@ -56,13 +57,22 @@ 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 SubscribeQuote(const string& szInstrumentIDs, const string& szExchageID);
//void UnsubscribeQuote(const string& szInstrumentIDs, const string& szExchageID);
// ������¶��Ľӿ�
#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);

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

void StartThread();
void StopThread();
Expand All @@ -84,8 +94,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<string>& instrumentIDs, const string& szExchageID);
void SubscribeQuote(const set<string>& instrumentIDs, const string& szExchageID);
void Subscribe(const set<string>& instrumentIDs, const string& szExchangeID);
void SubscribeQuote(const set<string>& instrumentIDs, const string& szExchangeID);

//virtual void OnFrontConnected();
//virtual void OnFrontDisconnected(int nReason);
Expand Down Expand Up @@ -121,6 +131,8 @@ class CMdUserApi
UserInfoField m_UserInfo;
int m_nSleep;

map<string,set<string>> m_DictSet; //��Լ��

CMsgQueue* m_msgQueue; //��Ϣ����ָ��
//CMsgQueue* m_msgQueue_Query;
void* m_pClass;
Expand Down
7 changes: 7 additions & 0 deletions QuantBox_TongShi_Quote/suggest.txt
Original file line number Diff line number Diff line change
@@ -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);