alpacahq / alpacahq/alpaca-backtrader-api

Cannot purchase Long and create a trailing stop

未关闭
#391 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
702
派生
160
PR 合并指标
30 天内没有已合并 PR

描述

I'm trying to buy for a long position with a trailing stop.

Source snippet:
```
valid_for_minutes = 1
buy_long = self.buy(exectype=exectype,
price=price,
size=data.long_size,
valid=timedelta(minutes=valid_for_minutes),
transmit=False)
data.long_order = self.sell(exectype=bt.Order.StopTrail,
parent=buy_long,
size=data.long_size,
trailamount=trail_amount)
```

Traceback:
```
File "..\backtrader_v1\strategies\base.py", line 191, in purchase
data.long_order = self.sell(exectype=bt.Order.StopTrail,
File "C:\Projects\Personal\Trading\trader\backtrader_v1\venv\lib\site-packages\backtrader\strategy.py", line 963, in sell
return self.broker.sell(
File "C:\Projects\Personal\Trading\trader\backtrader_v1\venv\lib\site-packages\alpaca_backtrader_api\alpacabroker.py", line 323, in sell
return self._transmit(order)
File "C:\Projects\Personal\Trading\trader\backtrader_v1\venv\lib\site-packages\alpaca_backtrader_api\alpacabroker.py", line 275, in _transmit
parent, stopside = self.opending.pop(pref)
ValueError: not enough values to unpack (expected 2, got 1)
```

Requirements.txt
```
alpaca-backtrader-api==0.15.0
setuptools==59.5.0
```

Long works fine alone, bracket orders work fine, but when I use the `transmit=False` and use the non-transmitted purchase as a parent I get this error. I'm basing my code on the example: https://www.backtrader.com/blog/posts/2018-02-01-stop-trading/stop-trading/ under the AutoStopOrStopTrail class. The ManualStopOrStopTrail class works fine because it doesn't leverage the `parent` and `transmit=False` feature, but it delays the submitting the trailing stop by a minute...so it's not optimal.

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。