code.vegaprotocol.io/vega@v0.79.0/core/integration/steps/the_margin_calculator.go (about)

     1  // Copyright (C) 2023 Gobalsky Labs Limited
     2  //
     3  // This program is free software: you can redistribute it and/or modify
     4  // it under the terms of the GNU Affero General Public License as
     5  // published by the Free Software Foundation, either version 3 of the
     6  // License, or (at your option) any later version.
     7  //
     8  // This program is distributed in the hope that it will be useful,
     9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  // GNU Affero General Public License for more details.
    12  //
    13  // You should have received a copy of the GNU Affero General Public License
    14  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    15  
    16  package steps
    17  
    18  import (
    19  	"code.vegaprotocol.io/vega/core/integration/steps/market"
    20  	types "code.vegaprotocol.io/vega/protos/vega"
    21  
    22  	"github.com/cucumber/godog"
    23  )
    24  
    25  func TheMarginCalculator(config *market.Config, name string, table *godog.Table) error {
    26  	row := marginCalculatorRow{row: parseMarginCalculatorTable(table)}
    27  
    28  	return config.MarginCalculators.Add(name, &types.MarginCalculator{
    29  		ScalingFactors: &types.ScalingFactors{
    30  			SearchLevel:       row.searchLevelFactor(),
    31  			InitialMargin:     row.initialMarginFactor(),
    32  			CollateralRelease: row.collateralReleaseFactor(),
    33  		},
    34  	})
    35  }
    36  
    37  func parseMarginCalculatorTable(table *godog.Table) RowWrapper {
    38  	return StrictParseFirstRow(table, []string{
    39  		"release factor",
    40  		"initial factor",
    41  		"search factor",
    42  	}, []string{})
    43  }
    44  
    45  type marginCalculatorRow struct {
    46  	row RowWrapper
    47  }
    48  
    49  func (r marginCalculatorRow) collateralReleaseFactor() float64 {
    50  	return r.row.MustF64("release factor")
    51  }
    52  
    53  func (r marginCalculatorRow) initialMarginFactor() float64 {
    54  	return r.row.MustF64("initial factor")
    55  }
    56  
    57  func (r marginCalculatorRow) searchLevelFactor() float64 {
    58  	return r.row.MustF64("search factor")
    59  }