github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/v2/rest/tickers_hist.go (about) 1 package rest 2 3 import ( 4 "fmt" 5 "net/url" 6 "strings" 7 8 "github.com/bitfinexcom/bitfinex-api-go/pkg/convert" 9 "github.com/bitfinexcom/bitfinex-api-go/pkg/models/tickerhist" 10 ) 11 12 // TickerHistoryService manages the Tickers History endpoint. 13 type TickerHistoryService struct { 14 requestFactory 15 Synchronous 16 } 17 18 type GetTickerHistPayload struct { 19 Symbols []string 20 Start int64 21 End int64 22 Limit uint32 23 } 24 25 // Get - retrieves the ticker history for the given symbol 26 // see https://docs.bitfinex.com/reference#tickers-history for more info 27 func (s *TickerHistoryService) Get(pld GetTickerHistPayload) ([]tickerhist.TickerHist, error) { 28 if len(pld.Symbols) == 0 { 29 return nil, fmt.Errorf("missing mandatory parameters: []Symbols") 30 } 31 32 req := NewRequestWithMethod("tickers/hist", "GET") 33 req.Params = make(url.Values) 34 req.Params.Add("symbols", strings.Join(pld.Symbols, ",")) 35 36 if pld.Start != 0 { 37 req.Params.Add("start", fmt.Sprintf("%d", pld.Start)) 38 } 39 40 if pld.End != 0 { 41 req.Params.Add("end", fmt.Sprintf("%d", pld.End)) 42 } 43 44 if pld.Limit != 0 { 45 req.Params.Add("limit", fmt.Sprintf("%d", pld.Limit)) 46 } 47 48 raw, err := s.Request(req) 49 if err != nil { 50 return nil, err 51 } 52 53 tickers := tickerhist.SnapshotFromRaw(convert.ToInterfaceArray(raw)) 54 return tickers.Snapshot, nil 55 }