forked from QuantBox/QuantBox_XAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
223 lines (163 loc) · 7.02 KB
/
Program.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
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
using QuantBox.XAPI.Callback;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Threading;
namespace QuantBox.XAPI
{
class Program
{
static void OnConnectionStatus(object sender, ConnectionStatus status, ref RspUserLoginField userLogin, int size1)
{
Console.WriteLine("11111" + status);
}
static void OnConnectionStatus2(object sender, ConnectionStatus status, ref RspUserLoginField userLogin, int size1)
{
Console.WriteLine("22222" + status+userLogin.ErrorMsg());
}
static void OnRtnDepthMarketData(object sender, ref DepthMarketDataField marketData)
{
Console.WriteLine(marketData.InstrumentID);
Console.WriteLine(marketData.ExchangeID);
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 SettlementInfoField settlementInfo, int size1, bool bIsLast)
{
}
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.ErrorID + error.ErrorMsg());
}
static void OnRtnTrade(object sender, ref TradeField trade)
{
Console.WriteLine("CC " + trade.Time + "CC " + trade.ID + "CC " + trade.TradeID);
}
static void Main(string[] args)
{
for (int i = 0; i < 10000; ++i)
{
test_CTP_Main(args);
}
Console.ReadKey();
}
static void test_Linux_Main(string[] args)
{
//Console.WriteLine (Path.GetTempPath());
//return;
Queue queue = new Queue(@"libQuantBox_Queue.so");
//Queue queue2 = new Queue(@"libQuantBox_Queue.so");
MarketDataApi api = new MarketDataApi(@"/home/hetao/works/QuantBox_X/QuantBox.XAPI/bin/libQuantBox_CTP_Quote.so", queue);
//TraderApi api2 = new TraderApi(@"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\TAPI\CTP\QuantBox.C2CTP.Trade.dll", queue2);
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.ResumeType = ResumeType.Restart;
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("IF1410", "");
Console.ReadKey();
Console.ReadKey();
api.Dispose();
}
#region LTS
static void test_LTS_Main(string[] args)
{
Queue queue = new Queue(@"QuantBox_Queue.dll");
Queue queue2 = new Queue(@"QuantBox_Queue.dll");
MarketDataApi api = new MarketDataApi("QuantBox_LTS_Quote.dll", queue);
TraderApi api2 = new TraderApi("QuantBox_C2LTS_Trade.dll", queue2);
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();
api2.ReqQryInstrument("", "");
Console.ReadKey();
api.Dispose();
api2.Dispose();
//queue.Dispose();
}
#endregion
static MarketDataApi api;
static void test_CTP_Main(string[] args)
{
ApiManager.QueuePath = @"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\QuantBox_Queue.dll";
api = ApiManager.CreateApi(@"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\XAPI\CTP\QuantBox_CTP_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.Connect();
Thread.Sleep(5*1000);
ApiManager.ReleaseApi(api);
//api.Dispose();
//queue.Dispose();
}
static void test_KingstarGold_Main(string[] args)
{
ApiManager.QueuePath = @"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\QuantBox_Queue.dll";
api = ApiManager.CreateApi(@"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();
ApiManager.ReleaseApi(api);
Console.ReadKey();
Console.ReadKey();
//api.Dispose();
//queue.Dispose();
}
}
}