From 6abb320bce7f0e8481c7f397768b3c4475ba8715 Mon Sep 17 00:00:00 2001 From: c9s Date: Tue, 7 Nov 2023 11:17:08 +0800 Subject: [PATCH] emacross: clean up and update config --- config/emacross.yaml | 37 +++++++++++++++++++++++++++++++ pkg/strategy/emacross/strategy.go | 16 +++++-------- 2 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 config/emacross.yaml diff --git a/config/emacross.yaml b/config/emacross.yaml new file mode 100644 index 000000000..c1ce36a46 --- /dev/null +++ b/config/emacross.yaml @@ -0,0 +1,37 @@ +persistence: + json: + directory: var/data + redis: + host: 127.0.0.1 + port: 6379 + db: 0 + +sessions: + binance: + exchange: binance + envVarPrefix: binance + +exchangeStrategies: +- on: binance + emacross: + symbol: BTCUSDT + # interval: 5m + # fastWindow: 6 + # slowWindow: 18 + # quantity: 0.01 + leverage: 2 + +backtest: + startTime: "2022-01-01" + endTime: "2022-03-01" + symbols: + - BTCUSDT + sessions: [max,binance] + # syncSecKLines: true + accounts: + binance: + makerFeeRate: 0.0% + takerFeeRate: 0.075% + balances: + BTC: 0.0 + USDT: 10_000.0 diff --git a/pkg/strategy/emacross/strategy.go b/pkg/strategy/emacross/strategy.go index 2778fb687..1ece94b76 100644 --- a/pkg/strategy/emacross/strategy.go +++ b/pkg/strategy/emacross/strategy.go @@ -47,8 +47,7 @@ func (s *Strategy) InstanceID() string { } func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) { - session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: types.Interval5m}) - session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: types.Interval1m}) + session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: s.Interval}) } func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.ExchangeSession) error { @@ -59,8 +58,9 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo. s.lastKLine = k })) - fastEMA := session.Indicators(s.Symbol).EWMA(types.IntervalWindow{Interval: types.Interval5m, Window: 7}) - slowEMA := session.Indicators(s.Symbol).EWMA(types.IntervalWindow{Interval: types.Interval5m, Window: 14}) + fastEMA := session.Indicators(s.Symbol).EWMA(types.IntervalWindow{Interval: s.Interval, Window: s.FastWindow}) + slowEMA := session.Indicators(s.Symbol).EWMA(types.IntervalWindow{Interval: s.Interval, Window: s.SlowWindow}) + cross := indicatorv2.Cross(fastEMA, slowEMA) cross.OnUpdate(func(v float64) { switch indicatorv2.CrossType(v) { @@ -79,14 +79,10 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo. opts.Tags = []string{"emaCrossOver"} _, err := s.Strategy.OrderExecutor.OpenPosition(ctx, opts) - if err != nil { - log.WithError(err).Errorf("unable to submit buy order") - } + logErr(err, "unable to open position") case indicatorv2.CrossUnder: err := s.Strategy.OrderExecutor.ClosePosition(ctx, fixedpoint.One) - if err != nil { - log.WithError(err).Errorf("unable to submit sell order") - } + logErr(err, "unable to submit close position order") } })