github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/v1/ticker.go (about) 1 package bitfinex 2 3 import ( 4 "strconv" 5 "strings" 6 "time" 7 ) 8 9 type TickerService struct { 10 client *Client 11 } 12 13 type Tick struct { 14 Mid string 15 Bid string 16 Ask string 17 LastPrice string `json:"last_price"` 18 Low string 19 High string 20 Volume string 21 Timestamp string 22 } 23 24 // ParseTime - return Timestamp in time.Time format 25 func (el *Tick) ParseTime() (*time.Time, error) { 26 i, err := strconv.ParseFloat(el.Timestamp, 64) 27 if err != nil { 28 return nil, err 29 } 30 t := time.Unix(int64(i), 0) 31 return &t, nil 32 } 33 34 // Get(pair) - return last Tick for specified pair 35 func (s *TickerService) Get(pair string) (Tick, error) { 36 pair = strings.ToUpper(pair) 37 req, err := s.client.newRequest("GET", "pubticker/"+pair, nil) 38 39 if err != nil { 40 return Tick{}, err 41 } 42 43 var v = &Tick{} 44 _, err = s.client.do(req, v) 45 46 if err != nil { 47 return Tick{}, err 48 } 49 50 return *v, nil 51 }