forked from jasonweiyi/XAPI2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
397 lines (295 loc) · 12.4 KB
/
Program.cs
File metadata and controls
397 lines (295 loc) · 12.4 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
using XAPI.Callback;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;
using XAPI.Event;
namespace XAPI
{
class Program
{
static void OnConnectionStatus(object sender, ConnectionStatus status, ref RspUserLoginField userLogin, int size1)
{
if (size1>0)
{
Console.WriteLine("333333" + userLogin.ToFormattedStringLong());
}
else
{
Console.WriteLine("333333" + status);
}
}
static void OnConnectionStatus2(object sender, ConnectionStatus status, ref RspUserLoginField userLogin, int size1)
{
if (size1 > 0)
{
Console.WriteLine("222222" + userLogin.ToFormattedStringLong());
}
else
{
Console.WriteLine("222222" + status);
}
}
static void OnRtnDepthMarketData(object sender, ref DepthMarketDataNClass marketData)
{
Debugger.Log(0, null, "CTP:C#");
Console.WriteLine(marketData.InstrumentID);
Console.WriteLine(marketData.Exchange);
Console.WriteLine(marketData.LastPrice);
}
static void OnRspQryInstrument(object sender, ref InstrumentField instrument,int size1, bool bIsLast)
{
Console.WriteLine(instrument.InstrumentName);
}
static void OnRspQryTradingAccount(object sender, ref AccountField account, int size1, bool bIsLast)
{
}
static void OnRspQrySettlementInfo(object sender, ref SettlementInfoClass settlementInfo, int size1, bool bIsLast)
{
Console.WriteLine(settlementInfo.Content);
}
static void OnRtnOrder(object sender, ref OrderField order)
{
Console.WriteLine("AA " + order.Status + order.ExecType + order.Text() + "AA " + order.ID + "AA " + order.OrderID);
}
static void OnRtnError(object sender, ref ErrorField error)
{
Console.WriteLine("BB" + error.XErrorID + error.RawErrorID + error.Text());
}
static void OnRtnTrade(object sender, ref TradeField trade)
{
Console.WriteLine("CC " + trade.Time + "CC " + trade.ID + "CC " + trade.TradeID);
}
static bool OnFilterSubscribe(object sender, ExchangeType exchange, int instrument_part1, int instrument_part2, int instrument_part3, IntPtr pInstrument)
{
// 当数字为0时,只判断交易所
// 当交易所为
if (instrument_part1 == 0)
// 只要上海与深圳,不处理三板
return exchange != ExchangeType.NEEQ;
//type = ExchangeType::SZE;
//double1 = 399300;
int prefix1 = instrument_part1 / 100000;
int prefix3 = instrument_part1 / 1000;
switch (exchange)
{
case ExchangeType.SSE:
return (prefix1 == 6);
case ExchangeType.SZSE:
return (prefix1 == 0) || (prefix3 == 300);
default:
break;
}
return true;
}
static void Main(string[] args)
{
// 注意:为了进行进程外COM技术的支持,项目已经修改了启动对象,
// 默认是从另一个Main中启动,如想测试此内容,请修改项目的属性,Application->Startup object
int i;
int iCount = args.Length;
for (i = 0; i < iCount; i++)
{
Console.Write("Argument : ");
Console.WriteLine(args[i]);
}
Console.WriteLine("Press [ENTER] to exit.");
Console.ReadLine();
//for (int i = 0; i < 10000; ++i)
{
test_CTP_Main(args);
}
Console.ReadKey();
}
static void test_Linux_Main(string[] args)
{
XApi api = new XApi(@"libQuantBox_CTP_Quote.so");
XApi api2 = new XApi(@"libQuantBox_CTP_Trade.so");
api.Server.BrokerID = "1017";
api.Server.Address = "tcp://ctpmn1-front1.citicsf.com:51213";
api.User.UserID = "00000015";
api.User.Password = "123456";
api.OnConnectionStatus = OnConnectionStatus;
api.OnRtnDepthMarketData = OnRtnDepthMarketData;
api2.Server.BrokerID = "1017";
api2.Server.Address = "tcp://ctpmn1-front1.citicsf.com:51205";
api2.Server.PrivateTopicResumeType = ResumeType.Quick;
api2.User.UserID = "00000015";
api2.User.Password = "123456";
api2.OnConnectionStatus = OnConnectionStatus2;
api2.OnRspQryInstrument = OnRspQryInstrument;
api2.OnRspQryTradingAccount = OnRspQryTradingAccount;
api2.OnRspQrySettlementInfo = OnRspQrySettlementInfo;
api2.OnRtnOrder = OnRtnOrder;
api2.OnRtnError = OnRtnError;
api2.OnRtnTrade = OnRtnTrade;
api.Connect();
api2.Connect();
api.Subscribe("IF1502;IF1503", "");
Console.ReadKey();
Thread.Sleep (10000);
Console.WriteLine (123);
api.Dispose();
api2.Dispose();
}
#region LTS
static void test_LTS_Main(string[] args)
{
XApi api = new XApi("QuantBox_LTS_Quote.dll");
XApi api2 = new XApi("QuantBox_C2LTS_Trade.dll");
api.Server.BrokerID = "2010";
api.Server.Address = "tcp://211.144.195.163:44513";
api.User.UserID = "00000015";
api.User.Password = "123456";
api.OnConnectionStatus = OnConnectionStatus;
api.OnRtnDepthMarketData = OnRtnDepthMarketData;
api2.Server.BrokerID = "2010";
api2.Server.Address = "tcp://211.144.195.163:44505";
api2.User.UserID = "0020090001134";
api2.User.Password = "123321";
api2.OnConnectionStatus = OnConnectionStatus2;
api2.OnRspQryInstrument = OnRspQryInstrument;
api2.OnRspQryTradingAccount = OnRspQryTradingAccount;
api2.OnRspQrySettlementInfo = OnRspQrySettlementInfo;
api2.OnRtnOrder = OnRtnOrder;
api2.OnRtnError = OnRtnError;
api2.OnRtnTrade = OnRtnTrade;
api.Connect();
api2.Connect();
Console.ReadKey();
ReqQueryField query = default(ReqQueryField);
api2.ReqQuery(QueryType.ReqQryInstrument, ref query);
Console.ReadKey();
api.Dispose();
api2.Dispose();
//queue.Dispose();
}
#endregion
static XApi api;
static void test_TongShi_Main(string[] args)
{
api = new XApi(@"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\XAPI\TongShi\x86\QuantBox_TongShi_Quote.dll");
api.Server.Address = "D:\\Scengine\\Stock.dll";
api.OnConnectionStatus = OnConnectionStatus;
api.OnRtnDepthMarketData = OnRtnDepthMarketData;
api.OnFilterSubscribe = OnFilterSubscribe;
api.Connect();
Thread.Sleep(10 * 1000);
ReqQueryField query = default(ReqQueryField);
api.ReqQuery(QueryType.ReqQryInstrument, ref query);
Thread.Sleep(300 * 1000);
api.Dispose();
Thread.Sleep(5 * 1000);
}
static void test_CTP_Main(string[] args)
{
//api = new XApi(@"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\XAPI\CTP\x86\QuantBox_CTP_Quote.dll");
//api.Server.BrokerID = "1017";
//api.Server.Address = "tcp://ctpmn1-front1.citicsf.com:51213";
api = new XApi(@"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\XAPI\x86\CTP\CTP_Trade_x86.dll");
api.Server.BrokerID = "4040";
api.Server.Address = "tcp://180.166.103.21:51205";
api.Server.PrivateTopicResumeType = ResumeType.Undefined;
api.User.UserID = "";
api.User.Password = "";
api.OnConnectionStatus = OnConnectionStatus;
api.OnRtnDepthMarketData = OnRtnDepthMarketData;
api.OnRspQryInstrument = OnRspQryInstrument;
api.OnRspQrySettlementInfo = OnRspQrySettlementInfo;
api.Connect();
Thread.Sleep(5 * 1000);
//api.Subscribe("IF1502", "");
ReqQueryField query = default(ReqQueryField);
query.DateStart = 20161124;
api.ReqQuery(QueryType.ReqQrySettlementInfo, ref query);
Thread.Sleep(10 * 1000);
api.Dispose();
Thread.Sleep(5 * 1000);
}
static void test_KingstarStock_Main(string[] args)
{
//ApiManager.QueuePath = @"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\XAPI\QuantBox_CTP_Trade.dll";
api = new XApi(@"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\XAPI\KingstarStock\x86\QuantBox_KingstarStock_Trade.dll");
api.Server.BrokerID = "1017";
api.Server.Address = "tcp://ctpmn1-front1.citicsf.com:51205";
api.User.UserID = "00000015";
api.User.Password = "1234561";
api.OnConnectionStatus = OnConnectionStatus;
api.OnRtnDepthMarketData = OnRtnDepthMarketData;
api.OnRtnError = OnRtnError;
api.Connect();
Thread.Sleep(5 * 1000);
api.Dispose();
}
static void test_KingstarGold_Main(string[] args)
{
api = new XApi(@"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\XAPI\KingstarGold\QuantBox_KingstarGold.dll");
api.Server.BrokerID = "";
api.Server.Address = "tcp://124.74.239.38:18961";
api.User.UserID = "9843010200773696";
api.User.Password = "123456";
api.OnConnectionStatus = OnConnectionStatus;
api.OnRtnDepthMarketData = OnRtnDepthMarketData;
api.Connect();
Console.ReadKey();
api.Subscribe("IF1411", "");
Console.ReadKey();
api.Dispose();
Console.ReadKey();
Console.ReadKey();
}
static void test_Tdx_Main(string[] args)
{
api = new XApi(@"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\XAPI\x86\Tdx\Tdx_Trade_x86.dll");
api.Server.Address = @"D:\tc_yhzq_v6\Login.lua";
api.Server.ExtInfoChar128 = @"D:\tc_yhzq_v6\";
api.User.UserID = "16206";
api.User.Password = "198450";
api.Server.Address = @"D:\new_gjzq_v6\Login.lua";
api.Server.ExtInfoChar128 = @"D:\new_gjzq_v6\";
api.User.UserID = "31244679";
api.User.Password = "400323";
api.OnConnectionStatus = OnConnectionStatus;
api.OnRtnDepthMarketData = OnRtnDepthMarketData;
api.Connect();
Console.ReadKey();
Console.WriteLine("回车后开始查持仓");
Console.ReadKey();
ReqQueryField query = new ReqQueryField();
query.Int32ID = -1;
api.ReqQuery(QueryType.ReqQryInvestorPosition, ref query);
// api.Dispose();
Console.ReadKey();
Console.WriteLine("回车后退出");
Console.ReadKey();
}
static void test_Tdx_Event_Main(string[] args)
{
XApiWrapper api = new XApiWrapper(@"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\XAPI\Tdx\x86\QuantBox_Tdx_Trade.dll");
api.Server.BrokerID = "";
api.Server.Address = @"D:\new_hbzq_qq\Login.lua";
api.Server.ExtInfoChar128 = @"D:\new_hbzq_qq\";
api.User.UserID = "05000000000";
api.User.Password = "123456";
api.OnConnectionStatus += api_OnConnectionStatus;
api.OnRtnDepthMarketData += api_OnRtnDepthMarketData;
api.Connect();
Console.ReadKey();
Console.ReadKey();
api.Dispose();
Console.ReadKey();
Console.ReadKey();
}
static void api_OnRtnDepthMarketData(object sender, OnRtnDepthMarketDataNEventArgs e)
{
throw new NotImplementedException();
}
static void api_OnConnectionStatus(object sender, OnConnectionStatusEventArgs e)
{
throw new NotImplementedException();
}
}
}