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

     1  package rest
     2  
     3  import (
     4  	"github.com/bitfinexcom/bitfinex-api-go/pkg/models/common"
     5  	"github.com/bitfinexcom/bitfinex-api-go/pkg/models/notification"
     6  	"github.com/bitfinexcom/bitfinex-api-go/pkg/models/position"
     7  )
     8  
     9  // PositionService manages the Position endpoint.
    10  type PositionService struct {
    11  	requestFactory
    12  	Synchronous
    13  }
    14  
    15  // All - retrieves all of the active positions
    16  // see https://docs.bitfinex.com/reference#rest-auth-positions for more info
    17  func (s *PositionService) All() (*position.Snapshot, error) {
    18  	req, err := s.requestFactory.NewAuthenticatedRequest(common.PermissionRead, "positions")
    19  	if err != nil {
    20  		return nil, err
    21  	}
    22  
    23  	raw, err := s.Request(req)
    24  	if err != nil {
    25  		return nil, err
    26  	}
    27  
    28  	pss, err := position.SnapshotFromRaw(raw)
    29  	if err != nil {
    30  		return nil, err
    31  	}
    32  
    33  	return pss, nil
    34  }
    35  
    36  // Claim - submits a request to claim an active position with the given id
    37  // see https://docs.bitfinex.com/reference#claim-position for more info
    38  func (s *PositionService) Claim(cp *position.ClaimRequest) (*notification.Notification, error) {
    39  	bytes, err := cp.ToJSON()
    40  	if err != nil {
    41  		return nil, err
    42  	}
    43  
    44  	req, err := s.requestFactory.NewAuthenticatedRequestWithBytes(common.PermissionWrite, "position/claim", bytes)
    45  	if err != nil {
    46  		return nil, err
    47  	}
    48  
    49  	raw, err := s.Request(req)
    50  	if err != nil {
    51  		return nil, err
    52  	}
    53  
    54  	return notification.FromRaw(raw)
    55  }