Skip to content

Commit e1fe2f5

Browse files
committed
order legs amount check
1 parent ceb8b6e commit e1fe2f5

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

tigeropen/common/util/order_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ def limit_order_with_legs(account, contract, action, quantity, limit_price, orde
9696
:param order_legs: 附加订单列表
9797
:return:
9898
"""
99+
if order_legs and len(order_legs) > 2:
100+
raise Exception('2 order legs at most')
99101
return Order(account, contract, action, 'LMT', quantity, limit_price=limit_price, order_legs=order_legs)
100102

101103

tigeropen/examples/trade_client_demo.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,14 @@ def trade_apis():
9898
print(result)
9999

100100
# 限价单 + 附加订单 (仅主订单为限价单时支持附加订单)
101-
stop_loss_order_legs = order_leg('LOSS', 8.0, time_in_force='GTC') # 附加止损
102-
profit_taker_order_legs = order_leg('PROFIT', 12.0, time_in_force='GTC') # 附加止盈
101+
stop_loss_order_leg = order_leg('LOSS', 8.0, time_in_force='GTC') # 附加止损
102+
profit_taker_order_leg = order_leg('PROFIT', 12.0, time_in_force='GTC') # 附加止盈
103103

104104
main_order = openapi_client.create_order(account, contract, 'BUY', 'LMT', quantity=100, limit_price=10.0,
105-
order_legs=[stop_loss_order_legs, profit_taker_order_legs])
105+
order_legs=[stop_loss_order_leg, profit_taker_order_leg])
106106
# 本地构造限价单 + 附加订单
107107
# main_order = limit_order_with_legs(account, contract, 'BUY', 100, limit_price=10.0,
108-
# order_legs=[stop_loss_order_legs])
108+
# order_legs=[stop_loss_order_leg])
109109

110110
openapi_client.place_order(main_order)
111111
print(main_order)

tigeropen/trade/request/model.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,12 @@ def to_openapi_dict(self):
556556
params['outside_rth'] = self.outside_rth
557557

558558
if self.order_legs:
559+
if len(self.order_legs) > 2:
560+
raise Exception('2 order legs at most')
561+
leg_types = set()
559562
for order_leg in self.order_legs:
560563
if order_leg.leg_type == 'PROFIT':
564+
leg_types.add('PROFIT')
561565
params['attach_type'] = 'PROFIT'
562566
if order_leg.price is not None:
563567
params['profit_taker_price'] = order_leg.price
@@ -566,6 +570,7 @@ def to_openapi_dict(self):
566570
if order_leg.outside_rth is not None:
567571
params['profit_taker_rth'] = order_leg.outside_rth
568572
if order_leg.leg_type == 'LOSS':
573+
leg_types.add('LOSS')
569574
params['attach_type'] = 'LOSS'
570575
if order_leg.price is not None:
571576
params['stop_loss_price'] = order_leg.price
@@ -574,7 +579,7 @@ def to_openapi_dict(self):
574579
if order_leg.outside_rth is not None:
575580
params['stop_loss_rth'] = order_leg.outside_rth
576581
# 括号订单(止盈和止损)
577-
if len(self.order_legs) > 1:
582+
if len(leg_types) == 2:
578583
params['attach_type'] = 'BRACKETS'
579584

580585
return params

0 commit comments

Comments
 (0)