@@ -279,9 +279,10 @@ def get_orders(self, account=None, sec_type=None, market=Market.ALL, symbol=None
279279 return None
280280
281281 def get_open_orders (self , account = None , sec_type = None , market = Market .ALL , symbol = None , start_time = None ,
282- end_time = None ):
282+ end_time = None , parent_id = None ):
283283 """
284284 获取待成交订单列表. 参数同 get_orders
285+ :param parent_id: 主订单 order_id
285286 """
286287 params = OrdersParams ()
287288 params .account = account if account else self ._account
@@ -291,6 +292,7 @@ def get_open_orders(self, account=None, sec_type=None, market=Market.ALL, symbol
291292 params .symbol = symbol
292293 params .start_date = start_time
293294 params .end_date = end_time
295+ params .parent_id = parent_id
294296 request = OpenApiRequest (ACTIVE_ORDERS , biz_model = params )
295297 response_content = self .__fetch_data (request )
296298 if response_content :
@@ -377,7 +379,9 @@ def get_order(self, account=None, id=None, order_id=None, is_brief=False):
377379
378380 def create_order (self , account , contract , action , order_type , quantity , limit_price = None , aux_price = None ,
379381 trail_stop_price = None , trailing_percent = None , percent_offset = None , time_in_force = None ,
380- outside_rth = None ):
382+ outside_rth = None , attach_type = None , stop_loss_price = None , stop_loss_tif = 'DAY' , stop_loss_rth = None ,
383+ stop_loss_order_id = None , profit_taker_price = None , profit_taker_tif = 'DAY' , profit_taker_rth = None ,
384+ profit_taker_order_id = None ):
381385 """
382386 创建订单对象.
383387 :param account:
@@ -392,7 +396,16 @@ def create_order(self, account, contract, action, order_type, quantity, limit_pr
392396 :param percent_offset:
393397 :param time_in_force: 订单有效期, 'DAY'(当日有效)和'GTC'(取消前有效)
394398 :param outside_rth: 是否允许盘前盘后交易(美股专属)
395- :return:
399+
400+ :param attach_type: 附加订单类型(仅限价单支持). PROFIT 止盈单类型, LOSS 止损单类型, BRACKETS 括号订单类型(止损和止盈)
401+ :param stop_loss_price: 附加止损单价格
402+ :param stop_loss_tif: 附加止损单有效期. 'DAY'(当日有效)和'GTC'(取消前有效). 同 time_in_force 字段
403+ :param stop_loss_rth: 附加止损单是否允许盘前盘后交易(美股专属). True 允许, False 不允许. 同 outside_rth 字段
404+ :param stop_loss_order_id: 附加止损单号. 可以通过订单号接口获取, 如果传0或为空, 则服务器端会自动生成止损单号
405+ :param profit_taker_price: 附加止盈单价格
406+ :param profit_taker_tif: 附加止盈单有效期. 'DAY'(当日有效)和'GTC'(取消前有效). 同 time_in_force 字段
407+ :param profit_taker_rth: 附加止盈单是否允许盘前盘后交易(美股专属). True 允许, False 不允许. 同 outside_rth 字段
408+ :param profit_taker_order_id: 附加止盈单号. 可以通过订单号接口获取, 如果传0或为空, 则服务器端会自动生成止盈单号
396409 """
397410 params = AccountsParams ()
398411 params .account = account if account else self ._account
@@ -406,7 +419,11 @@ def create_order(self, account, contract, action, order_type, quantity, limit_pr
406419 order = Order (account , contract , action , order_type , quantity , limit_price = limit_price ,
407420 aux_price = aux_price , trail_stop_price = trail_stop_price ,
408421 trailing_percent = trailing_percent , percent_offset = percent_offset ,
409- time_in_force = time_in_force , outside_rth = outside_rth , order_id = order_id )
422+ time_in_force = time_in_force , outside_rth = outside_rth , order_id = order_id ,
423+ attach_type = attach_type , stop_loss_price = stop_loss_price , stop_loss_tif = stop_loss_tif ,
424+ stop_loss_rth = stop_loss_rth , stop_loss_order_id = stop_loss_order_id ,
425+ profit_taker_price = profit_taker_price , profit_taker_tif = profit_taker_tif ,
426+ profit_taker_rth = profit_taker_rth , profit_taker_order_id = profit_taker_order_id )
410427 return order
411428 else :
412429 raise ApiException (response .code , response .message )
@@ -476,14 +493,28 @@ def place_order(self, order):
476493 params .percent_offset = order .percent_offset
477494 params .time_in_force = order .time_in_force
478495 params .outside_rth = order .outside_rth
496+ params .attach_type = order .attach_type
497+ params .stop_loss_price = order .stop_loss_price
498+ params .stop_loss_tif = order .stop_loss_tif
499+ params .stop_loss_rth = order .stop_loss_rth
500+ params .stop_loss_order_id = order .stop_loss_order_id
501+ params .profit_taker_price = order .profit_taker_price
502+ params .profit_taker_tif = order .profit_taker_tif
503+ params .profit_taker_rth = order .profit_taker_rth
504+ params .profit_taker_order_id = order .profit_taker_order_id
505+
479506 request = OpenApiRequest (PLACE_ORDER , biz_model = params )
480507 response_content = self .__fetch_data (request )
481508 if response_content :
482509 response = OrderIdResponse ()
483510 response .parse_response_content (response_content )
484511 if response .is_success ():
485512 order .id = response .id
486- return response .order_id == order .order_id if order .order_id else True
513+ if order .order_id :
514+ return response .order_id == order .order_id
515+ else :
516+ order .order_id = response .order_id
517+ return True
487518 else :
488519 raise ApiException (response .code , response .message )
489520
0 commit comments