init
This commit is contained in:
45
demo/show.go
Normal file
45
demo/show.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package demo
|
||||
|
||||
import (
|
||||
"github.com/banbox/banbot/btime"
|
||||
"github.com/banbox/banbot/config"
|
||||
"github.com/banbox/banbot/core"
|
||||
"github.com/banbox/banbot/strat"
|
||||
"github.com/banbox/banexg/log"
|
||||
"go.uber.org/zap"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
func Show(pol *config.RunPolicyConfig) *strat.TradeStrat {
|
||||
pairMap := make(map[string]int)
|
||||
var copied []string
|
||||
var lastMS int64
|
||||
var lockPair sync.Mutex
|
||||
return &strat.TradeStrat{
|
||||
EachMaxLong: 1,
|
||||
OnStartUp: func(s *strat.StratJob) {
|
||||
lockPair.Lock()
|
||||
base, _, _, _ := core.SplitSymbol(s.Symbol.Symbol)
|
||||
pairMap[base] = 0
|
||||
lockPair.Unlock()
|
||||
},
|
||||
OnBar: func(s *strat.StratJob) {
|
||||
curMS := s.Env.TimeStop
|
||||
if curMS > lastMS {
|
||||
if len(copied) > 0 {
|
||||
date := btime.ToDateStr(lastMS, core.DefaultDateFmt)
|
||||
lockPair.Lock()
|
||||
totalNum := len(pairMap)
|
||||
lockPair.Unlock()
|
||||
log.Info("OnBar", zap.String("date", date), zap.Int("got", len(copied)),
|
||||
zap.Int("total", totalNum), zap.String("copied", strings.Join(copied, ",")))
|
||||
}
|
||||
lastMS = curMS
|
||||
copied = nil
|
||||
}
|
||||
base, _, _, _ := core.SplitSymbol(s.Symbol.Symbol)
|
||||
copied = append(copied, base)
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user