github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/v2/rest/ledgers.go (about) 1 package rest 2 3 import ( 4 "fmt" 5 "path" 6 7 "github.com/bitfinexcom/bitfinex-api-go/pkg/models/common" 8 "github.com/bitfinexcom/bitfinex-api-go/pkg/models/ledger" 9 ) 10 11 // LedgerService manages the Ledgers endpoint. 12 type LedgerService struct { 13 requestFactory 14 Synchronous 15 } 16 17 var maxLimit int32 = 2500 18 19 // Ledgers - all of the past ledger entreies 20 // see https://docs.bitfinex.com/reference#ledgers for more info 21 func (s *LedgerService) Ledgers(currency string, start int64, end int64, max int32) (*ledger.Snapshot, error) { 22 if max > maxLimit { 23 return nil, fmt.Errorf("Max request limit:%d, got: %d", maxLimit, max) 24 } 25 26 payload := map[string]interface{}{"start": start, "end": end, "limit": max} 27 req, err := s.requestFactory.NewAuthenticatedRequestWithData(common.PermissionRead, path.Join("ledgers", currency, "hist"), payload) 28 if err != nil { 29 return nil, err 30 } 31 32 raw, err := s.Request(req) 33 if err != nil { 34 return nil, err 35 } 36 37 lss, err := ledger.SnapshotFromRaw(raw, ledger.FromRaw) 38 if err != nil { 39 return nil, err 40 } 41 42 return lss, nil 43 }