forked from QuantBox/QuantBox_XAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXApi.QuoteRequest.cs
129 lines (110 loc) · 4.16 KB
/
XApi.QuoteRequest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
namespace QuantBox.XAPI.Callback
{
public partial class XApi
{
public DelegateOnRtnQuoteRequest OnRtnQuoteRequest
{
get {return OnRtnQuoteRequest_;}
set { OnRtnQuoteRequest_ = value; }
}
private DelegateOnRtnQuoteRequest OnRtnQuoteRequest_;
#region 做市商询价订阅,主要是XSpeed这个功能是在交易API中
public int MaxSubscribedQuotesCount;
public int SubscribedQuotesCount
{
get
{
lock (locker)
{
int cnt = 0;
foreach (var kv in _SubscribedQuotes)
{
cnt += kv.Value.Count;
}
return cnt;
}
}
}
public bool SubscribedQuotesContains(string szInstrument, string szExchange)
{
lock (locker)
{
HashSet<string> instruments;
if (_SubscribedQuotes.TryGetValue(szExchange, out instruments))
{
return instruments.Contains(szInstrument);
}
return false;
}
}
private Dictionary<string, HashSet<string>> _SubscribedQuotes = new Dictionary<string, HashSet<string>>();
public Dictionary<string, HashSet<string>> SubscribedQuotes
{
get
{
lock (locker)
{
return _SubscribedQuotes;
}
}
}
public virtual void SubscribeQuote(string szInstrument, string szExchange)
{
lock (locker)
{
IntPtr szInstrumentPtr = Marshal.StringToHGlobalAnsi(szInstrument);
IntPtr szExchangePtr = Marshal.StringToHGlobalAnsi(szExchange);
proxy.XRequest((byte)RequestType.SubscribeQuote, Handle, IntPtr.Zero, 0, 0,
szInstrumentPtr, 0, szExchangePtr, 0, IntPtr.Zero, 0);
HashSet<string> instruments;
if (!_SubscribedQuotes.TryGetValue(szExchange, out instruments))
{
instruments = new HashSet<string>();
_SubscribedQuotes[szExchange] = instruments;
}
szInstrument.Split(new char[2] { ';', ',' }).ToList().ForEach(x =>
{
instruments.Add(x);
});
Marshal.FreeHGlobal(szInstrumentPtr);
Marshal.FreeHGlobal(szExchangePtr);
}
}
public virtual void UnsubscribeQuote(string szInstrument, string szExchange)
{
lock (locker)
{
IntPtr szInstrumentPtr = Marshal.StringToHGlobalAnsi(szInstrument);
IntPtr szExchangePtr = Marshal.StringToHGlobalAnsi(szExchange);
proxy.XRequest((byte)RequestType.UnsubscribeQuote, Handle, IntPtr.Zero, 0, 0,
szInstrumentPtr, 0, szExchangePtr, 0, IntPtr.Zero, 0);
HashSet<string> instruments;
if (!_SubscribedQuotes.TryGetValue(szExchange, out instruments))
{
instruments = new HashSet<string>();
_SubscribedQuotes[szExchange] = instruments;
}
szInstrument.Split(new char[2] { ';', ',' }).ToList().ForEach(x =>
{
instruments.Remove(x);
});
Marshal.FreeHGlobal(szInstrumentPtr);
Marshal.FreeHGlobal(szExchangePtr);
}
}
#endregion
private void _OnRtnQuoteRequest(IntPtr ptr1, int size1)
{
if (OnRtnQuoteRequest_ == null)
return;
//QuoteRequestField obj = PInvokeUtility.GetObjectFromIntPtr<QuoteRequestField>(ptr1);
QuoteRequestField obj = (QuoteRequestField)Marshal.PtrToStructure(ptr1, typeof(QuoteRequestField));
OnRtnQuoteRequest_(this, ref obj);
}
}
}