forked from bitfinexcom/bitfinex-api-go
/
derivatives.go
39 lines (36 loc) · 927 Bytes
/
derivatives.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
package rest
import (
"github.com/henrytw/bitfinex-api-go/v2"
"path"
)
// OrderService manages data flow for the Order API endpoint
type DerivativesService struct {
requestFactory
Synchronous
}
// All returns all orders for the authenticated account.
func (s *WalletService) SetCollateral(symbol string, amount float64) (bool, error) {
urlPath := path.Join("deriv", "collateral", "set")
data := map[string]interface{}{
"symbol": symbol,
"collateral": amount,
}
req, err := s.requestFactory.NewAuthenticatedRequestWithData(bitfinex.PermissionRead, urlPath, data)
if err != nil {
return false, err
}
raw, err := s.Request(req)
if err != nil {
return false, err
}
// [[1]] == success, [] || [[0]] == false
if len(raw) <= 0 {
return false, nil
}
item := raw[0].([]interface{})
// [1] == success, [] || [0] == false
if len(item) > 0 && item[0].(int) == 1 {
return true, nil
}
return false, nil
}