88from tigeropen .common .consts import OrderStatus
99
1010ORDER_FIELDS_TO_IGNORE = {'type' , '_status' , 'contract' , '_remaining' }
11-
11+ ALGO_PARAMS_TAG_MAP = {'noTakeLiq' : 'no_take_liq' , 'startTime' : 'start_time' , 'endTime' : 'end_time' ,
12+ 'participationRate' : 'participation_rate' , 'allowPastEndTime' : 'allow_past_end_time' }
1213
1314class Order (object ):
1415 __slots__ = ["account" , "id" , "order_id" , "parent_id" , "order_time" , "reason" , "trade_time" , "contract" , "action" ,
1516 "quantity" , "filled" , "_remaining" , "avg_fill_price" , "commission" , "realized_pnl" , "_status" ,
1617 "trail_stop_price" , "limit_price" , "aux_price" , "trailing_percent" , "percent_offset" , "action" ,
17- "order_type" , "time_in_force" , "outside_rth" , "order_legs" ]
18+ "order_type" , "time_in_force" , "outside_rth" , "order_legs" , "algo_params" ]
1819
1920 def __init__ (self , account , contract , action , order_type , quantity , limit_price = None , aux_price = None ,
2021 trail_stop_price = None , trailing_percent = None , percent_offset = None , time_in_force = None ,
2122 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 , order_legs = None ):
23+ id = None , order_id = None , parent_id = None , order_time = None , trade_time = None , order_legs = None ,
24+ algo_params = None ):
2325 """
2426 - account: 订单所属的账户
2527 - id: 全局订单 id
@@ -46,6 +48,7 @@ def __init__(self, account, contract, action, order_type, quantity, limit_price=
4648 - status: Order_Status 的枚举, 表示订单状态
4749 - remaining: 未成交的数量
4850 - order_legs: 附加订单列表
51+ - algo_params: 算法订单参数
4952 """
5053
5154 self .id = id
@@ -73,6 +76,7 @@ def __init__(self, account, contract, action, order_type, quantity, limit_price=
7376 self .order_time = order_time
7477 self .trade_time = trade_time
7578 self .order_legs = order_legs
79+ self .algo_params = algo_params
7680
7781 def to_dict (self ):
7882 dct = {name : getattr (self , name ) for name in self .__slots__ if name not in ORDER_FIELDS_TO_IGNORE }
@@ -141,3 +145,44 @@ def to_dict(self):
141145
142146 def __repr__ (self ):
143147 return "OrderLeg(%s)" % self .to_dict ()
148+
149+
150+ class AlgoParams (object ):
151+ """
152+ 算法订单参数
153+ """
154+ def __init__ (self , start_time = None , end_time = None , no_take_liq = None , allow_past_end_time = None ,
155+ participation_rate = None ):
156+ """
157+ :param start_time: 生效开始时间(时间戳 TWAP和VWAP专用)
158+ :param end_time: 生效结束时间(时间戳 TWAP和VWAP专用)
159+ :param no_take_liq: 是否尽可能减少交易次数(VWAP订单专用)
160+ :param allow_past_end_time: 是否允许生效时间结束后继续完成成交(TWAP和VWAP专用)
161+ :param participation_rate: 参与率(VWAP专用,0.01-0.5)
162+ """
163+ self .start_time = start_time
164+ self .end_time = end_time
165+ self .no_take_liq = no_take_liq
166+ self .allow_past_end_time = allow_past_end_time
167+ self .participation_rate = participation_rate
168+
169+ def to_dict (self ):
170+ return self .__dict__
171+
172+ @staticmethod
173+ def from_tags (tag_values ):
174+ """
175+ :param tag_values:
176+ :return: AlgoParams 对象
177+ """
178+ algo_params = AlgoParams ()
179+ if tag_values :
180+ for item in tag_values :
181+ tag = item .get ('tag' )
182+ value = item .get ('value' )
183+ setattr (algo_params , ALGO_PARAMS_TAG_MAP .get (tag ), value )
184+ return algo_params
185+ return None
186+
187+ def __repr__ (self ):
188+ return "AlgoParams(%s)" % self .to_dict ()
0 commit comments