Skip to content

Commit 4fa1fff

Browse files
committed
黄金API行情测试
1 parent aa7cfe7 commit 4fa1fff

File tree

9 files changed

+51
-25
lines changed

9 files changed

+51
-25
lines changed

QuantBox.XAPI/Callback/ApiManager.cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,20 @@ public static class ApiManager
1111
{
1212
public static string QueuePath;
1313

14-
private static ConcurrentDictionary<BaseApi, Queue> dict = new ConcurrentDictionary<BaseApi, Queue>();
14+
private static ConcurrentDictionary<TraderApi, Queue> dict = new ConcurrentDictionary<TraderApi, Queue>();
1515

16-
public static MarketDataApi CreateMarketDataApi(string path)
17-
{
18-
Queue queue = new Queue(QueuePath);
19-
MarketDataApi api = new MarketDataApi(path, new Queue(QueuePath));
20-
dict.TryAdd(api, queue);
21-
return api;
22-
}
23-
24-
public static TraderApi CreateTraderApi(string path)
16+
public static TraderApi CreateApi(string path)
2517
{
2618
Queue queue = new Queue(QueuePath);
2719
TraderApi api = new TraderApi(path, new Queue(QueuePath));
2820
dict.TryAdd(api, queue);
2921
return api;
3022
}
3123

32-
public static void Release(BaseApi api)
24+
public static void ReleaseApi(BaseApi api)
3325
{
3426
Queue queue;
35-
if(dict.TryRemove(api,out queue))
27+
if(dict.TryRemove(api as TraderApi,out queue))
3628
{
3729
api.Dispose();
3830
queue.Dispose();

QuantBox.XAPI/Callback/MarketDataApi.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ protected override IntPtr OnRespone(byte type, IntPtr pApi1, IntPtr pApi2, doubl
9393
_OnRtnDepthMarketData(ptr1);
9494
break;
9595
default:
96+
base.OnRespone(type, pApi1, pApi2, double1, double2, ptr1, size1, ptr2, size2, ptr3, size3);
9697
break;
9798
}
9899

QuantBox.XAPI/Callback/TraderApi.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ protected override IntPtr OnRespone(byte type, IntPtr pApi1, IntPtr pApi2, doubl
155155
_OnRtnTrade(ptr1, size1);
156156
break;
157157
default:
158+
base.OnRespone(type, pApi1, pApi2, double1, double2, ptr1, size1, ptr2, size2, ptr3, size3);
158159
break;
159160
}
160161

QuantBox.XAPI/Program.cs

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ static void OnRtnTrade(object sender, ref TradeField trade)
6060

6161
static void Main(string[] args)
6262
{
63-
UIntPtr a = new UIntPtr(456);
64-
Console.WriteLine(a);
65-
return;
63+
//test_KingstarGold_Main(args);
6664
test_CTP_Main(args);
6765
}
6866

@@ -161,7 +159,7 @@ static void test_LTS_Main(string[] args)
161159
static void test_CTP_Main(string[] args)
162160
{
163161
ApiManager.QueuePath = @"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\QuantBox_Queue.dll";
164-
api = ApiManager.CreateMarketDataApi(@"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\XAPI\CTP\QuantBox_CTP_Quote.dll");
162+
api = ApiManager.CreateApi(@"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\XAPI\CTP\QuantBox_CTP_Quote.dll");
165163

166164
api.Server.BrokerID = "1017";
167165
api.Server.Address = "tcp://ctpmn1-front1.citicsf.com:51213";
@@ -180,7 +178,38 @@ static void test_CTP_Main(string[] args)
180178

181179
Console.ReadKey();
182180

183-
ApiManager.Release(api);
181+
ApiManager.ReleaseApi(api);
182+
183+
Console.ReadKey();
184+
185+
Console.ReadKey();
186+
187+
//api.Dispose();
188+
//queue.Dispose();
189+
}
190+
191+
static void test_KingstarGold_Main(string[] args)
192+
{
193+
ApiManager.QueuePath = @"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\QuantBox_Queue.dll";
194+
api = ApiManager.CreateApi(@"C:\Program Files\SmartQuant Ltd\OpenQuant 2014\XAPI\KingstarGold\QuantBox_KingstarGold.dll");
195+
196+
api.Server.BrokerID = "";
197+
api.Server.Address = "tcp://124.74.239.38:18961";
198+
199+
api.User.UserID = "9843010200773696";
200+
api.User.Password = "123456";
201+
202+
api.OnConnectionStatus = OnConnectionStatus;
203+
api.OnRtnDepthMarketData = OnRtnDepthMarketData;
204+
205+
api.Connect();
206+
207+
Console.ReadKey();
208+
api.Subscribe("IF1411", "");
209+
210+
Console.ReadKey();
211+
212+
ApiManager.ReleaseApi(api);
184213

185214
Console.ReadKey();
186215

QuantBox.XAPI/Struct.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public struct UserInfoField
1616
/// <summary>
1717
/// 用户代码
1818
/// </summary>
19-
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
19+
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
2020
public string UserID;
2121
/// <summary>
2222
/// 密码

QuantBox_KingstarGold/TraderApi.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,9 @@ void CTraderApi::Connect(const string& szPath,
119119
//m_pApi->SubscribePrivateTopic((THOST_TE_RESUME_TYPE)pServerInfo->Resume);
120120

121121
//初始化连接
122-
m_pApi->Init();
122+
int ret = m_pApi->Init();
123123
XRespone(ResponeType::OnConnectionStatus, m_msgQueue, this, ConnectionStatus::Connecting, 0, nullptr, 0, nullptr, 0, nullptr, 0);
124+
ReqUserLogin();
124125
}
125126
}
126127

QuantBox_Queue/MsgQueue.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
void CMsgQueue::Clear()
55
{
6-
ResponeItem* pItem = NULL;
6+
ResponeItem* pItem = nullptr;
77
//清空队列
88
while (m_queue.try_dequeue(pItem))
99
{
@@ -16,7 +16,7 @@ void CMsgQueue::Clear()
1616

1717
bool CMsgQueue::Process()
1818
{
19-
ResponeItem* pItem = NULL;
19+
ResponeItem* pItem = nullptr;
2020
if (m_queue.try_dequeue(pItem))
2121
{
2222
Output(pItem);
@@ -40,7 +40,8 @@ void CMsgQueue::StartThread()
4040

4141
void CMsgQueue::StopThread()
4242
{
43-
//m_mtx.unlock();
43+
//m_mtx.lock();
44+
lock_guard<mutex> cl(m_mtx);
4445

4546
m_bRunning = false;
4647
if(m_hThread)
@@ -49,6 +50,7 @@ void CMsgQueue::StopThread()
4950
delete m_hThread;
5051
m_hThread = nullptr;
5152
}
53+
//m_mtx.unlock();
5254
}
5355

5456
void CMsgQueue::RunInThread()
@@ -67,6 +69,6 @@ void CMsgQueue::RunInThread()
6769
}
6870

6971
// 清理线程
70-
m_hThread = NULL;
72+
m_hThread = nullptr;
7173
m_bRunning = false;
7274
}

QuantBox_Queue/MsgQueue.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class CMsgQueue
9999

100100
private:
101101
volatile bool m_bRunning;
102-
recursive_mutex m_mtx;
102+
mutex m_mtx;
103103
thread* m_hThread;
104104
ReaderWriterQueue<ResponeItem*> m_queue;
105105
fnOnRespone m_fnOnRespone;

include/ApiDataType.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ typedef int TimeIntType;
7171
/////////////////////////////////////////////////////////////////////////
7272
///UserIDType是一个用户代码类型
7373
/////////////////////////////////////////////////////////////////////////
74-
typedef char UserIDType[16];
74+
typedef char UserIDType[32];
7575

7676
/////////////////////////////////////////////////////////////////////////
7777
///TFtdcPasswordType是一个密码类型

0 commit comments

Comments
 (0)