forked from jasonweiyi/XAPI2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWAPIWrapperCpp.h
More file actions
245 lines (179 loc) · 8.5 KB
/
WAPIWrapperCpp.h
File metadata and controls
245 lines (179 loc) · 8.5 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
#ifndef _WAPIWRAPPERCPP_H
#define _WAPIWRAPPERCPP_H
#include <windows.h>
#include <comutil.h>
#ifdef WAPIWRAPPERCPP_EXPORTS
#define WAPIWRAPPERCPP_EXP __declspec(dllexport)
#else
#define WAPIWRAPPERCPP_EXP __declspec(dllimport)
#endif
//控件未注册错误
const LONG noRegErr = -1;
enum ErrMsgLang //错误信息语言
{
eENG = 0, ///< 英语
eCHN, ///< 中文
};
class WAPIWRAPPERCPP_EXP WindData
{
public:
VARIANT data; ///< 数据
VARIANT codes; ///< Code列表
VARIANT fields; ///< 指标列表
VARIANT times; ///< 时间列表
LONG errorCode; ///< 错误码
public:
WindData();
~WindData();
VOID InitWindData();
VOID ClearWindData();
//获取错误信息
LPCWSTR GetErrorMsg() const;
//日期转化函数(需要delete)
static WCHAR* DateToString(DATE date, LPCWSTR strFormat = L"%Y-%m-%d");
static VOID FreeString(WCHAR*& pStr);
//////////////////////////////////////////////////////////////////////////
//数据使用
INT GetCodesLength() const;
INT GetFieldsLength() const;
INT GetTimesLength() const;
LPCWSTR GetCodeByIndex(int index) const;
LPCWSTR GetFieldsByIndex(int index) const;
BOOL GetTimeByIndex(int index, WCHAR timeBuffer[], int& length) const;
DATE GetTimeByIndex(int index) const;
//获取数据查询接口OneData
BOOL GetDataItem(int timeIndex, int codesIndex, int fieldsIndex, VARIANT& outItem) const;
//获取日期列表
const DATE* GetTDaysInfo(LONG& lDateCount) const;
//////////////////////////////////////////////////////////////////////////
//交易使用
INT GetRecordCount() const;
//获取交易接口OneData
BOOL GetTradeItem(int recordIndex, int fieldsIndex, VARIANT& outItem) const;
//获取登录ID
LONG GetLogonID() const;
//获取Order请求Id
LONG GetOrderRequestID() const;
//获取OrderNumber
LPCWSTR GetOrderNumber(int recordIndex = 0) const;
};
// 回调函数定义
typedef LONG (WINAPI *WsqCallBack)(ULONGLONG reqId, const WindData &windData);
typedef LONG (WINAPI *TradeCallBack)(LONG LogonID, const WindData &windData);
// 此类是从 WAPIWrapperCpp.dll 导出的
class WAPIWRAPPERCPP_EXP CWAPIWrapperCpp {
public:
//基本函数
//////////////////////////////////////////////////////////////////////////
//Wind接口启动函数
static LONG start(LPCWSTR options = NULL, LPCWSTR options2 = NULL, LONG timeout = 5000);
//Wind接口终止函数
static LONG stop();
//判断连接状态
static LONG isconnected();
//若 requestId 为0 取消所有请求;否则只取消给定ID号的请求
static VOID cancelRequest(ULONGLONG requestId);
//取消所有请求
static VOID cancelAllRequest();
//获取错误码相应的错误信息
static BOOL getErrorMsg(LONG errCode, ErrMsgLang lang, WCHAR msg[], int& /*inout*/msgLength);
//////////////////////////////////////////////////////////////////////////
//数据函数
//////////////////////////////////////////////////////////////////////////
//多值函数wsd,获得日期序列
static LONG wsd(WindData& outWindData, LPCWSTR windCodes, LPCWSTR fields, LPCWSTR startTime = NULL, LPCWSTR endTime = NULL, LPCWSTR options = NULL);
//多值函数wss,获得历史快照
static LONG wss(WindData& outWindData, LPCWSTR windCodes, LPCWSTR fields, LPCWSTR options = NULL);
//多值函数wsi,获得分钟序列
static LONG wsi(WindData& outWindData, LPCWSTR windCodes, LPCWSTR fields, LPCWSTR startTime, LPCWSTR endTime, LPCWSTR options = NULL);
//多值函数wst,获得日内跳价
static LONG wst(WindData& outWindData, LPCWSTR windCodes, LPCWSTR fields, LPCWSTR startTime, LPCWSTR endTime, LPCWSTR options = NULL);
//多值函数wsq,获得实时行情
//非订阅模式,取一次性快照数据
static LONG wsq(WindData& outWindData, LPCWSTR windCodes, LPCWSTR fields, LPCWSTR options = NULL);
//订阅模式,订阅实时数据,数据通过回调函数返回
static LONG wsq(ULONGLONG &reqId, LPCWSTR windCodes, LPCWSTR fields, WsqCallBack callBack, LPCWSTR options = NULL, BOOL updateAllFields = FALSE);
//多值函数tdq,获得实时行情
//订阅模式td,订阅实时数据,数据通过回调函数返回
static LONG tdq(ULONGLONG &reqId, LPCWSTR windCodes, LPCWSTR fields, WsqCallBack callBack, LPCWSTR options = NULL, BOOL updateAllFields = FALSE);
//多值函数bbq,获得实时行情
//非订阅模式,取一次性快照数据
static LONG bbq(WindData& outWindData, LPCWSTR windCodes, LPCWSTR fields, LPCWSTR options = NULL);
//订阅模式,订阅实时数据,数据通过回调函数返回
static LONG bbq(ULONGLONG &reqId, LPCWSTR windCodes, LPCWSTR fields, WsqCallBack callBack, LPCWSTR options = NULL);
//多值函数wset,获得指定数据集
static LONG wset(WindData& outWindData, LPCWSTR reportName, LPCWSTR options = NULL);
//多值函数edb,获得经济数据
static LONG edb(WindData& outWindData, LPCWSTR windCodes, LPCWSTR startTime = NULL, LPCWSTR endTime = NULL, LPCWSTR options = NULL);
//组合报表函数
static LONG wpf(WindData& outWindData, LPCWSTR portfolioName, LPCWSTR viewName, LPCWSTR options = NULL);
//组合上传函数
static LONG wupf(WindData& outWindData, LPCWSTR portfolioName, LPCWSTR tradeDate, LPCWSTR windCodes, LPCWSTR quantity, LPCWSTR costPrice, LPCWSTR options = NULL);
//证劵筛选函数
static LONG weqs(WindData& outWindData, LPCWSTR planName, LPCWSTR options = NULL);
//日历日、工作日、交易日的日期序列函数
static LONG tdays(WindData& outWindData, LPCWSTR startTime, LPCWSTR endTime, LPCWSTR options = NULL);
//日历日、工作日、交易日的日期偏移计算
static LONG tdaysoffset(DATE& outDate, LPCWSTR startTime, LONG offset, LPCWSTR options = NULL);
//日历日、工作日、交易日的日期天数计算
static LONG tdayscount(LONG& outCount, LPCWSTR startTime, LPCWSTR endTime, LPCWSTR options = NULL);
//////////////////////////////////////////////////////////////////////////
//交易函数
//////////////////////////////////////////////////////////////////////////
//交易账号登陆
static LONG tlogon(WindData& outWindData, LPCWSTR brokerID, LPCWSTR departmentID, LPCWSTR accountID, LPCWSTR password, LPCWSTR accountType, LPCWSTR options = NULL,TradeCallBack callBack=0);
//交易账号登出, 0:登出全部已登录的账号
static LONG tlogout(INT longId=0);
//下单
static LONG torder(WindData& outWindData, LPCWSTR windCodes, LPCWSTR tradeSide, LPCWSTR orderPrice, LPCWSTR orderVolume, LPCWSTR options = NULL);
static LONG torder(LONG& reqId, LPCWSTR windCodes, LPCWSTR tradeSide, DOUBLE orderPrice, LONG orderVolume, LPCWSTR options = NULL, WCHAR** pErrosMsg = NULL);
//备兑取消
//备兑
static LONG tcovered(WindData& outWindData, LPCWSTR windCodes, LPCWSTR tradeSide, LPCWSTR orderVolume, LPCWSTR options = NULL);
static LONG tcovered(LONG& reqId, LPCWSTR windCodes, LPCWSTR tradeSide, LONG orderVolume, LPCWSTR options = NULL, WCHAR** pErrosMsg = NULL);
//交易情况查询
static LONG tquery(WindData& outWindData, LPCWSTR qryCode, LPCWSTR options = NULL);
//撤单
static LONG tcancel(LPCWSTR orderNumber, LPCWSTR options = NULL);
//////////////////////////////////////////////////////////////////////////
//回测函数
//////////////////////////////////////////////////////////////////////////
//回测开始
static LONG bktstart(WindData& outWindData, LPCWSTR strategyName, LPCWSTR startDate, LPCWSTR endDate, LPCWSTR options = NULL);
//回测查询
static LONG bktquery(WindData& outWindData, LPCWSTR qrycode, LPCWSTR qrytime, LPCWSTR options = NULL);
//回测下单
static LONG bktorder(WindData& outWindData, LPCWSTR tradeTime, LPCWSTR securityCode, LPCWSTR tradeSide, LPCWSTR tradeVol, LPCWSTR options = NULL);
//回测结束
static LONG bktend(WindData& outWindData, LPCWSTR options);
//查看回测状态
static LONG bktstatus(WindData& outWindData, LPCWSTR options);
//回测概要
static LONG bktsummary(WindData& outWindData, LPCWSTR bktID, LPCWSTR view, LPCWSTR options);
//回测删除
static LONG bktdelete(WindData& outWindData, LPCWSTR bktID, LPCWSTR options);
//返回策略列表
static LONG bktstrategy(WindData& outWindData, LPCWSTR options);
//////////////////////////////////////////////////////////////////////////
//app应用相关
/**
* @brief 第三方开发App进行权限认证
* @param WindData & outWindData: 返回数据
* @param LPCTSTR appKey: 第三方开发的app从大奖章网站获取唯一认证的Id
* @param LPCTSTR appSecret:第三方开发app的秘钥
* @param LPCTSTR options:保留参数
* @return LONG: 成功\错误码
*/
static LONG wappAuth(WindData& outWindData, LPCTSTR appKey, LPCTSTR appSecret, LPCTSTR options);
/**
* @brief 第三方开发App和大奖章进行通讯函数
* @param WindData & outWindData:返回数据
* @param LPCTSTR type_id: communication type,include:message_put; message_get; app_version; app_fps; app_data_get; app_data_put
* @param LPCTSTR message: communication content
* @param LPCTSTR options: 保留参数
* @return LONG: 成功\错误码
*/
static LONG wappMessage(WindData& outWindData, LPCTSTR type_id, LPCTSTR message, LPCTSTR options);
//////////////////////////////////////////////////////////////////////////
};
#endif