Skip to content

Commit c0ffd41

Browse files
committed
加入行情过滤接口,可提前将通视行情过滤
1 parent 242cb67 commit c0ffd41

File tree

20 files changed

+189
-58
lines changed

20 files changed

+189
-58
lines changed

QuantBox.XAPI/Callback/XApi.MarketData.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ public DelegateOnRtnDepthMarketData OnRtnDepthMarketData
1818
}
1919
// 这种写法的主要目的是求快
2020
private DelegateOnRtnDepthMarketData OnRtnDepthMarketData_;
21+
22+
public DelegateOnFilterSubscribe OnFilterSubscribe
23+
{
24+
get { return OnFilterSubscribe_; }
25+
set { OnFilterSubscribe_ = value; }
26+
}
27+
// 这种写法的主要目的是求快
28+
private DelegateOnFilterSubscribe OnFilterSubscribe_;
2129

2230

2331
#region 已经订阅的行情
@@ -130,5 +138,13 @@ private void _OnRtnDepthMarketData(IntPtr ptr1)
130138

131139
OnRtnDepthMarketData_(this, ref obj);
132140
}
141+
142+
private bool _OnFilterSubscribe(double double1, int size1, int size2, int size3, IntPtr ptr1)
143+
{
144+
if (OnFilterSubscribe_ == null)
145+
return true;
146+
147+
return OnFilterSubscribe_(this, (ExchangeType)double1, size1, size2, size3, ptr1);
148+
}
133149
}
134150
}

QuantBox.XAPI/Callback/XApi.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,12 @@ protected override IntPtr OnRespone(byte type, IntPtr pApi1, IntPtr pApi2, doubl
8888
case ResponeType.OnRspQryHistoricalBars:
8989
_OnRspQryHistoricalBars(ptr1, size1, ptr2, size2, double1);
9090
break;
91-
91+
case ResponeType.OnFilterSubscribe:
92+
if(_OnFilterSubscribe(double1, size1, size2, size3, ptr1))
93+
{
94+
return new IntPtr(1);
95+
}
96+
return IntPtr.Zero;
9297
default:
9398
base.OnRespone(type, pApi1, pApi2, double1, double2, ptr1, size1, ptr2, size2, ptr3, size3);
9499
break;

QuantBox.XAPI/Delegate.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ namespace QuantBox.XAPI
2424

2525
public delegate void DelegateOnRspQryHistoricalTicks(object sender, IntPtr pTicks, int size1, [In] ref HistoricalDataRequestField request, int size2, bool bIsLast);
2626
public delegate void DelegateOnRspQryHistoricalBars(object sender, IntPtr pBars, int size1, [In] ref HistoricalDataRequestField request, int size2, bool bIsLast);
27+
28+
public delegate bool DelegateOnFilterSubscribe(object sender, ExchangeType exchange, int instrument_part1, int instrument_part2, int instrument_part3, IntPtr pInstrument);
2729
}

QuantBox.XAPI/Enum.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,4 +256,18 @@ public enum IdCardType : byte
256256
AccountsPermits,
257257
OtherCard,
258258
};
259+
260+
public enum ExchangeType : byte
261+
{
262+
Undefined,
263+
SHFE, // 上期所
264+
DCE, // 大商所
265+
CZCE, // 郑商所
266+
CFFEX, // 中金所
267+
INE, // 能源中心
268+
SSE, // 上交所
269+
SZE, // 深交所
270+
NEEQ, // 全国中小企业股份转让系统
271+
HKEx,
272+
};
259273
}

QuantBox.XAPI/Program.cs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,37 @@ static void OnRtnTrade(object sender, ref TradeField trade)
6060
Console.WriteLine("CC " + trade.Time + "CC " + trade.ID + "CC " + trade.TradeID);
6161
}
6262

63+
static bool OnFilterSubscribe(object sender, ExchangeType exchange, int instrument_part1, int instrument_part2, int instrument_part3, IntPtr pInstrument)
64+
{
65+
// 当数字为0时,只判断交易所
66+
// 当交易所为
67+
if (instrument_part1 == 0)
68+
// 只要上海与深圳,不处理三板
69+
return exchange != ExchangeType.NEEQ;
70+
71+
//type = ExchangeType::SZE;
72+
//double1 = 399300;
73+
74+
int prefix1 = instrument_part1 / 100000;
75+
int prefix3 = instrument_part1 / 1000;
76+
switch (exchange)
77+
{
78+
case ExchangeType.SSE:
79+
return (prefix1 == 6);
80+
case ExchangeType.SZE:
81+
return (prefix1 == 0) || (prefix3 == 300);
82+
default:
83+
break;
84+
}
85+
86+
return true;
87+
}
88+
6389
static void Main(string[] args)
6490
{
6591
//for (int i = 0; i < 10000; ++i)
6692
{
67-
test_CTP_Main(args);
93+
test_TongShi_Main(args);
6894
}
6995
Console.ReadKey();
7096
}
@@ -158,6 +184,28 @@ static void test_LTS_Main(string[] args)
158184

159185
static XApi api;
160186

187+
static void test_TongShi_Main(string[] args)
188+
{
189+
190+
api = new XApi(@"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\XAPI\TongShi\x86\QuantBox_TongShi_Quote.dll");
191+
192+
api.Server.Address = "D:\\Scengine\\Stock.dll";
193+
194+
api.OnConnectionStatus = OnConnectionStatus;
195+
api.OnRtnDepthMarketData = OnRtnDepthMarketData;
196+
api.OnFilterSubscribe = OnFilterSubscribe;
197+
198+
api.Connect();
199+
Thread.Sleep(10 * 1000);
200+
api.ReqQryInstrument("", "");
201+
202+
Thread.Sleep(300 * 1000);
203+
204+
api.Dispose();
205+
206+
Thread.Sleep(5 * 1000);
207+
}
208+
161209
static void test_CTP_Main(string[] args)
162210
{
163211
//api = new XApi(@"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\XAPI\CTP\x86\QuantBox_CTP_Quote.dll");

QuantBox.XAPI/Proxy.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
namespace QuantBox.XAPI
88
{
99
public delegate IntPtr XCall(byte type, IntPtr pApi1, IntPtr pApi2, double double1, double double2, IntPtr ptr1, int size1, IntPtr ptr2, int size2, IntPtr ptr3, int size3);
10-
1110
public class Proxy
1211
{
1312
private InvokeBase _Invoke;

QuantBox.XAPI/RequestType.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,5 @@ public enum RequestType:byte
4848
ReqQryHistoricalTicks,
4949
ReqQryHistoricalBars,
5050
ReqQryInvestor,
51-
5251
}
5352
}

QuantBox.XAPI/ResponeType.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,7 @@ public enum ResponeType : byte
2323
OnRspQryHistoricalTicks,
2424
OnRspQryHistoricalBars,
2525
OnRspQryInvestor,
26+
27+
OnFilterSubscribe,
2628
}
2729
}

QuantBox_Queue/MsgQueue.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,18 @@ class DLL_PUBLIC CMsgQueue
7171
}
7272

7373
// 直接发送,不入队列
74-
void Input_Output(char type, void* pApi1, void* pApi2, double double1, double double2, void* ptr1, int size1, void* ptr2, int size2, void* ptr3, int size3)
74+
void* Input_Output(char type, void* pApi1, void* pApi2, double double1, double double2, void* ptr1, int size1, void* ptr2, int size2, void* ptr3, int size3)
7575
{
7676
try
7777
{
7878
if (m_fnOnRespone)
79-
(*m_fnOnRespone)(type, pApi1, pApi2, double1, double2, ptr1, size1, ptr2, size2, ptr3, size3);
79+
return (*m_fnOnRespone)(type, pApi1, pApi2, double1, double2, ptr1, size1, ptr2, size2, ptr3, size3);
8080
}
8181
catch (...)
8282
{
8383
m_fnOnRespone = nullptr;
8484
}
85+
return nullptr;
8586
}
8687

8788
// 对输入的数据做了一次复制,主要是为了解决转过来的指针可能失效的问题。

QuantBox_TongShi_Quote/MdUserApi.cpp

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ LRESULT CMdUserApi::_OnMsg(WPARAM wParam, LPARAM lParam)
4747
RCV_REPORT_STRUCTEx* pLast = &pHeader->m_pReport[pHeader->m_nPacketNum - 1];
4848

4949
// 前后都不合要求才跳过
50-
//if (FilterExchange(pFirst->m_wMarket) || FilterExchange(pLast->m_wMarket))
50+
if (FilterExchangeInstrument(pFirst->m_wMarket, 0) || FilterExchangeInstrument(pLast->m_wMarket, 0))
5151
{
5252
for (i = 0; i < pHeader->m_nPacketNum; i++)
5353
{
@@ -322,42 +322,22 @@ void CMdUserApi::OnRspQryInstrument(DepthMarketDataField* _pField,RCV_REPORT_STR
322322
m_msgQueue->Input_NoCopy(ResponeType::OnRspQryInstrument, m_msgQueue, m_pClass, index >= Count - 1, 0, pField, sizeof(InstrumentField), nullptr, 0, nullptr, 0);
323323
}
324324

325-
bool CMdUserApi::FilterExchange(WORD wMarket)
326-
{
327-
// 只要上海与深圳,不处理三板
328-
return wMarket != SB_MARKET_EX;
329-
}
330325

331-
bool CMdUserApi::FilterInstrument(WORD wMarket, int instrument)
326+
bool CMdUserApi::FilterExchangeInstrument(WORD wMarket, int instrument)
332327
{
333-
// 只处理A股,不处理债券与基金
334-
int prefix1 = instrument / 100000;
335-
switch (wMarket)
336-
{
337-
case SH_MARKET_EX:
338-
return (prefix1 == 6);
339-
case SZ_MARKET_EX:
340-
return (prefix1 == 0) || (prefix1 == 3);
341-
default:
342-
break;
343-
}
344-
return false;
328+
// 行情太多,需要过滤
329+
return (bool)m_msgQueue->Input_Output(ResponeType::OnFilterSubscribe, m_msgQueue, m_pClass, Market_2_ExchangeType(wMarket), 0, nullptr, instrument, nullptr, 0, nullptr, 0);
345330
}
346331

347332
//行情回调,得保证此函数尽快返回
348333
void CMdUserApi::OnRtnDepthMarketData(RCV_REPORT_STRUCTEx *pDepthMarketData, int index, int Count)
349334
{
350335
// 把不想要的过滤了,加快速度
351-
//if (
352-
// FilterExchange(pDepthMarketData->m_wMarket)
353-
// &&FilterInstrument(pDepthMarketData->m_wMarket, atoi(pDepthMarketData->m_szLabel))
354-
// )
355-
//{
356-
//}
357-
//else
358-
//{
359-
// return;
360-
//}
336+
if (!FilterExchangeInstrument(
337+
pDepthMarketData->m_wMarket,
338+
atoi(pDepthMarketData->m_szLabel))
339+
)
340+
return;
361341

362342
DepthMarketDataField* pField = (DepthMarketDataField*)m_msgQueue->new_block(sizeof(DepthMarketDataField));
363343

0 commit comments

Comments
 (0)