This commit is contained in:
2026-08-24 20:53:21 +08:00
commit 6e78bba16a
287 changed files with 32443 additions and 0 deletions

48
demo/limits.go Normal file
View File

@@ -0,0 +1,48 @@
package demo
import (
"github.com/banbox/banbot/config"
"github.com/banbox/banbot/orm/ormo"
"github.com/banbox/banbot/strat"
"github.com/banbox/banexg/log"
"go.uber.org/zap"
)
func DemoV1(pol *config.RunPolicyConfig) *strat.TradeStrat {
dirt := -1.0
limitRate := 0.001
slRate := 0.005
return &strat.TradeStrat{
WarmupNum: 30,
OnBar: func(s *strat.StratJob) {
if s.OrderNum == 0 {
price := s.Env.Close.Get(0)
limit := price * (1 - dirt*limitRate)
stopLoss := price * (1 - dirt*slRate)
err := s.OpenOrder(&strat.EnterReq{
Tag: "enter",
Limit: limit,
Short: dirt < 0,
StopLoss: stopLoss,
})
if err != nil {
log.Error("open fail", zap.Error(err))
} else {
log.Info("new order", zap.Float64("limit", limit), zap.Float64("stopLoss", stopLoss))
}
}
},
OnCheckExit: func(s *strat.StratJob, od *ormo.InOutOrder) *strat.ExitReq {
price := s.Env.Close.Get(0)
stopLoss := price * (1 - dirt*slRate)
sl := od.GetStopLoss()
if sl != nil && (stopLoss-sl.Price)*dirt > 0 {
// 有盈利,调整跟踪止损
log.Info("set stoploss", zap.Float64("val", stopLoss))
sl.Price = stopLoss
od.DirtyInfo = true
}
return nil
},
}
}