Skip to content

Commit 0142695

Browse files
committed
support bracket order for alpaca-backtrader
1 parent 93d90cc commit 0142695

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

alpaca_backtrader_api/alpacastore.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -558,11 +558,15 @@ def order_create(self, order, stopside=None, takeside=None, **kwargs):
558558
# if order.exectype == bt.Order.StopTrail:
559559
# okwargs['trailingStop'] = order.trailamount
560560

561-
# if stopside is not None:
562-
# okwargs['stopLoss'] = stopside.price
561+
if stopside:
562+
okwargs['stop_loss'] = {'stop_price': stopside.price}
563+
564+
if takeside:
565+
okwargs['take_profit'] = {'limit_price': takeside.price}
566+
567+
if stopside or takeside:
568+
okwargs['order_class'] = "bracket"
563569

564-
# if takeside is not None:
565-
# okwargs['takeProfit'] = takeside.price
566570

567571
okwargs.update(**kwargs) # anything from the user
568572

@@ -572,6 +576,8 @@ def order_create(self, order, stopside=None, takeside=None, **kwargs):
572576
def _t_order_create(self):
573577
while True:
574578
try:
579+
# if self.q_ordercreate.empty():
580+
# continue
575581
msg = self.q_ordercreate.get()
576582
if msg is None:
577583
break

0 commit comments

Comments
 (0)