forked from bitfinexcom/bitfinex-api-go
/
status.go
73 lines (65 loc) · 1.93 KB
/
status.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package rest
import (
"fmt"
"net/url"
"path"
"strings"
"github.com/evzpav/bitfinex-api-go/pkg/models/derivatives"
)
// TradeService manages the Trade endpoint.
type StatusService struct {
requestFactory
Synchronous
}
const (
DERIV_TYPE = "deriv"
)
func (ss *StatusService) get(sType string, key string) (*derivatives.Snapshot, error) {
req := NewRequestWithMethod(path.Join("status", sType), "GET")
req.Params = make(url.Values)
req.Params.Add("keys", key)
raw, err := ss.Request(req)
if err != nil {
return nil, err
}
trueRaw := make([][]interface{}, len(raw))
for i, r := range raw {
trueRaw[i] = r.([]interface{})
}
s, err := derivatives.SnapshotFromRaw(trueRaw)
if err != nil {
return nil, err
}
return s, nil
}
// Retrieves derivative status information for the given symbol from the platform
// see https://docs.bitfinex.com/reference#rest-public-status for more info
func (ss *StatusService) DerivativeStatus(symbol string) (*derivatives.DerivativeStatus, error) {
data, err := ss.get(DERIV_TYPE, symbol)
if err != nil {
return nil, err
}
if len(data.Snapshot) == 0 {
return nil, fmt.Errorf("no status found for symbol %s", symbol)
}
return data.Snapshot[0], err
}
// Retrieves derivative status information for the given symbols from the platform
// see https://docs.bitfinex.com/reference#rest-public-status for more info
func (ss *StatusService) DerivativeStatusMulti(symbols []string) ([]*derivatives.DerivativeStatus, error) {
key := strings.Join(symbols, ",")
data, err := ss.get(DERIV_TYPE, key)
if err != nil {
return nil, err
}
return data.Snapshot, err
}
// Retrieves derivative status information for all symbols from the platform
// see https://docs.bitfinex.com/reference#rest-public-status for more info
func (ss *StatusService) DerivativeStatusAll() ([]*derivatives.DerivativeStatus, error) {
data, err := ss.get(DERIV_TYPE, "ALL")
if err != nil {
return nil, err
}
return data.Snapshot, err
}