github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/v1/history.go (about) 1 package bitfinex 2 3 import "time" 4 5 type HistoryService struct { 6 client *Client 7 } 8 9 type Balance struct { 10 Currency string 11 Amount string 12 Balance string 13 Description string 14 Timestamp string 15 } 16 17 func (s *HistoryService) Balance(currency, wallet string, since, until time.Time, limit int) ([]Balance, error) { 18 19 payload := map[string]interface{}{"currency": currency} 20 21 if !since.IsZero() { 22 payload["since"] = since.Unix() 23 } 24 if !until.IsZero() { 25 payload["until"] = until.Unix() 26 } 27 if limit != 0 { 28 payload["limit"] = limit 29 } 30 31 req, err := s.client.newAuthenticatedRequest("POST", "history", payload) 32 33 if err != nil { 34 return nil, err 35 } 36 37 var v []Balance 38 39 _, err = s.client.do(req, &v) 40 41 if err != nil { 42 return nil, err 43 } 44 45 return v, nil 46 } 47 48 type Movement struct { 49 ID int64 `json:",int"` 50 Currency string 51 Method string 52 Type string 53 Amount string 54 Description string 55 Status string 56 Timestamp string 57 } 58 59 func (s *HistoryService) Movements(currency, method string, since, until time.Time, limit int) ([]Movement, error) { 60 61 payload := map[string]interface{}{"currency": currency, "method": method} 62 63 if !since.IsZero() { 64 payload["since"] = since.Unix() 65 } 66 if !until.IsZero() { 67 payload["until"] = until.Unix() 68 } 69 if limit != 0 { 70 payload["limit"] = limit 71 } 72 73 req, err := s.client.newAuthenticatedRequest("POST", "history/movements", payload) 74 75 if err != nil { 76 return nil, err 77 } 78 79 var v []Movement 80 81 _, err = s.client.do(req, &v) 82 83 if err != nil { 84 return nil, err 85 } 86 87 return v, nil 88 } 89 90 type PastTrade struct { 91 Price string 92 Amount string 93 Timestamp string 94 Exchange string 95 Type string 96 FeeCurrency string `json:"fee_currency"` 97 FeeAmount string `json:"fee_amount"` 98 TID int64 99 OrderId int64 `json:"order_id,int"` 100 } 101 102 func (s *HistoryService) Trades(pair string, since, until time.Time, limit int, reverse bool) ([]PastTrade, error) { 103 payload := map[string]interface{}{"symbol": pair} 104 105 if !since.IsZero() { 106 payload["timestamp"] = since.Unix() 107 } 108 if !until.IsZero() { 109 payload["until"] = until.Unix() 110 } 111 if limit != 0 { 112 payload["limit_trades"] = limit 113 } 114 if reverse { 115 payload["reverse"] = 1 116 } 117 118 req, err := s.client.newAuthenticatedRequest("POST", "mytrades", payload) 119 120 if err != nil { 121 return nil, err 122 } 123 124 var v []PastTrade 125 126 _, err = s.client.do(req, &v) 127 128 if err != nil { 129 return nil, err 130 } 131 132 return v, nil 133 }