Files
banstagy/arb/stat_group.go
2026-08-24 20:53:21 +08:00

53 lines
1.3 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package arb
import (
"github.com/banbox/banbot/config"
"github.com/banbox/banbot/core"
"github.com/banbox/banbot/exg"
"github.com/banbox/banbot/orm"
"github.com/banbox/banexg"
"github.com/banbox/banexg/errs"
"github.com/banbox/banexg/log"
"go.uber.org/zap"
"sort"
)
func StatGroupPairs() *errs.Error {
exgId := "binance"
endMS := config.TimeRange.EndMS
// 生成待订阅标的列表
exsMap := orm.GetExSymbols(exgId, banexg.MarketLinear)
limit := 720
exsList, barList, _, err := getExsBars(exg.Default, exsMap, "1h", 0, endMS, limit)
if err != nil {
return err
}
arr := make([]*core.StrFloat, 0, len(exsList))
for i, exs := range exsList {
var sumVal float64
bars := barList[i]
if float64(len(bars)) < float64(limit)*0.9 {
continue
}
for _, b := range bars {
sumVal += b.Volume * b.Close
}
arr = append(arr, &core.StrFloat{
Str: exs.Symbol,
Val: sumVal,
})
}
// 按成交量降序,取前30%
sort.Slice(arr, func(i, j int) bool {
return arr[i].Val > arr[j].Val
})
cutNum := int(float64(len(arr)) * 0.2)
cutPairs := make([]string, 0, cutNum)
for i := 0; i < cutNum; i++ {
base, _, _, _ := core.SplitSymbol(arr[i].Str)
cutPairs = append(cutPairs, base)
}
log.Info("cut 20% of pairs", zap.Int("num", cutNum), zap.Int("total", len(arr)), zap.Strings("items", cutPairs))
return nil
}