Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API-222: GetAvailableMargin #24

Merged
merged 2 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading