code.vegaprotocol.io/vega@v0.79.0/core/integration/steps/the_price_monitoring.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 "fmt" 20 21 "code.vegaprotocol.io/vega/core/integration/steps/market" 22 types "code.vegaprotocol.io/vega/protos/vega" 23 24 "github.com/cucumber/godog" 25 ) 26 27 func ThePriceMonitoring(config *market.Config, name string, table *godog.Table) error { 28 rows := parsePriceMonitoringTable(table) 29 triggers := make([]*types.PriceMonitoringTrigger, 0, len(rows)) 30 for _, r := range rows { 31 row := priceMonitoringRow{row: r} 32 p := &types.PriceMonitoringTrigger{ 33 Horizon: row.horizon(), 34 Probability: fmt.Sprintf("%0.16f", row.probability()), 35 AuctionExtension: row.auctionExtension(), 36 } 37 triggers = append(triggers, p) 38 } 39 40 return config.PriceMonitoring.Add( 41 name, 42 &types.PriceMonitoringSettings{ 43 Parameters: &types.PriceMonitoringParameters{ 44 Triggers: triggers, 45 }, 46 }, 47 ) 48 } 49 50 func parsePriceMonitoringTable(table *godog.Table) []RowWrapper { 51 return StrictParseTable(table, []string{ 52 "horizon", 53 "probability", 54 "auction extension", 55 }, []string{}) 56 } 57 58 type priceMonitoringRow struct { 59 row RowWrapper 60 } 61 62 func (r priceMonitoringRow) horizon() int64 { 63 return r.row.MustI64("horizon") 64 } 65 66 func (r priceMonitoringRow) probability() float64 { 67 return r.row.MustF64("probability") 68 } 69 70 func (r priceMonitoringRow) auctionExtension() int64 { 71 return r.row.MustI64("auction extension") 72 }