-
Notifications
You must be signed in to change notification settings - Fork 3
/
mdapi_wrap.cxx
421 lines (366 loc) · 14.2 KB
/
mdapi_wrap.cxx
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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <iostream>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <sys/types.h>
#include "ThostFtdcMdApi.h"
#include "ThostFtdcTraderApi.h"
#include "ThostFtdcUserApiDataType.h"
#include "ThostFtdcUserApiStruct.h"
#include "mdapi_wrap.h"
typedef long long intgo;
typedef struct
{
char* p;
int64_t n;
} _gostring_;
typedef struct
{
void* array;
int64_t len;
int64_t cap;
} _goslice_;
#ifdef __cplusplus
extern "C" {
#endif
QCTPMdSpi* _wrap_CThostFtdcMdApi_CreateFtdcMdApi()
{
CThostFtdcMdApi* pUserApi = CThostFtdcMdApi::CreateFtdcMdApi("./data/", false);
QCTPMdSpi* pUserSpi = new QCTPMdSpi(pUserApi);
pUserSpi->RegisterSpi(pUserSpi);
return pUserSpi;
}
QCTPMdSpi* _wrap_CThostFtdcMdApi_CreateFtdcMdApi2(uintptr_t gUserApi, const char* pszFlowPath, const bool bIsUsingUdp, const bool bIsMulticast)
{
// printf("go_user_api %lu\n", gUserApi);
CThostFtdcMdApi* pUserApi = CThostFtdcMdApi::CreateFtdcMdApi(pszFlowPath, bIsUsingUdp, bIsMulticast);
QCTPMdSpi* pUserSpi = new QCTPMdSpi(pUserApi, gUserApi);
pUserSpi->RegisterSpi(pUserSpi);
return pUserSpi;
}
// 获取API的版本信息
///@retrun 获取到的版本号
const char* _wrap_CThostFtdcMdApi_GetApiVersion(QCTPMdSpi* pMdApi)
{
return pMdApi->GetApiVersion();
}
// 删除接口对象本身
///@remark 不再使用本接口对象时,调用该函数删除接口对象
void _wrap_CThostFtdcMdApi_Release(QCTPMdSpi* pMdApi)
{
return pMdApi->Release();
}
// 初始化
///@remark 初始化运行环境,只有调用后,接口才开始工作
void _wrap_CThostFtdcMdApi_Init(QCTPMdSpi* pMdApi)
{
return pMdApi->Init();
}
// 等待接口线程结束运行
///@return 线程退出代码
int _wrap_CThostFtdcMdApi_Join(QCTPMdSpi* pMdApi)
{
return pMdApi->Join();
}
// 获取当前交易日
///@retrun 获取到的交易日
///@remark 只有登录成功后,才能得到正确的交易日
const char* _wrap_CThostFtdcMdApi_GetTradingDay(QCTPMdSpi* pMdApi)
{
return pMdApi->GetTradingDay();
}
// 注册前置机网络地址
///@param pszFrontAddress:前置机网络地址。
///@remark 网络地址的格式为:“protocol://ipaddress:port”,如:”tcp://127.0.0.1:17001”。
///@remark “tcp”代表传输协议,“127.0.0.1”代表服务器地址。”17001”代表服务器端口号。
void _wrap_CThostFtdcMdApi_RegisterFront(QCTPMdSpi* pMdApi, char* pszFrontAddress)
{
return pMdApi->RegisterFront(pszFrontAddress);
}
// 注册名字服务器网络地址
///@param pszNsAddress:名字服务器网络地址。
///@remark 网络地址的格式为:“protocol://ipaddress:port”,如:”tcp://127.0.0.1:12001”。
///@remark “tcp”代表传输协议,“127.0.0.1”代表服务器地址。”12001”代表服务器端口号。
///@remark RegisterNameServer优先于RegisterFront
void _wrap_CThostFtdcMdApi_RegisterNameServer(QCTPMdSpi* pMdApi, char* pszNsAddress)
{
return pMdApi->RegisterNameServer(pszNsAddress);
}
// 注册名字服务器用户信息
///@param pFensUserInfo:用户信息。
void _wrap_CThostFtdcMdApi_RegisterFensUserInfo(QCTPMdSpi* pMdApi, CThostFtdcFensUserInfoField* pFensUserInfo)
{
return pMdApi->RegisterFensUserInfo(pFensUserInfo);
}
// 订阅行情。
///@param ppInstrumentID 合约ID
///@param nCount 要订阅/退订行情的合约个数
///@remark
int _wrap_CThostFtdcMdApi_SubscribeMarketData(QCTPMdSpi* pMdApi, char** ppInstrumentID, int nCount)
{
return pMdApi->SubscribeMarketData(ppInstrumentID, nCount);
}
// 退订行情。
///@param ppInstrumentID 合约ID
///@param nCount 要订阅/退订行情的合约个数
///@remark
int _wrap_CThostFtdcMdApi_UnSubscribeMarketData(QCTPMdSpi* pMdApi, char** ppInstrumentID, int nCount)
{
return pMdApi->UnSubscribeMarketData(ppInstrumentID, nCount);
}
// 订阅询价。
///@param ppInstrumentID 合约ID
///@param nCount 要订阅/退订行情的合约个数
///@remark
int _wrap_CThostFtdcMdApi_SubscribeForQuoteRsp(QCTPMdSpi* pMdApi, char** ppInstrumentID, int nCount)
{
return pMdApi->SubscribeForQuoteRsp(ppInstrumentID, nCount);
}
// 退订询价。
///@param ppInstrumentID 合约ID
///@param nCount 要订阅/退订行情的合约个数
///@remark
int _wrap_CThostFtdcMdApi_UnSubscribeForQuoteRsp(QCTPMdSpi* pMdApi, char** ppInstrumentID, int nCount)
{
return pMdApi->UnSubscribeForQuoteRsp(ppInstrumentID, nCount);
}
// 用户登录请求
int _wrap_CThostFtdcMdApi_ReqUserLogin(QCTPMdSpi* pMdApi, CThostFtdcReqUserLoginField* pReqUserLoginField, int nRequestID)
{
int ret = pMdApi->ReqUserLogin(pReqUserLoginField, nRequestID);
printf("req_user_login: %d", ret);
return ret;
}
// 登出请求
int _wrap_CThostFtdcMdApi_ReqUserLogout(QCTPMdSpi* pMdApi, CThostFtdcUserLogoutField* pUserLogout, int nRequestID)
{
return pMdApi->ReqUserLogout(pUserLogout, nRequestID);
}
// 请求查询组播合约
int _wrap_CThostFtdcMdApi_ReqQryMulticastInstrument(QCTPMdSpi* pMdApi, CThostFtdcQryMulticastInstrumentField* pQryMulticastInstrument, int nRequestID)
{
return pMdApi->ReqQryMulticastInstrument(pQryMulticastInstrument, nRequestID);
}
#ifdef __cplusplus
}
#endif
// 当客户端与交易后台建立起通信连接时(还未登录前),该方法被调用。
extern "C" void wrapMdOnFrontConnected(uintptr_t);
void QCTPMdSpi::OnFrontConnected()
{
wrapMdOnFrontConnected(gUserApi);
}
// 当客户端与交易后台通信连接断开时,该方法被调用。当发生这个情况后,API会自动重新连接,客户端可不做处理。
///@param nReason 错误原因
/// 0x1001 网络读失败
/// 0x1002 网络写失败
/// 0x2001 接收心跳超时
/// 0x2002 发送心跳失败
/// 0x2003 收到错误报文
extern "C" void wrapMdOnFrontDisconnected(uintptr_t, int);
void QCTPMdSpi::OnFrontDisconnected(int nReason)
{
wrapMdOnFrontDisconnected(gUserApi, nReason);
}
// 心跳超时警告。当长时间未收到报文时,该方法被调用。
///@param nTimeLapse 距离上次接收报文的时间
extern "C" void wrapMdOnHeartBeatWarning(uintptr_t, int);
void QCTPMdSpi::OnHeartBeatWarning(int nTimeLapse)
{
wrapMdOnHeartBeatWarning(gUserApi, nTimeLapse);
}
// 登录请求响应
extern "C" void wrapMdOnRspUserLogin(uintptr_t, CThostFtdcRspUserLoginField*, CThostFtdcRspInfoField*, int, bool);
void QCTPMdSpi::OnRspUserLogin(CThostFtdcRspUserLoginField* pRspUserLogin, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast)
{
wrapMdOnRspUserLogin(gUserApi, pRspUserLogin, pRspInfo, nRequestID, bIsLast);
}
// 登出请求响应
extern "C" void wrapMdOnRspUserLogout(uintptr_t, CThostFtdcUserLogoutField*, CThostFtdcRspInfoField*, int, bool);
void QCTPMdSpi::OnRspUserLogout(CThostFtdcUserLogoutField* pUserLogout, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast)
{
wrapMdOnRspUserLogout(gUserApi, pUserLogout, pRspInfo, nRequestID, bIsLast);
}
// 请求查询组播合约响应
extern "C" void wrapMdOnRspQryMulticastInstrument(uintptr_t, CThostFtdcMulticastInstrumentField*, CThostFtdcRspInfoField*, int, bool);
void QCTPMdSpi::OnRspQryMulticastInstrument(CThostFtdcMulticastInstrumentField* pMulticastInstrument, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast)
{
wrapMdOnRspQryMulticastInstrument(gUserApi, pMulticastInstrument, pRspInfo, nRequestID, bIsLast);
}
// 错误应答
extern "C" void wrapMdOnRspError(uintptr_t, CThostFtdcRspInfoField*, int, bool);
void QCTPMdSpi::OnRspError(CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast)
{
wrapMdOnRspError(gUserApi, pRspInfo, nRequestID, bIsLast);
}
// 订阅行情应答
extern "C" void wrapMdOnRspSubMarketData(uintptr_t, CThostFtdcSpecificInstrumentField*, CThostFtdcRspInfoField*, int, bool);
void QCTPMdSpi::OnRspSubMarketData(CThostFtdcSpecificInstrumentField* pSpecificInstrument, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast)
{
wrapMdOnRspSubMarketData(gUserApi, pSpecificInstrument, pRspInfo, nRequestID, bIsLast);
}
// 取消订阅行情应答
extern "C" void wrapMdOnRspUnSubMarketData(uintptr_t, CThostFtdcSpecificInstrumentField*, CThostFtdcRspInfoField*, int, bool);
void QCTPMdSpi::OnRspUnSubMarketData(CThostFtdcSpecificInstrumentField* pSpecificInstrument, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast)
{
wrapMdOnRspUnSubMarketData(gUserApi, pSpecificInstrument, pRspInfo, nRequestID, bIsLast);
}
// 订阅询价应答
extern "C" void wrapMdOnRspSubForQuoteRsp(uintptr_t, CThostFtdcSpecificInstrumentField*, CThostFtdcRspInfoField*, int, bool);
void QCTPMdSpi::OnRspSubForQuoteRsp(CThostFtdcSpecificInstrumentField* pSpecificInstrument, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast)
{
wrapMdOnRspSubForQuoteRsp(gUserApi, pSpecificInstrument, pRspInfo, nRequestID, bIsLast);
}
// 取消订阅询价应答
extern "C" void wrapMdOnRspUnSubForQuoteRsp(uintptr_t, CThostFtdcSpecificInstrumentField*, CThostFtdcRspInfoField*, int, bool);
void QCTPMdSpi::OnRspUnSubForQuoteRsp(CThostFtdcSpecificInstrumentField* pSpecificInstrument, CThostFtdcRspInfoField* pRspInfo, int nRequestID, bool bIsLast)
{
wrapMdOnRspUnSubForQuoteRsp(gUserApi, pSpecificInstrument, pRspInfo, nRequestID, bIsLast);
}
// 深度行情通知
extern "C" void wrapMdOnRtnDepthMarketData(uintptr_t, CThostFtdcDepthMarketDataField*);
void QCTPMdSpi::OnRtnDepthMarketData(CThostFtdcDepthMarketDataField* pDepthMarketData)
{
wrapMdOnRtnDepthMarketData(gUserApi, pDepthMarketData);
}
// 询价通知
extern "C" void wrapMdOnRtnForQuoteRsp(uintptr_t, CThostFtdcForQuoteRspField*);
void QCTPMdSpi::OnRtnForQuoteRsp(CThostFtdcForQuoteRspField* pForQuoteRsp)
{
wrapMdOnRtnForQuoteRsp(gUserApi, pForQuoteRsp);
}
QCTPMdSpi::QCTPMdSpi(CThostFtdcMdApi* pUserApi)
{
this->pUserApi = pUserApi;
}
QCTPMdSpi::QCTPMdSpi(CThostFtdcMdApi* pUserApi, uintptr_t gUserApi)
{
this->pUserApi = pUserApi;
this->gUserApi = gUserApi;
}
uintptr_t _wrap_CThostFtdcMdApi_DestroyUserMdApi(QCTPMdSpi* pMdApi)
{
delete (pMdApi);
return 0;
}
// 获取API的版本信息
///@retrun 获取到的版本号
const char* QCTPMdSpi::GetApiVersion()
{
return this->pUserApi->GetApiVersion();
}
// 删除接口对象本身
///@remark 不再使用本接口对象时,调用该函数删除接口对象
void QCTPMdSpi::Release()
{
this->pUserApi->RegisterSpi(NULL);
return this->pUserApi->Release();
}
// 初始化
///@remark 初始化运行环境,只有调用后,接口才开始工作
void QCTPMdSpi::Init()
{
this->pUserApi->Init();
}
// 等待接口线程结束运行
///@return 线程退出代码
int QCTPMdSpi::Join()
{
return this->pUserApi->Join();
}
// 获取当前交易日
///@retrun 获取到的交易日
///@remark 只有登录成功后,才能得到正确的交易日
const char* QCTPMdSpi::GetTradingDay()
{
return this->pUserApi->GetTradingDay();
}
// 注册前置机网络地址
///@param pszFrontAddress:前置机网络地址。
///@remark 网络地址的格式为:“protocol://ipaddress:port”,如:”tcp://127.0.0.1:17001”。
///@remark “tcp”代表传输协议,“127.0.0.1”代表服务器地址。”17001”代表服务器端口号。
void QCTPMdSpi::RegisterFront(char* pszFrontAddress)
{
this->pUserApi->RegisterFront(pszFrontAddress);
}
// 注册名字服务器网络地址
///@param pszNsAddress:名字服务器网络地址。
///@remark 网络地址的格式为:“protocol://ipaddress:port”,如:”tcp://127.0.0.1:12001”。
///@remark “tcp”代表传输协议,“127.0.0.1”代表服务器地址。”12001”代表服务器端口号。
///@remark RegisterNameServer优先于RegisterFront
void QCTPMdSpi::RegisterNameServer(char* pszNsAddress)
{
this->pUserApi->RegisterNameServer(pszNsAddress);
}
// 注册名字服务器用户信息
///@param pFensUserInfo:用户信息。
void QCTPMdSpi::RegisterFensUserInfo(CThostFtdcFensUserInfoField* pFensUserInfo)
{
this->pUserApi->RegisterFensUserInfo(pFensUserInfo);
}
// 注册回调接口
///@param pSpi 派生自回调接口类的实例
void QCTPMdSpi::RegisterSpi(CThostFtdcMdSpi* pSpi)
{
this->pUserApi->RegisterSpi(pSpi);
}
// 订阅行情。
///@param ppInstrumentID 合约ID
///@param nCount 要订阅/退订行情的合约个数
///@remark
int QCTPMdSpi::SubscribeMarketData(char** ppInstrumentID, int nCount)
{
return this->pUserApi->SubscribeMarketData(ppInstrumentID, nCount);
}
// 退订行情。
///@param ppInstrumentID 合约ID
///@param nCount 要订阅/退订行情的合约个数
///@remark
int QCTPMdSpi::UnSubscribeMarketData(char** ppInstrumentID, int nCount)
{
return this->pUserApi->UnSubscribeMarketData(ppInstrumentID, nCount);
}
// 订阅询价。
///@param ppInstrumentID 合约ID
///@param nCount 要订阅/退订行情的合约个数
///@remark
int QCTPMdSpi::SubscribeForQuoteRsp(char** ppInstrumentID, int nCount)
{
return this->pUserApi->SubscribeForQuoteRsp(ppInstrumentID, nCount);
}
// 退订询价。
///@param ppInstrumentID 合约ID
///@param nCount 要订阅/退订行情的合约个数
///@remark
int QCTPMdSpi::UnSubscribeForQuoteRsp(char** ppInstrumentID, int nCount)
{
return this->pUserApi->UnSubscribeForQuoteRsp(ppInstrumentID, nCount);
}
// 用户登录请求
int QCTPMdSpi::ReqUserLogin(CThostFtdcReqUserLoginField* pReqUserLoginField, int nRequestID)
{
return this->pUserApi->ReqUserLogin(pReqUserLoginField, nRequestID);
}
// 登出请求
int QCTPMdSpi::ReqUserLogout(CThostFtdcUserLogoutField* pUserLogout, int nRequestID)
{
return this->pUserApi->ReqUserLogout(pUserLogout, nRequestID);
}
// 请求查询组播合约
int QCTPMdSpi::ReqQryMulticastInstrument(CThostFtdcQryMulticastInstrumentField* pQryMulticastInstrument, int nRequestID)
{
return this->pUserApi->ReqQryMulticastInstrument(pQryMulticastInstrument, nRequestID);
}