github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/v1/lendbook.go (about) 1 package bitfinex 2 3 import ( 4 "net/url" 5 "strconv" 6 "strings" 7 "time" 8 ) 9 10 type LendbookService struct { 11 client *Client 12 } 13 14 type Lend struct { 15 Rate string 16 Amount string 17 Period int 18 Timestamp string 19 Frr string 20 } 21 22 func (el *Lend) ParseTime() (*time.Time, error) { 23 i, err := strconv.ParseFloat(el.Timestamp, 64) 24 if err != nil { 25 return nil, err 26 } 27 t := time.Unix(int64(i), 0) 28 return &t, nil 29 } 30 31 type Lendbook struct { 32 Bids []Lend 33 Asks []Lend 34 } 35 36 // GET /lendbook/:currency 37 func (s *LendbookService) Get(currency string, limitBids, limitAsks int) (Lendbook, error) { 38 currency = strings.ToUpper(currency) 39 40 params := url.Values{} 41 if limitBids != 0 { 42 params.Add("limit_bids", strconv.Itoa(limitBids)) 43 } 44 if limitAsks != 0 { 45 params.Add("limit_asks", strconv.Itoa(limitAsks)) 46 } 47 48 req, err := s.client.newRequest("GET", "lendbook/"+currency, params) 49 if err != nil { 50 return Lendbook{}, err 51 } 52 53 var v Lendbook 54 _, err = s.client.do(req, &v) 55 if err != nil { 56 return Lendbook{}, err 57 } 58 59 return v, nil 60 } 61 62 type Lends struct { 63 Rate string 64 AmountLent string `json:"amount_lent"` 65 AmountUsed string `json:"amount_used"` 66 Timestamp int64 67 } 68 69 func (el *Lends) Time() *time.Time { 70 t := time.Unix(el.Timestamp, 0) 71 return &t 72 } 73 74 // GET /lends/:currency 75 func (s *LendbookService) Lends(currency string) ([]Lends, error) { 76 currency = strings.ToUpper(currency) 77 req, err := s.client.newRequest("GET", "lends/"+currency, nil) 78 if err != nil { 79 return nil, err 80 } 81 82 var v []Lends 83 _, err = s.client.do(req, &v) 84 if err != nil { 85 return nil, err 86 } 87 88 return v, nil 89 }