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