github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/v2/rest/book.go (about)

     1  package rest
     2  
     3  import (
     4  	"net/url"
     5  	"path"
     6  	"strconv"
     7  
     8  	"github.com/bitfinexcom/bitfinex-api-go/pkg/convert"
     9  	"github.com/bitfinexcom/bitfinex-api-go/pkg/models/book"
    10  	"github.com/bitfinexcom/bitfinex-api-go/pkg/models/common"
    11  )
    12  
    13  type BookService struct {
    14  	Synchronous
    15  }
    16  
    17  // All - retrieve all books for the given symbol with the given precision at the given price level
    18  // see https://docs.bitfinex.com/reference#rest-public-books for more info
    19  func (b *BookService) All(symbol string, precision common.BookPrecision, priceLevels int) (*book.Snapshot, error) {
    20  	req := NewRequestWithMethod(path.Join("book", symbol, string(precision)), "GET")
    21  	req.Params = make(url.Values)
    22  	req.Params.Add("len", strconv.Itoa(priceLevels))
    23  
    24  	raw, err := b.Request(req)
    25  	if err != nil {
    26  		return nil, err
    27  	}
    28  
    29  	return book.SnapshotFromRaw(symbol, string(precision), convert.ToInterfaceArray(raw), raw)
    30  }