28 lines
561 B
Go
28 lines
561 B
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
// GetTick 单次轮询。
|
|
func GetTick(ctx context.Context) (map[string]float64, error) {
|
|
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
|
defer cancel()
|
|
|
|
prices, err := BinanceClient.NewListPricesService().Symbols(Symbols).Do(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
priceBySymbol := make(map[string]float64, len(prices))
|
|
for _, p := range prices {
|
|
v, err := strconv.ParseFloat(p.Price, 64)
|
|
if err != nil {
|
|
continue
|
|
}
|
|
priceBySymbol[p.Symbol] = v
|
|
}
|
|
return priceBySymbol, nil
|
|
}
|