Repository navigation
Expand file tree
/
Copy pathxttype.py
More file actions
361 lines (337 loc) · 13.1 KB
/
Copy pathxttype.py
File metadata and controls
361 lines (337 loc) · 13.1 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
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
#coding=utf-8
from . import xtconstant
"""
定义Python的数据结构,给Python策略使用
包含股票+信用
"""
class StockAccount(object):
"""
定义证券账号类, 用于证券账号的报撤单等
"""
def __new__(cls, account_id, account_type = 'STOCK'):
"""
:param account_id: 资金账号
:return: 若资金账号不为字符串,返回类型错误
"""
if not isinstance(account_id, str):
return u"资金账号必须为字符串类型"
return super(StockAccount, cls).__new__(cls)
def __init__(self, account_id, account_type = 'STOCK'):
"""
:param account_id: 资金账号
"""
account_type = account_type.upper()
for int_type, str_type in xtconstant.ACCOUNT_TYPE_DICT.items():
if account_type == str_type:
self.account_type = int_type
self.account_id = account_id
return
raise Exception("不支持的账号类型:{}!".format(account_type))
class XtAsset(object):
"""
迅投股票账号资金结构
"""
def __init__(self, account_id, cash, frozen_cash, market_value, total_asset):
"""
:param account_id: 资金账号
:param cash: 可用
:param frozen_cash: 冻结
:param market_value: 持仓市值
:param total_asset: 总资产
"""
self.account_type = xtconstant.SECURITY_ACCOUNT
self.account_id = account_id
self.cash = cash
self.frozen_cash = frozen_cash
self.market_value = market_value
self.total_asset = total_asset
class XtOrder(object):
"""
迅投股票委托结构
"""
def __init__(self, account_id, stock_code,
order_id, order_sysid, order_time, order_type, order_volume,
price_type, price, traded_volume, traded_price,
order_status, status_msg, strategy_name, order_remark, direction, offset_flag):
"""
:param account_id: 资金账号
:param stock_code: 证券代码, 例如"600000.SH"
:param order_id: 委托编号
:param order_sysid: 柜台编号
:param order_time: 报单时间
:param order_type: 委托类型, 23:买, 24:卖
:param order_volume: 委托数量, 股票以'股'为单位, 债券以'张'为单位
:param price_type: 报价类型, 详见帮助手册
:param price: 报价价格,如果price_type为指定价, 那price为指定的价格,否则填0
:param traded_volume: 成交数量, 股票以'股'为单位, 债券以'张'为单位
:param traded_price: 成交均价
:param order_status: 委托状态
:param status_msg: 委托状态描述, 如废单原因
:param strategy_name: 策略名称
:param order_remark: 委托备注
:param direction: 多空, 股票不需要
:param offset_flag: 交易操作,用此字段区分股票买卖,期货开、平仓,期权买卖等
"""
self.account_type = xtconstant.SECURITY_ACCOUNT
self.account_id = account_id
self.stock_code = stock_code
self.order_id = order_id
self.order_sysid = order_sysid
self.order_time = order_time
self.order_type = order_type
self.order_volume = order_volume
self.price_type = price_type
self.price = price
self.traded_volume = traded_volume
self.traded_price = traded_price
self.order_status = order_status
self.status_msg = status_msg
self.strategy_name = strategy_name
self.order_remark = order_remark
self.direction = direction
self.offset_flag = offset_flag
class XtTrade(object):
"""
迅投股票成交结构
"""
def __init__(self, account_id, stock_code,
order_type, traded_id, traded_time, traded_price, traded_volume, traded_amount,
order_id, order_sysid, strategy_name, order_remark, direction, offset_flag):
"""
:param account_id: 资金账号
:param stock_code: 证券代码, 例如"600000.SH"
:param order_type: 委托类型
:param traded_id: 成交编号
:param traded_time: 成交时间
:param traded_price: 成交均价
:param traded_volume: 成交数量, 股票以'股'为单位, 债券以'张'为单位
:param traded_amount: 成交金额
:param order_id: 委托编号
:param order_sysid: 柜台编号
:param strategy_name: 策略名称
:param order_remark: 委托备注
:param direction: 多空, 股票不需要
:param offset_flag: 交易操作,用此字段区分股票买卖,期货开、平仓,期权买卖等
"""
self.account_type = xtconstant.SECURITY_ACCOUNT
self.account_id = account_id
self.order_type = order_type
self.stock_code = stock_code
self.traded_id = traded_id
self.traded_time = traded_time
self.traded_price = traded_price
self.traded_volume = traded_volume
self.traded_amount = traded_amount
self.order_id = order_id
self.order_sysid = order_sysid
self.strategy_name = strategy_name
self.order_remark = order_remark
self.direction = direction
self.offset_flag = offset_flag
class XtPosition(object):
"""
迅投股票持仓结构
"""
def __init__(self, account_id, stock_code,
volume, can_use_volume, open_price, market_value,
frozen_volume, on_road_volume, yesterday_volume, avg_price, direction):
"""
:param account_id: 资金账号
:param stock_code: 证券代码, 例如"600000.SH"
:param volume: 持仓数量,股票以'股'为单位, 债券以'张'为单位
:param can_use_volume: 可用数量, 股票以'股'为单位, 债券以'张'为单位
:param open_price: 开仓价
:param market_value: 市值
:param frozen_volume: 冻结数量
:param on_road_volume: 在途股份
:param yesterday_volume: 昨夜拥股
:param avg_price: 成本价
:param direction: 多空, 股票不需要
"""
self.account_type = xtconstant.SECURITY_ACCOUNT
self.account_id = account_id
self.stock_code = stock_code
self.volume = volume
self.can_use_volume = can_use_volume
self.open_price = open_price
self.market_value = market_value
self.frozen_volume = frozen_volume
self.on_road_volume = on_road_volume
self.yesterday_volume = yesterday_volume
self.avg_price = avg_price
self.direction = direction
class XtOrderError(object):
"""
迅投股票委托失败结构
"""
def __init__(self, account_id, order_id,
error_id=None, error_msg=None,
strategy_name=None, order_remark=None):
"""
:param account_id: 资金账号
:param order_id: 订单编号
:param error_id: 报单失败错误码
:param error_msg: 报单失败具体信息
:param strategy_name: 策略名称
:param order_remark: 委托备注
"""
self.account_type = xtconstant.SECURITY_ACCOUNT
self.account_id = account_id
self.order_id = order_id
self.error_id = error_id
self.error_msg = error_msg
self.strategy_name = strategy_name
self.order_remark = order_remark
class XtCancelError(object):
"""
迅投股票委托撤单失败结构
"""
def __init__(self, account_id, order_id, market, order_sysid,
error_id=None, error_msg=None):
"""
:param account_id: 资金账号
:param order_id: 订单编号
:param market: 交易市场 0:上海 1:深圳
:param order_sysid: 柜台委托编号
:param error_id: 撤单失败错误码
:param error_msg: 撤单失败具体信息
"""
self.account_type = xtconstant.SECURITY_ACCOUNT
self.account_id = account_id
self.order_id = order_id
self.market = market
self.order_sysid = order_sysid
self.error_id = error_id
self.error_msg = error_msg
class XtOrderResponse(object):
"""
迅投异步下单接口对应的委托反馈
"""
def __init__(self, account_id, order_id, strategy_name, order_remark, error_msg, seq):
"""
:param account_id: 资金账号
:param order_id: 订单编号
:param strategy_name: 策略名称
:param order_remark: 委托备注
:param seq: 下单请求序号
"""
self.account_type = xtconstant.SECURITY_ACCOUNT
self.account_id = account_id
self.order_id = order_id
self.strategy_name = strategy_name
self.order_remark = order_remark
self.error_msg = error_msg
self.seq = seq
class XtCancelOrderResponse(object):
"""
迅投异步委托撤单请求返回结构
"""
def __init__(self, account_id, cancel_result, order_id, order_sysid, seq, error_msg):
"""
:param account_id: 资金账号
:param cancel_result: 撤单结果
:param order_id: 订单编号
:param order_sysid: 柜台委托编号
:param seq: 撤单请求序号
:param error_msg: 撤单反馈信息
"""
self.account_type = xtconstant.SECURITY_ACCOUNT
self.account_id = account_id
self.cancel_result = cancel_result
self.order_id = order_id
self.order_sysid = order_sysid
self.seq = seq
self.error_msg = error_msg
class XtCreditOrder(XtOrder):
"""
迅投信用委托结构
"""
def __init__(self, account_id, stock_code,
order_id, order_time, order_type, order_volume,
price_type, price, traded_volume, traded_price,
order_status, status_msg, order_remark, contract_no):
"""
:param account_id: 资金账号
:param stock_code: 证券代码, 例如"600000.SH"
:param order_id: 委托编号
:param order_time: 报单时间
:param order_type: 委托类型, 23:买, 24:卖
:param order_volume: 委托数量, 股票以'股'为单位, 债券以'张'为单位
:param price_type: 报价类型, 详见帮助手册
:param price: 报价价格,如果price_type为指定价, 那price为指定的价格,否则填0
:param traded_volume: 成交数量, 股票以'股'为单位, 债券以'张'为单位
:param traded_price: 成交均价
:param order_status: 委托状态
:param status_msg: 委托状态描述, 如废单原因
:param order_remark: 委托备注
:param contract_no: 两融合同编号
"""
self.account_type = xtconstant.CREDIT_ACCOUNT
self.account_id = account_id
self.stock_code = stock_code
self.order_id = order_id
self.order_time = order_time
self.order_type = order_type
self.order_volume = order_volume
self.price_type = price_type
self.price = price
self.traded_volume = traded_volume
self.traded_price = traded_price
self.order_status = order_status
self.status_msg = status_msg
self.order_remark = order_remark
self.contract_no = contract_no
class XtCreditDeal(object):
"""
迅投信用成交结构
"""
def __init__(self, account_id, stock_code,
traded_id, traded_time, traded_price,
traded_volume, order_id, contract_no):
"""
:param account_id: 资金账号
:param stock_code: 证券代码, 例如"600000.SH"
:param traded_id: 成交编号
:param traded_time: 成交时间
:param traded_price: 成交均价
:param traded_volume: 成交数量, 股票以'股'为单位, 债券以'张'为单位
:param order_id: 委托编号
:param contract_no: 两融合同编号
"""
self.account_type = xtconstant.CREDIT_ACCOUNT
self.account_id = account_id
self.stock_code = stock_code
self.traded_id = traded_id
self.traded_time = traded_time
self.traded_price = traded_price
self.traded_volume = traded_volume
self.order_id = order_id
self.contract_no = contract_no
class XtAccountStatus(object):
"""
迅投账号状态结构
"""
def __init__(self, account_id, account_type, status):
"""
:param account_id: 资金账号
:param account_type: 账号状态
:param status: 账号状态,详细见账号状态定义
"""
self.account_type = account_type
self.account_id = account_id
self.status = status
class XtSmtAppointmentResponse(object):
"""
迅投约券相关异步接口的反馈
"""
def __init__(self, seq, success, msg, apply_id):
"""
:param seq: 异步请求序号
:param success: 申请是否成功
:param msg: 反馈信息
:param apply_id: 若申请成功返回资券申请编号
"""
self.seq = seq
self.success = success
self.msg = msg
self.apply_id = apply_id