strategy: fix irr

This commit is contained in:
austin362667 2022-10-04 14:24:41 +08:00
parent 04453c23ea
commit 26d640ff3b
2 changed files with 18 additions and 7 deletions

View File

@ -13,22 +13,21 @@ sessions:
exchangeStrategies:
- on: binance
oneliner:
irr:
symbol: BTCBUSD
interval: 1m
interval: 1s
window: 120
amount: 5_000.0
backtest:
sessions:
- binance
startTime: "2021-01-01"
endTime: "2022-09-30"
startTime: "2022-10-01"
endTime: "2022-10-04"
symbols:
- BTCBUSD
accounts:
binance:
takerFeeRate: 0.0
balances:
# ETH: 1
BUSD: 5_000.0

View File

@ -213,9 +213,21 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
// use kline direction to prevent reversing position too soon
if diffQty.Sign() > 0 { // && kline.Direction() >= 0
s.orderExecutor.OpenPosition(context.Background(), bbgo.OpenPositionOptions{Quantity: diffQty.Abs(), Long: true, LimitOrder: false})
_, _ = s.orderExecutor.SubmitOrders(ctx, types.SubmitOrder{
Symbol: s.Symbol,
Side: types.SideTypeBuy,
Quantity: diffQty.Abs(),
Type: types.OrderTypeMarket,
Tag: "irr buy more",
})
} else if diffQty.Sign() < 0 { // && kline.Direction() <= 0
s.orderExecutor.OpenPosition(context.Background(), bbgo.OpenPositionOptions{Quantity: diffQty.Abs(), Short: true, LimitOrder: false})
_, _ = s.orderExecutor.SubmitOrders(ctx, types.SubmitOrder{
Symbol: s.Symbol,
Side: types.SideTypeSell,
Quantity: diffQty.Abs(),
Type: types.OrderTypeMarket,
Tag: "irr sell more",
})
}
}))