emacross: clean up and update config

This commit is contained in:
c9s 2023-11-07 11:17:08 +08:00
parent 85e87e10b6
commit 6abb320bce
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 43 additions and 10 deletions

37
config/emacross.yaml Normal file
View File

@ -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

View File

@ -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")
}
})