github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/v2/rest/derivatives.go (about) 1 package rest 2 3 import ( 4 "path" 5 6 "github.com/bitfinexcom/bitfinex-api-go/pkg/models/common" 7 ) 8 9 // OrderService manages data flow for the Order API endpoint 10 type DerivativesService struct { 11 requestFactory 12 Synchronous 13 } 14 15 // Update the amount of collateral for a Derivative position 16 // see https://docs.bitfinex.com/reference#rest-auth-deriv-pos-collateral-set for more info 17 func (s *WalletService) SetCollateral(symbol string, amount float64) (bool, error) { 18 urlPath := path.Join("deriv", "collateral", "set") 19 data := map[string]interface{}{ 20 "symbol": symbol, 21 "collateral": amount, 22 } 23 req, err := s.requestFactory.NewAuthenticatedRequestWithData(common.PermissionRead, urlPath, data) 24 if err != nil { 25 return false, err 26 } 27 raw, err := s.Request(req) 28 if err != nil { 29 return false, err 30 } 31 // [[1]] == success, [] || [[0]] == false 32 if len(raw) <= 0 { 33 return false, nil 34 } 35 item := raw[0].([]interface{}) 36 // [1] == success, [] || [0] == false 37 if len(item) > 0 && item[0].(int) == 1 { 38 return true, nil 39 } 40 return false, nil 41 }