github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/v1/trades.go (about) 1 package bitfinex 2 3 import ( 4 "net/url" 5 "strconv" 6 "strings" 7 "time" 8 ) 9 10 type TradesService struct { 11 client *Client 12 } 13 14 type Trade struct { 15 Price string 16 Amount string 17 Exchange string 18 Type string 19 Timestamp int64 20 TradeId int64 `json:"tid,int"` 21 } 22 23 func (el *Trade) Time() *time.Time { 24 t := time.Unix(el.Timestamp, 0) 25 return &t 26 } 27 28 func (s *TradesService) All(pair string, timestamp time.Time, limitTrades int) ([]Trade, error) { 29 pair = strings.ToUpper(pair) 30 31 params := url.Values{} 32 if !time.Time.IsZero(timestamp) { 33 params.Add("timestamp", strconv.FormatInt(timestamp.Unix(), 10)) 34 } 35 if limitTrades != 0 { 36 params.Add("limit_trades", strconv.Itoa(limitTrades)) 37 } 38 req, err := s.client.newRequest("GET", "trades/"+pair, params) 39 if err != nil { 40 return nil, err 41 } 42 43 var v []Trade 44 45 _, err = s.client.do(req, &v) 46 if err != nil { 47 return nil, err 48 } 49 50 return v, nil 51 }