forked from jasonweiyi/xapi_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypeConvert.cpp
More file actions
321 lines (297 loc) · 7.73 KB
/
TypeConvert.cpp
File metadata and controls
321 lines (297 loc) · 7.73 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
#include "stdafx.h"
#include "TypeConvert.h"
#include <stdlib.h>
#include <string.h>
#include "../include/ChinaStock.h"
/// 类似于OpenQuant FIX一样的效果,插件层简单,基本不要做怎么计算或处理
/// 对于一个单子的某个状态可能是这样的,新单,部分成交,完全成交
/// EmitAccept,EmitFill
/// OnRtnOrder,OnRtnTrade,如何转成Emit
/// EmitAccept是什么
///
/// 接口向外提供的回报可以分两种方案,ExecutionReport或委托回报与成交回报
/// OpenQuant中使用ExecutionReport问题是因为OQ自己有OrderManager,如果其它软件要看到委托和成交列表是没法得到的
/// 所以接口应当返回委托与成交回报
HedgeFlagType TSecurityFtdcHedgeFlagType_2_HedgeFlagType(TSecurityFtdcHedgeFlagType In)
{
switch (In)
{
//case SECURITY_FTDC_HF_Arbitrage:
// return HedgeFlagType::Arbitrage;
case SECURITY_FTDC_HF_Hedge:
return HedgeFlagType::Hedge;
case SECURITY_FTDC_HF_Speculation:
default:
return HedgeFlagType::Speculation;
}
}
TSecurityFtdcHedgeFlagType HedgeFlagType_2_TSecurityFtdcHedgeFlagType(HedgeFlagType In)
{
switch (In)
{
//case HedgeFlagType::Arbitrage:
// return SECURITY_FTDC_HF_Arbitrage;
case HedgeFlagType::Hedge:
return SECURITY_FTDC_HF_Hedge;
case HedgeFlagType::Speculation:
default:
return SECURITY_FTDC_HF_Speculation;
}
}
OpenCloseType TSecurityFtdcOffsetFlagType_2_OpenCloseType(TSecurityFtdcOffsetFlagType In)
{
switch (In)
{
case SECURITY_FTDC_OF_CloseToday:
return OpenCloseType::CloseToday;
case SECURITY_FTDC_OF_Close:
return OpenCloseType::Close;
case SECURITY_FTDC_OF_Open:
default:
return OpenCloseType::Open;
}
}
TSecurityFtdcOffsetFlagType OpenCloseType_2_TSecurityFtdcOffsetFlagType(OpenCloseType In)
{
switch (In)
{
case OpenCloseType::CloseToday:
return SECURITY_FTDC_OF_CloseToday;
case OpenCloseType::Close:
return SECURITY_FTDC_OF_Close;
case OpenCloseType::Open:
default:
return SECURITY_FTDC_OF_Open;
}
}
TSecurityFtdcDirectionType OrderSide_2_TSecurityFtdcDirectionType(OrderSide In)
{
if (In == OrderSide::Sell)
return SECURITY_FTDC_D_Sell;
return SECURITY_FTDC_D_Buy;
}
OrderSide TSecurityFtdcDirectionType_2_OrderSide(TSecurityFtdcDirectionType In)
{
if (In == SECURITY_FTDC_D_Sell)
return OrderSide::Sell;
return OrderSide::Buy;
}
PositionSide TSecurityFtdcPosiDirectionType_2_PositionSide(TSecurityFtdcPosiDirectionType In)
{
if (In == SECURITY_FTDC_PD_Short)
return PositionSide::Short;
return PositionSide::Long;
}
PositionSide TradeField_2_PositionSide(TradeField* pIn)
{
//if (pIn->OpenClose == OpenCloseType::Open)
//{
// if (pIn->Side == OrderSide::Buy)
// return PositionSide::Long;
// return PositionSide::Short;
//}
//else
//{
// if (pIn->Side == OrderSide::Buy)
// return PositionSide::Short;
// return PositionSide::Long;
//}
return PositionSide::Long;
}
TSecurityFtdcOrderPriceTypeType OrderType_2_TSecurityFtdcOrderPriceTypeType(OrderType In)
{
switch (In)
{
case Market:
return SECURITY_FTDC_OPT_AnyPrice;
case Stop:
return SECURITY_FTDC_OPT_AnyPrice;
case Limit:
return SECURITY_FTDC_OPT_LimitPrice;
case StopLimit:
return SECURITY_FTDC_OPT_LimitPrice;
case MarketOnClose:
return SECURITY_FTDC_OPT_AnyPrice;
case TrailingStop:
return SECURITY_FTDC_OPT_AnyPrice;
case TrailingStopLimit:
return SECURITY_FTDC_OPT_LimitPrice;
default:
return SECURITY_FTDC_OPT_LimitPrice;
}
}
OrderStatus CSecurityFtdcOrderField_2_OrderStatus(CSecurityFtdcOrderField* pIn)
{
switch (pIn->OrderStatus)
{
case SECURITY_FTDC_OST_Canceled:
if (pIn->OrderSubmitStatus == SECURITY_FTDC_OSS_InsertRejected)
return OrderStatus::Rejected;
return OrderStatus::Cancelled;
case SECURITY_FTDC_OST_Unknown:
// 如果是撤单,也有可能出现这一条,如何过滤?
if (pIn->OrderSubmitStatus == SECURITY_FTDC_OSS_InsertSubmitted)
return OrderStatus::New;
default:
if (pIn->VolumeTotal == 0)
return OrderStatus::Filled;
else if (pIn->VolumeTotal == pIn->VolumeTotalOriginal)
return OrderStatus::New;
else
return OrderStatus::PartiallyFilled;
}
}
OrderType CSecurityFtdcOrderField_2_OrderType(CSecurityFtdcOrderField* pIn)
{
switch (pIn->OrderPriceType)
{
case SECURITY_FTDC_OPT_AnyPrice:
return OrderType::Market;
case SECURITY_FTDC_OPT_LimitPrice:
return OrderType::Limit;
default:
return OrderType::Limit;
}
}
TimeInForce CSecurityFtdcOrderField_2_TimeInForce(CSecurityFtdcOrderField* pIn)
{
switch (pIn->TimeCondition)
{
case SECURITY_FTDC_TC_GFD:
return TimeInForce::Day;
case SECURITY_FTDC_TC_IOC:
switch (pIn->VolumeCondition)
{
case SECURITY_FTDC_VC_AV:
return TimeInForce::IOC;
case SECURITY_FTDC_VC_CV:
return TimeInForce::FOK;
default:
return TimeInForce::IOC;
}
default:
return TimeInForce::Day;
}
}
ExecType CSecurityFtdcOrderField_2_ExecType(CSecurityFtdcOrderField* pIn)
{
switch (pIn->OrderStatus)
{
case SECURITY_FTDC_OST_Canceled:
if (pIn->OrderSubmitStatus == SECURITY_FTDC_OSS_InsertRejected)
return ExecType::ExecRejected;
return ExecType::ExecCancelled;
case SECURITY_FTDC_OST_Unknown:
// 如果是撤单,也有可能出现这一条,如何过滤?
if (pIn->OrderSubmitStatus == SECURITY_FTDC_OSS_InsertSubmitted)
return ExecType::ExecNew;
case SECURITY_FTDC_OST_AllTraded:
case SECURITY_FTDC_OST_PartTradedQueueing:
return ExecType::ExecTrade;
default:
return ExecType::ExecNew;
}
}
PutCall CSecurityFtdcInstrumentField_2_PutCall(CSecurityFtdcInstrumentField* pIn)
{
if (strlen(pIn->InstrumentID) == 8)
{
if (pIn->ExchangeInstID[6] == 'C')
{
return PutCall::Call;
}
}
return PutCall::Put;
}
InstrumentType CSecurityFtdcInstrumentField_2_InstrumentType(CSecurityFtdcInstrumentField* pIn)
{
switch (pIn->ProductClass)
{
case SECURITY_FTDC_PC_Futures:
return InstrumentType::Future;
case SECURITY_FTDC_PC_Options:
return InstrumentType::Option;
case SECURITY_FTDC_PC_Combination:
return InstrumentType::MultiLeg;
case SECURITY_FTDC_PC_EFP:
return InstrumentType::Future;
case SECURITY_FTDC_PC_ETF:
return InstrumentType::ETF;
case SECURITY_FTDC_PC_ETFPurRed:
return InstrumentType::ETF;
default:
if (strlen(pIn->InstrumentID) == 8)
{
return InstrumentType::Option;
}
if (pIn->ExchangeID[1] == 'Z')
{
return InstrumentID_2_InstrumentType_SZE(atoi(pIn->InstrumentID));
}
else
{
return InstrumentID_2_InstrumentType_SSE(atoi(pIn->InstrumentID));
}
}
}
PriceType CSecurityFtdcInstrumentField_2_PriceTick(CSecurityFtdcInstrumentField* pIn)
{
if (pIn->PriceTick != 0)
return pIn->PriceTick;
// 期权为0.001
if (strlen(pIn->InstrumentID) == 8)
{
return 0.001;
}
if (pIn->ExchangeID[1] == 'Z')
{
return InstrumentID_2_PriceTick_SZE(atoi(pIn->InstrumentID));
}
else
{
return InstrumentID_2_PriceTick_SSE(atoi(pIn->InstrumentID));
}
}
IdCardType TSecurityFtdcIdCardTypeType_2_IdCardType(TSecurityFtdcIdCardTypeType In)
{
switch (In)
{
case SECURITY_FTDC_ICT_EID:
return IdCardType::EID;
case SECURITY_FTDC_ICT_IDCard:
return IdCardType::IDCard;
case SECURITY_FTDC_ICT_OfficerIDCard:
return IdCardType::OfficerIDCard;
case SECURITY_FTDC_ICT_PoliceIDCard:
return IdCardType::PoliceIDCard;
case SECURITY_FTDC_ICT_SoldierIDCard:
return IdCardType::SoldierIDCard;
case SECURITY_FTDC_ICT_HouseholdRegister:
return IdCardType::HouseholdRegister;
case SECURITY_FTDC_ICT_Passport:
return IdCardType::Passport;
case SECURITY_FTDC_ICT_TaiwanCompatriotIDCard:
return IdCardType::TaiwanCompatriotIDCard;
case SECURITY_FTDC_ICT_HomeComingCard:
return IdCardType::HomeComingCard;
case SECURITY_FTDC_ICT_LicenseNo:
return IdCardType::LicenseNo;
case SECURITY_FTDC_ICT_TaxNo:
return IdCardType::TaxNo;
case SECURITY_FTDC_ICT_OtherCard:
default:
return IdCardType::OtherCard;
}
}
ExchangeType TSecurityFtdcExchangeIDType_2_ExchangeType(TSecurityFtdcExchangeIDType In)
{
switch (In[1])
{
case 'S':
return ExchangeType::SSE;
case 'Z':
return ExchangeType::SZE;
default:
return ExchangeType::Undefined_;
}
}