fix backtest

This commit is contained in:
なるみ 2022-10-28 15:15:55 +08:00
parent 7dd951e39c
commit 532f3c11e7
2 changed files with 35 additions and 18 deletions

View File

@ -8,18 +8,34 @@ notifications:
orderUpdate: true
submitOrder: true
backtest:
startTime: "2022-01-01"
endTime: "2022-10-01"
symbols:
- BTCUSDT
- ETHUSDT
- MAXUSDT
account:
max:
makerFeeRate: 0.075%
takerFeeRate: 0.075%
balances:
BTC: 0.0
ETH: 0.0
MAX: 0.0
USDT: 10000.0
exchangeStrategies:
- on: max
rebalance:
interval: 1d
quoteCurrency: TWD
quoteCurrency: USDT
targetWeights:
BTC: 40%
ETH: 20%
MAX: 10%
USDT: 15%
TWD: 15%
threshold: 2%
BTC: 50%
ETH: 25%
MAX: 15%
USDT: 10%
threshold: 1%
# max amount to buy or sell per order
maxAmount: 10_000
maxAmount: 1_000
dryRun: false

View File

@ -66,7 +66,9 @@ func (s *Strategy) Validate() error {
}
func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) {
session.Subscribe(types.KLineChannel, s.symbols()[0], types.SubscribeOptions{Interval: s.Interval})
for _, symbol := range s.symbols() {
session.Subscribe(types.KLineChannel, symbol, types.SubscribeOptions{Interval: s.Interval})
}
}
func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, session *bbgo.ExchangeSession) error {
@ -113,21 +115,20 @@ func (s *Strategy) rebalance(ctx context.Context, orderExecutor bbgo.OrderExecut
func (s *Strategy) prices(ctx context.Context, session *bbgo.ExchangeSession) types.ValueMap {
m := make(types.ValueMap)
tickers, err := session.Exchange.QueryTickers(ctx, s.symbols()...)
if err != nil {
log.WithError(err).Error("failed to query tickers")
return nil
}
for currency := range s.TargetWeights {
if currency == s.QuoteCurrency {
m[s.QuoteCurrency] = fixedpoint.One
continue
}
m[currency] = tickers[currency+s.QuoteCurrency].Last
}
ticker, err := session.Exchange.QueryTicker(ctx, currency+s.QuoteCurrency)
if err != nil {
log.WithError(err).Error("failed to query tickers")
return nil
}
m[currency] = ticker.Last
}
return m
}