Skip to content

Commit

Permalink
Merge pull request #24 from gateway-fm/API-222
Browse files Browse the repository at this point in the history
API-222: GetAvailableMargin
  • Loading branch information
asolovov authored Sep 27, 2023
2 parents 83c186f + 240729e commit c1fcc01
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
15 changes: 15 additions & 0 deletions mocks/service/mockService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions perpsv3.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ type IPerpsv3 interface {
// GetFoundingRate is used to get current market founding rate by given market ID
GetFoundingRate(marketId *big.Int) (*big.Int, error)

// GetAvailableMargin is used to get available margin for given account ID
GetAvailableMargin(accountId *big.Int) (*big.Int, error)

// FormatAccount is used to get account, and it's additional data from the contract by given account id
FormatAccount(id *big.Int) (*models.Account, error)

Expand Down Expand Up @@ -229,6 +232,10 @@ func (p *Perpsv3) GetFoundingRate(marketId *big.Int) (*big.Int, error) {
return p.service.GetFoundingRate(marketId)
}

func (p *Perpsv3) GetAvailableMargin(accountId *big.Int) (*big.Int, error) {
return p.service.GetAvailableMargin(accountId)
}

func (p *Perpsv3) FormatAccounts() ([]*models.Account, error) {
return p.service.FormatAccounts()
}
Expand Down
10 changes: 10 additions & 0 deletions services/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ func (s *Service) FormatAccounts() ([]*models.Account, error) {
return s.formatAccounts(opts)
}

func (s *Service) GetAvailableMargin(accountId *big.Int) (*big.Int, error) {
margin, err := s.perpsMarket.GetAvailableMargin(nil, accountId)
if err != nil {
logger.Log().WithField("layer", "").Errorf("get avaliable margin error: %v", err.Error())
return nil, errors.GetReadContractErr(err, "perps market", "GetAvailableMargin")
}

return margin, nil
}

// formatAccounts is used to get accounts from the contract using event filter function for 'AccountCreated' event
// and given filter options
func (s *Service) formatAccounts(opts *bind.FilterOpts) ([]*models.Account, error) {
Expand Down
3 changes: 3 additions & 0 deletions services/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ type IService interface {
// GetFoundingRate is used to get current founding rate by given market ID
GetFoundingRate(marketId *big.Int) (*big.Int, error)

// GetAvailableMargin is used to get available margin for given account ID
GetAvailableMargin(accountId *big.Int) (*big.Int, error)

// FormatAccount is used to get account, and it's additional data from the contract by given account id
FormatAccount(id *big.Int) (*models.Account, error)

Expand Down

0 comments on commit c1fcc01

Please sign in to comment.