系统管理员点击同步时同步半年历史数据

This commit is contained in:
2026-07-04 11:54:07 +08:00
parent 716761b3d9
commit 63687723ab
3 changed files with 176 additions and 2 deletions
+41
View File
@@ -74,6 +74,19 @@ type UniverseDetail struct {
Symbols []string `json:"symbols"`
}
// KlineData 对应 /v1/klines/batch 返回的单标的历史 K 线(紧凑列式)。
type KlineData struct {
Symbol string `json:"-"`
Name string `json:"-"`
Timestamp []int64 `json:"timestamp"`
Open []float64 `json:"open"`
High []float64 `json:"high"`
Low []float64 `json:"low"`
Close []float64 `json:"close"`
Volume []int64 `json:"volume"`
Amount []float64 `json:"amount"`
}
// Client 封装 tickflow HTTP API 调用。
type Client struct {
baseURL string
@@ -120,6 +133,34 @@ func (c *Client) GetQuotesBySymbols(symbols []string) ([]Quote, error) {
return quotes, nil
}
// GetKlinesBatch 批量获取多只股票的历史日 K 线。
// symbols 最多 100 只(tickflow 限制)。
func (c *Client) GetKlinesBatch(symbols []string, period string, startMs, endMs int64) (map[string]KlineData, error) {
if len(symbols) == 0 {
return nil, nil
}
if len(symbols) > 100 {
return nil, fmt.Errorf("GetKlinesBatch supports up to 100 symbols, got %d", len(symbols))
}
params := map[string]any{
"symbols": strings.Join(symbols, ","),
"period": period,
"adjust": "none",
"start_time": startMs,
"end_time": endMs,
"count": 10000,
}
var result map[string]KlineData
if err := c.request("GET", "/v1/klines/batch", params, nil, &result); err != nil {
return nil, err
}
for sym, data := range result {
data.Symbol = sym
result[sym] = data
}
return result, nil
}
func (c *Client) request(method, path string, params, body map[string]any, result any) error {
url := c.baseURL + path