Files
big-qmt/go-client/libs/calc.go
2026-08-26 02:10:05 +08:00

39 lines
804 B
Go

package libs
import (
"math"
"math/rand"
"time"
)
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
func randStr(n int) string {
b := make([]rune, n)
for i := range b {
b[i] = letters[rand.Intn(len(letters))]
}
return string(b)
}
func TradingTime(t time.Time) bool {
if t.Weekday() == time.Saturday || t.Weekday() == time.Sunday {
return false
}
second := t.Hour()*3600 + t.Minute()*60 + t.Second()
return (second >= 9*3600+30*60 && second <= 11*3600+30*60) ||
(second >= 13*3600 && second <= 15*3600)
}
func CalcBuyVolume(price, buyValue float64) int {
if price <= 0 || buyValue <= 0 {
return 0
}
// 不足一手时仍按最低一手委托。
hands := int(math.Floor(buyValue / (price * 100)))
if hands == 0 {
hands = 1
}
return hands * 100
}