@@ -14,12 +14,12 @@ class Order(object):
1414 __slots__ = ["account" , "id" , "order_id" , "parent_id" , "order_time" , "reason" , "trade_time" , "contract" , "action" ,
1515 "quantity" , "filled" , "_remaining" , "avg_fill_price" , "commission" , "realized_pnl" , "_status" ,
1616 "trail_stop_price" , "limit_price" , "aux_price" , "trailing_percent" , "percent_offset" , "action" ,
17- "order_type" , "time_in_force" , "outside_rth" , "attach_order " ]
17+ "order_type" , "time_in_force" , "outside_rth" , "order_legs " ]
1818
1919 def __init__ (self , account , contract , action , order_type , quantity , limit_price = None , aux_price = None ,
2020 trail_stop_price = None , trailing_percent = None , percent_offset = None , time_in_force = None ,
2121 outside_rth = None , filled = 0 , avg_fill_price = 0 , commission = None , realized_pnl = None ,
22- id = None , order_id = None , parent_id = None , order_time = None , trade_time = None , attach_order = None ):
22+ id = None , order_id = None , parent_id = None , order_time = None , trade_time = None , order_legs = None ):
2323 """
2424 - account: 订单所属的账户
2525 - id: 全局订单 id
@@ -45,7 +45,7 @@ def __init__(self, account, contract, action, order_type, quantity, limit_price=
4545 - contract: 合约对象
4646 - status: Order_Status 的枚举, 表示订单状态
4747 - remaining: 未成交的数量
48- - attach_order : 附加订单
48+ - order_legs : 附加订单
4949 """
5050
5151 self .id = id
@@ -72,7 +72,7 @@ def __init__(self, account, contract, action, order_type, quantity, limit_price=
7272 self .percent_offset = percent_offset
7373 self .order_time = order_time
7474 self .trade_time = trade_time
75- self .attach_order = attach_order
75+ self .order_legs = order_legs
7676
7777 def to_dict (self ):
7878 dct = {name : getattr (self , name ) for name in self .__slots__ if name not in ORDER_FIELDS_TO_IGNORE }
@@ -119,16 +119,16 @@ def __unicode__(self):
119119 return text_type (repr (self ))
120120
121121
122- class AttachOrder (object ):
122+ class OrderLeg (object ):
123123 """
124124 附加订单
125125 """
126126
127- def __init__ (self , attach_type = None , stop_loss_price = None , stop_loss_tif = None , stop_loss_rth = None ,
127+ def __init__ (self , type , stop_loss_price = None , stop_loss_tif = None , stop_loss_rth = None ,
128128 stop_loss_order_id = None , profit_taker_price = None , profit_taker_tif = None , profit_taker_rth = None ,
129129 profit_taker_order_id = None ):
130130 """
131- :param attach_type : 附加订单类型(仅限价单支持). PROFIT 止盈单类型, LOSS 止损单类型, BRACKETS 括号订单类型(止损和止盈)
131+ :param type : 附加订单类型(仅限价单支持). PROFIT 止盈单类型, LOSS 止损单类型, BRACKETS 括号订单类型(止损和止盈)
132132 :param stop_loss_price: 附加止损单价格
133133 :param stop_loss_tif: 附加止损单有效期. 'DAY'(当日有效)和'GTC'(取消前有效). 同 time_in_force 字段
134134 :param stop_loss_rth: 附加止损单是否允许盘前盘后交易(美股专属). True 允许, False 不允许. 同 outside_rth 字段
@@ -138,18 +138,20 @@ def __init__(self, attach_type=None, stop_loss_price=None, stop_loss_tif=None, s
138138 :param profit_taker_rth: 附加止盈单是否允许盘前盘后交易(美股专属). True 允许, False 不允许. 同 outside_rth 字段
139139 :param profit_taker_order_id: 附加止盈单号. 可以通过订单号接口获取, 如果传0或为空, 则服务器端会自动生成止盈单号
140140 """
141- self .attach_type = attach_type
142- self .stop_loss_price = stop_loss_price
143- self .stop_loss_tif = stop_loss_tif
144- self .stop_loss_rth = stop_loss_rth
145- self .stop_loss_order_id = stop_loss_order_id
146- self .profit_taker_price = profit_taker_price
147- self .profit_taker_tif = profit_taker_tif
148- self .profit_taker_rth = profit_taker_rth
149- self .profit_taker_order_id = profit_taker_order_id
141+ self .type = type
142+ if self .type == 'LOSS' or self .type == 'BRACKETS' :
143+ self .stop_loss_price = stop_loss_price
144+ self .stop_loss_tif = stop_loss_tif
145+ self .stop_loss_rth = stop_loss_rth
146+ self .stop_loss_order_id = stop_loss_order_id
147+ if self .type == 'PROFIT' or self .type == 'BRACKETS' :
148+ self .profit_taker_price = profit_taker_price
149+ self .profit_taker_tif = profit_taker_tif
150+ self .profit_taker_rth = profit_taker_rth
151+ self .profit_taker_order_id = profit_taker_order_id
150152
151153 def to_dict (self ):
152154 return self .__dict__
153155
154156 def __repr__ (self ):
155- return "AttachOrder (%s)" % self .to_dict ()
157+ return "OrderLeg (%s)" % self .to_dict ()
0 commit comments