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: exchangeStrategies:
- on: binance - on: binance
oneliner: irr:
symbol: BTCBUSD symbol: BTCBUSD
interval: 1m interval: 1s
window: 120 window: 120
amount: 5_000.0 amount: 5_000.0
backtest: backtest:
sessions: sessions:
- binance - binance
startTime: "2021-01-01" startTime: "2022-10-01"
endTime: "2022-09-30" endTime: "2022-10-04"
symbols: symbols:
- BTCBUSD - BTCBUSD
accounts: accounts:
binance: binance:
takerFeeRate: 0.0 takerFeeRate: 0.0
balances: balances:
# ETH: 1
BUSD: 5_000.0 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 // use kline direction to prevent reversing position too soon
if diffQty.Sign() > 0 { // && kline.Direction() >= 0 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 } 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",
})
} }
})) }))