Files
stock/internal/logic/a/new.go
2026-02-12 19:41:52 +08:00

64 lines
1.2 KiB
Go
Raw 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 a
import (
"time"
"git.apinb.com/bsm-sdk/core/utils"
tushare "github.com/ShawnRong/tushare-go"
)
var (
TushareToken = "432de9ba12b6711948450273ed6e478dbac9e3e712323bbf823ada11"
TushareClient *tushare.TuShare
)
func NewApiClient() {
TushareClient = tushare.New(TushareToken)
}
// 获取最近N个交易日,asc=true 顺序asc=false 倒序
func GetTradeDateBy(max int, asc bool) []string {
reply, _ := TushareClient.TradeCal(map[string]string{
"is_open": "1",
"end_date": time.Now().Format("20060102"),
}, []string{"exchange", "cal_date"})
var days []string
for i := 0; i < max; i++ {
days = append(days, reply.Data.Items[i][1].(string))
}
// 将days的数据倒序
if asc {
var newDays []string
for i := len(days) - 1; i >= 0; i-- {
newDays = append(newDays, days[i])
}
return newDays
}
return days
}
func ReturnLastDay() (string, string) {
now := time.Now()
end := now.Format("20060102")
start := now.AddDate(0, 0, -1).Format("20060102")
return start, end
}
func Anys2Strings(any []any) []string {
var ret []string
for _, item := range any {
ret = append(ret, utils.AnyToString(item))
}
return ret
}
func Any2Float(in any) float64 {
if in == nil {
return -1
}
return in.(float64)
}