Skip to content

Commit c618bc2

Browse files
committed
将所有API的发送队列都全部统一起来
这次统一过急,有些API没有经过测试,需要发布时再次测试一次
1 parent 4c8291e commit c618bc2

89 files changed

Lines changed: 6013 additions & 5873 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

QuantBox.XAPI/Callback/ApiManager.cs

Lines changed: 0 additions & 45 deletions
This file was deleted.

QuantBox.XAPI/Callback/BaseApi.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ public class BaseApi : IDisposable
1414
public Logger log;
1515
protected Proxy proxy;
1616
protected IntPtr Handle = IntPtr.Zero;
17-
protected Queue _Queue;
1817
private string _Path1;
19-
//private string _Path2;
2018

2119
protected XCall _XRespone;
2220

@@ -54,13 +52,12 @@ public int ReconnectInterval
5452

5553
private System.Timers.Timer _Timer = new System.Timers.Timer();
5654

57-
internal BaseApi(string path1,Queue queue)
55+
internal BaseApi(string path1)
5856
{
5957
_Path1 = path1;
6058

6159
// 这里是因为回调函数可能被GC回收
6260
_XRespone = _OnRespone;
63-
_Queue = queue;
6461

6562
ReconnectInterval = 0;
6663
}
@@ -127,11 +124,9 @@ public virtual void Connect()
127124

128125
Handle = proxy.XRequest((byte)RequestType.Create, IntPtr.Zero, IntPtr.Zero, 0, 0, IntPtr.Zero, 0, IntPtr.Zero, 0, IntPtr.Zero, 0);
129126

130-
Register(_Queue.Handle);
127+
RegisterAndStart(Marshal.GetFunctionPointerForDelegate(_XRespone));
128+
131129

132-
_Queue.Register(Marshal.GetFunctionPointerForDelegate(_XRespone));
133-
// 启动队列循环
134-
_Queue.Connect();
135130

136131
IntPtr ServerIntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(ServerInfoField)));
137132
Marshal.StructureToPtr(Server, ServerIntPtr, false);
@@ -158,10 +153,7 @@ internal virtual void Disconnect()
158153
IsConnected = false;
159154

160155
if (proxy != null)
161-
{
162-
// 将API与队列解绑定,这句提前操作了就收不到Disconnected事件了
163-
//proxy.XRequest((byte)RequestType.Register, Handle, IntPtr.Zero, 0, 0, IntPtr.Zero, 0, IntPtr.Zero, 0, IntPtr.Zero, 0);
164-
156+
{
165157
proxy.XRequest((byte)RequestType.Disconnect, Handle, IntPtr.Zero, 0, 0, IntPtr.Zero, 0, IntPtr.Zero, 0, IntPtr.Zero, 0);
166158
proxy.XRequest((byte)RequestType.Release, Handle, IntPtr.Zero, 0, 0, IntPtr.Zero, 0, IntPtr.Zero, 0, IntPtr.Zero, 0);
167159

@@ -174,7 +166,7 @@ internal virtual void Disconnect()
174166

175167
}
176168

177-
public void Register(IntPtr ptr1)
169+
public void RegisterAndStart(IntPtr ptr1)
178170
{
179171
lock (this)
180172
{

QuantBox.XAPI/Callback/Queue.cs

Lines changed: 0 additions & 93 deletions
This file was deleted.

QuantBox.XAPI/Callback/XApi.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ namespace QuantBox.XAPI.Callback
1010
{
1111
public partial class XApi : BaseApi, IDisposable, IXApi
1212
{
13-
internal XApi(string path1, Queue queue)
14-
: base(path1, queue)
13+
public XApi(string path1)
14+
: base(path1)
1515
{
1616
}
1717

QuantBox.XAPI/Enum.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public enum ResumeType : byte
109109
Restart,
110110
Resume,
111111
Quick,
112+
Undefined,
112113
};
113114

114115
public enum PutCall : byte

QuantBox.XAPI/Program.cs

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static void Main(string[] args)
6363
{
6464
//for (int i = 0; i < 10000; ++i)
6565
{
66-
test_Linux_Main(args);
66+
test_KingstarStock_Main(args);
6767
}
6868
Console.ReadKey();
6969
}
@@ -77,9 +77,9 @@ static void test_Linux_Main(string[] args)
7777
//XApi api = ApiManager.CreateApi(@"/home/hetao/works/QuantBox_XAPI/bin/Debug/libQuantBox_CTP_Quote.so");
7878
//XApi api2 = ApiManager.CreateApi(@"/home/hetao/works/QuantBox_XAPI/bin/Debug/libQuantBox_CTP_Trade.so");
7979

80-
ApiManager.QueuePath = @"libQuantBox_Queue.so";
81-
XApi api = ApiManager.CreateApi(@"libQuantBox_CTP_Quote.so");
82-
XApi api2 = ApiManager.CreateApi(@"libQuantBox_CTP_Trade.so");
80+
//ApiManager.QueuePath = @"libQuantBox_Queue.so";
81+
XApi api = new XApi(@"libQuantBox_CTP_Quote.so");
82+
XApi api2 = new XApi(@"libQuantBox_CTP_Trade.so");
8383

8484
api.Server.BrokerID = "1017";
8585
api.Server.Address = "tcp://ctpmn1-front1.citicsf.com:51213";
@@ -115,17 +115,15 @@ static void test_Linux_Main(string[] args)
115115

116116
Thread.Sleep (10000);
117117
Console.WriteLine (123);
118-
ApiManager.ReleaseApi(api);
119-
ApiManager.ReleaseApi(api2);
118+
api.Dispose();
119+
api2.Dispose();
120120
}
121121

122122
#region LTS
123123
static void test_LTS_Main(string[] args)
124124
{
125-
Queue queue = new Queue(@"QuantBox_Queue.dll");
126-
Queue queue2 = new Queue(@"QuantBox_Queue.dll");
127-
XApi api = new XApi("QuantBox_LTS_Quote.dll", queue);
128-
XApi api2 = new XApi("QuantBox_C2LTS_Trade.dll", queue2);
125+
XApi api = new XApi("QuantBox_LTS_Quote.dll");
126+
XApi api2 = new XApi("QuantBox_C2LTS_Trade.dll");
129127

130128
api.Server.BrokerID = "2010";
131129
api.Server.Address = "tcp://211.144.195.163:44513";
@@ -169,8 +167,8 @@ static void test_LTS_Main(string[] args)
169167

170168
static void test_CTP_Main(string[] args)
171169
{
172-
ApiManager.QueuePath = @"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\QuantBox_Queue.dll";
173-
api = ApiManager.CreateApi(@"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\XAPI\CTP\QuantBox_CTP_Trade.dll");
170+
//ApiManager.QueuePath = @"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\QuantBox_Queue.dll";
171+
api = new XApi(@"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\XAPI\CTP\QuantBox_CTP_Trade.dll");
174172

175173
api.Server.BrokerID = "1017";
176174
api.Server.Address = "tcp://ctpmn1-front1.citicsf.com:51205";
@@ -185,14 +183,37 @@ static void test_CTP_Main(string[] args)
185183

186184
Thread.Sleep(5*1000);
187185

188-
ApiManager.ReleaseApi(api);
186+
api.Dispose();
187+
188+
}
189+
190+
static void test_KingstarStock_Main(string[] args)
191+
{
192+
//ApiManager.QueuePath = @"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\XAPI\QuantBox_CTP_Trade.dll";
193+
api = new XApi(@"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\XAPI\KingstarStock\x86\QuantBox_KingstarStock_Trade.dll");
194+
195+
api.Server.BrokerID = "1017";
196+
api.Server.Address = "tcp://ctpmn1-front1.citicsf.com:51205";
197+
198+
api.User.UserID = "00000015";
199+
api.User.Password = "1234561";
200+
201+
api.OnConnectionStatus = OnConnectionStatus;
202+
api.OnRtnDepthMarketData = OnRtnDepthMarketData;
203+
api.OnRtnError = OnRtnError;
204+
205+
api.Connect();
206+
207+
Thread.Sleep(5 * 1000);
208+
209+
api.Dispose();
189210

190211
}
191212

192213
static void test_KingstarGold_Main(string[] args)
193214
{
194-
ApiManager.QueuePath = @"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\QuantBox_Queue.dll";
195-
api = ApiManager.CreateApi(@"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\XAPI\KingstarGold\QuantBox_KingstarGold.dll");
215+
//ApiManager.QueuePath = @"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\QuantBox_Queue.dll";
216+
api = new XApi(@"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\XAPI\KingstarGold\QuantBox_KingstarGold.dll");
196217

197218
api.Server.BrokerID = "";
198219
api.Server.Address = "tcp://124.74.239.38:18961";
@@ -210,7 +231,7 @@ static void test_KingstarGold_Main(string[] args)
210231

211232
Console.ReadKey();
212233

213-
ApiManager.ReleaseApi(api);
234+
api.Dispose();
214235

215236
Console.ReadKey();
216237

QuantBox.XAPI/QuantBox.XAPI.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
<WarningLevel>4</WarningLevel>
3131
</PropertyGroup>
3232
<PropertyGroup>
33-
<StartupObject />
33+
<StartupObject>
34+
</StartupObject>
3435
</PropertyGroup>
3536
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug64|AnyCPU'">
3637
<DebugSymbols>true</DebugSymbols>
@@ -80,13 +81,11 @@
8081
<Reference Include="System.Xml" />
8182
</ItemGroup>
8283
<ItemGroup>
83-
<Compile Include="Callback\ApiManager.cs" />
8484
<Compile Include="Callback\BaseApi.cs" />
8585
<Compile Include="Callback\XApi.cs" />
8686
<Compile Include="Callback\XApi.HistoricalData.cs" />
8787
<Compile Include="Callback\XApi.QuoteRequest.cs" />
8888
<Compile Include="Callback\XApi.MarketData.cs" />
89-
<Compile Include="Callback\Queue.cs" />
9089
<Compile Include="Callback\XApi.Instrument.cs" />
9190
<Compile Include="Callback\XApi.Trade.cs" />
9291
<Compile Include="Delegate.cs" />

0 commit comments

Comments
 (0)